Welcome! Log In Create A New Profile

Advanced

Booting btrfs raid 1 rootfs on Kirkwood boxes in only 10 steps ; )

Posted by saschadd 
Booting btrfs raid 1 rootfs on Kirkwood boxes in only 10 steps ; )
March 17, 2017 03:44AM
After some trial and error and with some good tips and hints from bodhi i got an btrfs raid 1 running on my NSA325v2.
As this took me quite some time to figure things out i share my little howto for others out there in the hope it might be helpful.

The following HowTo is how i did it on an NSA325v2 but it should be adaptable to other Kirkwood boxes as well.
I recommend to have the serial console at hand just to be sure but it might not be necessary. ;)

1. update uboot
update uboot to the latest version as described here http://forum.doozan.com/read.php?3,12381

2. install rootfs on stick
Install Debian-4.4.0-kirkwood-tld-1-rootfs-bodhi.tar.bz2 on an usb stick as described here http://forum.doozan.com/read.php?2,12096

3. boot newly created rootfs
Boot your Kirkwood box from this stick and run as recommended:
rm /etc/ssh/ssh_host*
ssh-keygen -A

apt update && apt upgrade
Then run
apt install btrfs-tools
to install btrfs-tools from the debian jessie repo.
DON'T install the latest version from source etc. as it might not have the needed local-premount/btrfs which is needed.
We can update later. ;)
reboot

4. update Kernel
Update to the latest Kernel as described here http://forum.doozan.com/read.php?2,12096

Before step
4. Create uImage and uInitrd and setup for booting.

we have to add btrfs to the file /etc/initramfs-tools/modules
nano  /etc/initramfs-tools/modules
add btrfs at the end of the file and save

after that we run the following
update-initramfs -u -k all
after that we can go on with the kernel update and at the end we will reboot to make sure everything is working.

If the box boots up without problems we can shutdown with
shutdown -hP now
At this point we have a working rootfs on one ext4 partition with btrfs support for the NSA325v2.


5. backup of the rootfs
Now we have to make a copy of that rootfs for later use.
Therefore we need another linux box where we

1. login as root
2. mkdir /media/rootfs
3. mount the newly created rootfs of our stick at /media/rootfs
4. cd /media/rootfs
5. making a backup of the rootfs to folder home: time tar -cjf /home/btrfs-rootfs.tar.bz2 . &
as bodhi already wrote: It will take a long time, so run it as background task and measure the time.
When it is done, you'll get the time statistics as an indication the task was completed and can see how long it took as bonus.

Now that we have the copy of our rootfs we copy this to our stick for further use on the NSA325v2 sata disks.
cp /home/btrfs-rootfs.tar.bz2 /media/rootfs/home
Now we can unmount our stick and put it back into the nsa325 and boot it from that stick.

6. Partitioning your harddisks
The following partition sizes are just how i made them, you can change sizes as you wish.

disk 1 (left)
1 250 MB boot partition
2 50 GB rootfs partition
3 data partition with all space left

as i want a btrfs raid1 of the rootfs and data partition i partition the right disk as follows
disk 2 (right)
1 50 GB rootfs partion raid1
2 data partition with all space left

7. create filesystems
Now we need to create the filesystems on the new partitions

For booting up the btrfs raid 1 we need a ext4 boot partition:
mkfs.ext4 /dev/sdb1 -L boot
(ext4 format and setting label boot to the 250MB boot partition)

Now the btrfs raid 1:
Note: If you want both data and metadata to be redundant, you'd use -d raid1 (RAID1 is the default for metadata, that's why we don't have to specify it here):
(-f means force and is needed if an old filesystem is dedected)

mkfs.btrfs -d raid1 -f /dev/sdb2 /dev/sdc1 -L rootfs
mkfs.btrfs -d raid1 -f /dev/sdb3 /dev/sdc2 -L data

after that you can have a look at the created raid1 volumes.
btrfs filesystem show

8. copy over rootfs
Now that we have prepared our harddrives we are ready to copy over the running system to the sata disks.

To accomplish this we mount our sata partitions as follows:
mkdir /media/boot
mkdir /media/root
mount /dev/sdb1 /media/boot
mount /dev/sdb2 /media/root

then we unpack the rootfs backup
cd /media/root
tar -xjf /home/btrfs-rootfs.tar.bz2

After that we move the boot folder to our boot partition
mv /media/root/boot /media/boot

9. Prepare fstab

nano /media/root/etc/fstab
and change the following in red:

# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
#/dev/root / ext4 noatime,errors=remount-ro 0 1
LABEL=rootfs / btrfs defaults,subvol=@,noatime,compress=lzo,autodefrag 0 1
tmpfs /tmp tmpfs defaults 0 0
/dev/sda3 /media/data/backup btrfs defaults,subvol=@,noatime,compress=lzo,autodefrag 0 1

Note: As you can see i mount the big data partition to /media/data/backup as i want it for backup use.
You can mount it wherever you want just make sure to create the folder before you reboot.
We can also make subvolumes on that data btrfs raid to put backup data into a separate subvolume and any other data in its own subvolume.
Those subvolumes would share the space of btrfs data raid.
But this is out of the scope of this howto. ;)


10. Final

Now its time to do a
shutdown -hP now

remove the stick

boot without the stick from sata



after successful reboot you can check that the rootfs raid1 is correctly mounted with

mount

which should show

....
/dev/sda2 on / type btrfs (rw,noatime,compress=lzo,space_cache,autodefrag,subvolid=5,subvol=/)
....

Note: You will only see sda2 here as the raid1 is done by btrfs itself and therefore only one disk has to be mounted.

If so, we have a running btrfs raid1 rootfs on our Kirkwood box.

-
happy hacking,

saschadd



Edited 1 time(s). Last edit at 03/17/2017 03:51AM by saschadd.
Re: Booting btrfs raid 1 rootfs on Kirkwood boxes in only 10 steps ; )
March 17, 2017 04:12AM
Thanks sachadd!

Added to the Wiki.

Quote

RAID

Making a RAID1 rootfs
Booting btrfs RAID 1 rootfs on Kirkwood boxes

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 1 time(s). Last edit at 03/17/2017 04:16AM by bodhi.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: