meta data for this page
This is an old revision of the document!
BTRFS as root filesystem
System overview
- /dev/sda1 4.08GB ext4 “/” used 1.56GB, free 2.53GB
- /dev/sda2 10.91GB extended
- /dev/sda5 524MB swap
- /dev/sda6 10.40GB ext4 “/home” 321MB used, 10.09GB free
Boot from live-cd
Btrfs support is heavily developed in Linux Kernel. So do not use old kernel.
I was using gparted-live-0.22.0-1-amd64.iso (NOTE: to match your existing system architecture (i586, amd64, etc)) Which contains:
- Kernel 3.16.0-4-586
- btrfs utils version 3.17
Conversion
fsck -f /dev/sda1 fsck -f /dev/sda6 btrfs-convert /dev/sda1
Disk usage before conversion: used 1.56GB, free 2.53GB after conversion: used 1.65GB, free 2.43GB
btrfs check /dev/sda1
Update system
Mount new root filesystem:
mount /dev/sda1 /mnt for i in dev dev/pts proc sys ; do mount --bind /$i /mnt/$i ; done chroot /mnt
get new UUID of /dev/sda1 using “blkid” mount /dev/sda1 somewhere, go to etc/fstab and update to new UUID:
UUID=a74f5787-aee1-4981-b7e6-fbd3cb6ac919 / btrfs defaults 0 1
update-grub grub-install /dev/sda exit reboot
and remove Live CD with Gparted
rollback to ext FS
Rollback to ext2 is possible. There is subvolume ext2_saved on filesystem.
btrfs subvolume list /
To delete backup
btrfs subvolume delete /ext2_saved
Update to kernel 4
Edit /etc/apt/sources and add sid release
apt-get update apt-get install linux-image-amd64 apt-get install btrfs-tools update-initramfs -u
- ERROR: Warning: /sbin/fsck.btrfs doesn't exist, can't install to initramfs, ignoring.
- EXPLANATION: “This is going to be changed back in the next version of btrfs-tools.”
- SOLUTION: ln -s /bin/fsck.btrfs /sbin/fsck.btrfs
Check btrfs-tools version
/bin/btrfs version
Converting dirs into subvolumes
To make backups, snapshoting, moving much easier and faster, every directory you want to backup by snapshot should be a subvolume. Also root filesystem should be created in separate subvolume not in btrfs root.
To distinguish volumes from directories we will use @ character at beginning of subvolume name. This is Ubuntu naming convention for subvolumes.
Proposed subvolumes structure /@ /@home /@var
root
- take a snapshot of root volume
btrfs subvolume snapshot . @root
- make @root subvolume a default root
- update
- /etc/fstab
UUID=739e6086-d925-4bdb-94f5-26d8c10dc171 / btrfs defaults,subvol=@root
or
- set @root subvolume default mount path
btrfs subvolume set-default @root /
- move directory to subvolume (cp –reflink is much faster on BTRFS)
subdirectories
- On BTRFS root create a new subvolume
btrfs subvolume create /mnt/btrfs/@home
- move files into the new subvolume as if it were a directory
mv /mnt/btrs/@/home/* /mnt/btrfs/@home/
- remove old directory
rmdir /mnt/btrfs/@/home
- update /etc/fstab to mount @home as /home