enira.net

We are all living in a technological wasteland.

RSS
people

Powershell – Windows Firewall: Trusting range of IPs

Introduction

just a code snippet this time. For a demo environment I’ve had to trust an entire set of IPs. Being the lazy person that I am I created a little powershell to add all at once.

The code

$IPs = @("10.10.10.210", "10.10.10.211", "10.10.10.212", "10.10.10.213", "10.10.10.214", "10.10.10.215", "10.10.10.216", "10.10.10.217", "10.10.10.218", "10.10.10.219") |`
	Foreach-object {
 
	#delete old rule (if there is one)
	netsh advfirewall firewall delete rule name="Allow from $_"
	#add new rule 
	netsh advfirewall firewall add rule name="Allow from $_" dir=in action=allow protocol=ANY remoteip=$_
	write-host "$_ Added Incoming for $?"
 
	#delete old rule (if there is one)
	netsh advfirewall firewall delete rule name="Allow to $_"
	#add new rule 
	netsh advfirewall firewall add rule name="Allow to $_" dir=out action=allow protocol=ANY remoteip=$_
	write-host "$_ Added Outgoing $?"
}
No Comments |

NAS – Next-gen filesystems – BTRFS RAID 0 & conversion to RAID 5

Introduction

This post will handle the creating of a RAID0 and the conversion of RAID5. This is a use case for the creation of my NAS. As I don’t have spare disks laying around, I will migrate the data from my current RAID5 to a BTRFS RAID0 and then decomission the old RAID5 and add a disk to the RAID0 to create a new BTRFS RAID5 system.

Test One: creating a RAID0

Our first test is to create a RAID0 on our BTRFS file system. I am currently using three 5GB disks. For RAID0 I will be using /dev/sdb and /dev/sdc

lsblk
NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                           8:0    0     6G  0 disk
├─sda1                        8:1    0   243M  0 part /boot
├─sda2                        8:2    0     1K  0 part
└─sda5                        8:5    0   5.8G  0 part
  ├─btrfs--vg-root (dm-0)   252:0    0   4.8G  0 lvm  /
  └─btrfs--vg-swap_1 (dm-1) 252:1    0     1G  0 lvm  [SWAP]
sdb                           8:16   0     5G  0 disk
sdc                           8:32   0     5G  0 disk
sdd                           8:48   0     5G  0 disk

So let’s create our RAID0 setup. Note that I am using the –mixed mode. This is for small disks only!

sudo mkfs.btrfs -d raid0 -m raid0 -L disk-raid0 --mixed /dev/sdb /dev/sdc

So now we can see in ‘fi show’ that whe have 2 devices working together.

sudo btrfs fi show
Label: 'disk-raid0'  uuid: a81963e6-8cfe-4da1-abed-579bc80669c7
        Total devices 2 FS bytes used 28.00KiB
        devid    1 size 5.00GiB used 532.00MiB path /dev/sdb
        devid    2 size 5.00GiB used 520.00MiB path /dev/sdc

Next, add it to the fstab file so it will start on boot.

sudo nano /etc/fstab

Use the UUID found in the ‘sudo btrfs fi show’ command.

UUID=a81963e6-8cfe-4da1-abed-579bc80669c7 /media/btrfs-raid0          btrfs defaults 0       0

Create our mountpoint.

sudo mkdir -p /media/btrfs-raid0

And reboot to test if the configuration works.

sudo reboot

Once rebooted you should see the RAID0 being mounted on ‘/media/btrfs-raid0’

df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/btrfs--vg-root  4.6G  1.9G  2.5G  44% /
none                        4.0K     0  4.0K   0% /sys/fs/cgroup
udev                        477M  4.0K  477M   1% /dev
tmpfs                        98M  1.3M   97M   2% /run
none                        5.0M     0  5.0M   0% /run/lock
none                        488M     0  488M   0% /run/shm
none                        100M     0  100M   0% /run/user
/dev/sda1                   236M  100M  124M  45% /boot
/dev/sdc                     10G  4.3M   10G   1% /media/btrfs-raid0

Samba mount to test

Before continuing, I’d like to add a Samba mount point so I can move files to our newly created RAID0.

sudo nano /etc/samba/smb.conf
[btrfs-raid0]
   comment = Test BTRFS RAID 0
   browseable = yes
   path = /media/btrfs-raid0
   valid users = btrfs
   writable = yes

Assign correct ownership levels.

sudo chown -R btrfs:btrfs /media/btrfs-raid0/

Restart the service to verify if everything works.

sudo service smbd restart

Now copy some files and verify the content. (Skipping this)

Test Two: converting to a RAID5

Before we continue with the conversion of a RAID5, let’s chech our setup first.

sudo btrfs fi show

This shows two disks in use sdb and sdc.

Label: disk-raid0  uuid: a81963e6-8cfe-4da1-abed-579bc80669c7
        Total devices 2 FS bytes used 288.00KiB
        devid    1 size 5.00GiB used 528.00MiB path /dev/sdb
        devid    2 size 5.00GiB used 520.00MiB path /dev/sdc

Let’s fill it up with some 5GB of data and verify the content.

btrfs filesystem df /media/btrfs-raid0/
System, RAID0: total=16.00MiB, used=4.00KiB
Data+Metadata, RAID0: total=6.00GiB, used=5.28GiB
Data+Metadata, single: total=8.00MiB, used=4.00KiB
unknown, single: total=112.00MiB, used=0.00

Before converting to a RAID5 system, we need to add a disk. As RAID5 uses minimal 3 disks and RAID0 is currently working with 2. Let’s add the /dev/sdd disk.

sudo btrfs device add /dev/sdd /media/btrfs-raid0/

Now let’s see what has happened to our drives. As you can see there is nothing written on our added drive. Normally you should rebalance. But converting will trigger the rebalance.

sudo btrfs fi show
Label: disk-raid0  uuid: a81963e6-8cfe-4da1-abed-579bc80669c7
        Total devices 3 FS bytes used 5.28GiB
        devid    1 size 5.00GiB used 3.02GiB path /dev/sdb
        devid    2 size 5.00GiB used 3.01GiB path /dev/sdc
        devid    3 size 5.00GiB used 0.00 path /dev/sdd

Now let’s convert to a RAID5 system.

sudo btrfs balance start -dconvert=raid5 -mconvert=raid5 /media/btrfs-raid0/
sudo btrfs fi show

Now you can see that the drive is rebalanced and the data is written on our extra disk ‘sdd’.

Label: disk-raid0  uuid: a81963e6-8cfe-4da1-abed-579bc80669c7
        Total devices 3 FS bytes used 5.28GiB
        devid    1 size 5.00GiB used 4.03GiB path /dev/sdb
        devid    2 size 5.00GiB used 4.03GiB path /dev/sdc
        devid    3 size 5.00GiB used 4.03GiB path /dev/sdd

Now let’s verify if we can see the correct RAID level.

btrfs filesystem df /media/btrfs-raid0/
System, RAID5: total=64.00MiB, used=4.00KiB
Data+Metadata, RAID5: total=8.00GiB, used=5.28GiB
unknown, single: total=112.00MiB, used=0.00

Voila done. RAID0 is now a RAID5. :)

No Comments |