Using The btrfs Filesystem (With RAID1) With Ubuntu 12.10 On A Hetzner Server - Page 2

2.2 Adding /dev/sdb To The Setup

Now let's add /dev/sdb to our setup. First we copy our partition table from /dev/sda to /dev/sdb so that we have the same partitioning on /dev/sdb (/dev/sdb1 for swap and /dev/sdb2 for /). Please note that it is not necessary to use the same partitioning scheme on the second hard drive, for example you could add the whole second hard drive /dev/sdb without any partitions on it to the btrfs / partition, but if you do that and /dev/sda fails, the system will run on /dev/sdb, but without swap.

sfdisk -d /dev/sda | sfdisk --force /dev/sdb

Next mount the btrfs partition /dev/sda2 to /mnt:

mount /dev/sda2 /mnt

Add /dev/sdb2 to the btrfs partition:

btrfs device add /dev/sdb2 /mnt

Do a filesystem balance:

btrfs filesystem balance /mnt

We could now run btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt to set up RAID1 for data and metadata on our btrfs partition, however the btrfs tools in Hetzner's rescue system are too old to support that command. Therefore we will do it later when we have booted into our Ubuntu 12.10 system.

Now we mount some needed directories and chroot to /mnt:

for fs in proc sys dev dev/pts; do mount --bind /$fs /mnt/$fs; done
chroot /mnt

Make sure that the block IDs of /dev/sda2 and /dev/sdb2 are the same (fb56d61b-453f-4917-bf58-95225e163b9c in this example):

blkid /dev/sda2
[email protected] / # blkid /dev/sda2
/dev/sda2: UUID="fb56d61b-453f-4917-bf58-95225e163b9c" UUID_SUB="c29fc4d3-71ff-4075-92c2-8069d4f1828f" TYPE="btrfs"
[email protected] / #
blkid /dev/sdb2
[email protected] / # blkid /dev/sdb2
/dev/sdb2: UUID="fb56d61b-453f-4917-bf58-95225e163b9c" UUID_SUB="817875ce-457d-417a-8eb7-736709663b8d" TYPE="btrfs"
[email protected] / #

Open /etc/fstab...

vi /etc/fstab

... and make sure that this block ID is in use for the / partition (it should by default):

proc /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
# /dev/sda1 during Installation (RescueSystem)
UUID=48c56489-e44f-47bd-8054-75c0135d96ad none swap sw 0 0
# /dev/sda2 during Installation (RescueSystem)
UUID=fb56d61b-453f-4917-bf58-95225e163b9c / btrfs defaults 0 0

Next open /etc/grub.d/00_header...

vi /etc/grub.d/00_header

... and comment out line 93 (if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi):

function recordfail {
  set recordfail=1
  #if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi

If you don't do this, you will get the error...

error: sparse file not allowed

... when you boot from the btrfs file system, and you have to press ENTER to proceed with the boot process (see Ubuntu 12.10 + btrfs: error: sparse file not allowed). Therefore this step is needed even if you don't want to add /dev/sdb to your btrfs setup.

Update the boot loader...


... and install it on /dev/sda and /dev/sdb:

grub-install /dev/sda
grub-install /dev/sdb

Exit the chroot...


... and reboot the system:



3 Boot Into The Ubuntu 12.10 System

If all goes well, you should be able to log into your new Ubuntu 12.10 system after the reboot. Let's check if we are really using btrfs for the / partition:

[email protected] ~ # mount
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/security type securityfs (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
/dev/sda2 on / type btrfs (rw)
[email protected]u-1210-quantal-64-minimal ~ #

Looks good!

By default, btrfs uses RAID1 for metadata and no RAID for data. Let's change this to use RAID1 for both data and metadata:

btrfs balance start -dconvert=raid1 -mconvert=raid1 /

Afterwards, run...

btrfs filesystem df /

... to check if RAID1 has been set up for data and metadata:

[email protected] ~ # btrfs filesystem df /
Data, RAID1: total=5.00GB, used=721.54MB
System, RAID1: total=32.00MB, used=4.00KB
System: total=4.00MB, used=0.00
Metadata, RAID1: total=5.00GB, used=75.22MB
[email protected] ~ #

Congratulations, you've just finished your btrfs setup on a Hetzner root server!


Share this page:

2 Comment(s)

Add comment

Please register in our forum first to comment.


By: Linus

Did you also try this with an Ubuntu 1204? And what about the possibilities of data-corruption with btrfs?

By: Eugene Crosser

As of 2013-06-03, Hetzner rescue system uses GPT for the disks, and sfdisk does not work. So, instead of

sfdisk -d /dev/sda | sfdisk --force /dev/sdb

you have to do

sgdisk -R=/dev/sdb /dev/sda sgdisk -G /dev/sdb