*** I am not a btrfs expert nor do I take responsibility if you hose your system and your data, use this at your own risk ***
Ok so I will this is how I did it step by step, I will use a simple setup but there isn't anything stopping you from using a more complicated setup, ie btrfs raid. Putting /home on a seperate partition
So begin the installer, I manually partition my drive with gparted. Since I am using a gpt partitioned disk, I am going to create a 2MB unformatted partition and set the bios_grub flag on that partition, create a swap partition, then a 4GB partition for '/' and a 3GB 'home' partition.
sda1 -> bios_grub (only needed for gpt disks)
sda2 -> swap
sda3 -> btrfs volume for '/'
sda4 -> btrfs volume for 'home'
I also set the sda3 has bootable. Then go ahead with the install as normal, and wait for the installation to finish.
Once the installation is complete, do not reboot, just close the installer. Open up terminal and mount your '/' partition. Continue these steps in the live environment.
sudo mount /dev/sda3 /mnt
Now before we create out snapshots, we want to first edit fstab and grub.cfg the reason is if we snapshot first then we have to fix the same files in the snapshot subvolume. However we will create them later, what ever you choose for a name its up to you. I will use @root and @home as an example, however lets continue.
sudo nano /mnt/etc/fstab
Should look similar to this; now lets add our subvol flag/option. Also if you wish to add compression and ssd options, depending on your setup.
UUID=0fa86929-b194-4f90-b233-1519004f4122 none swap sw 0 0
UUID=244bab70-ce04-4b50-b546-6b55cc72e15e / btrfs defaults,relatime 0 1
UUID=e47c65e5-ff69-4a16-86af-497ac6921f12 /home btrfs defaults,relatime 0 2
so my '/' and '/home' mounts btrfs options will look like this.
UUID=244bab70-ce04-4b50-b546-6b55cc72e15e / btrfs defaults,relatime,subvol=@root 0 1
UUID=e47c65e5-ff69-4a16-86af-497ac6921f12 /home btrfs defaults,relatime,subvol=@home 0 2
Ok save and exit. Now we should never update /boot/grub/grub.cfg directly but this is the easiest way for us to boot into the subvolume, we'll properly fix grub.cfg once we boot into the subvolume.
nano /mnt/boot/grub/grub.cfg
Look for this section we are going to edit just to boot into the subvolume, clean up the file system and then update grub.
menuentry 'siduction 2013.2.0 december (xfce) GNU/Linux' --class siduction --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-244bab70-ce04-4b50-b546-6b55cc72e15e' {
load_video
insmod gzio
insmod part_gpt
insmod btrfs
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3 --hint='hd0,gpt3' 244bab70-ce04-4b50-b546-6b55cc72e15e
else
search --no-floppy --fs-uuid --set=root 244bab70-ce04-4b50-b546-6b55cc72e15e
fi
echo 'Loading Linux 3.12-6.towo-siduction-amd64 ...'
linux /boot/vmlinuz-3.12-6.towo-siduction-amd64 root=UUID=244bab70-ce04-4b50-b546-6b55cc72e15e ro quiet
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-3.12-6.towo-siduction-amd64
We need to focus on these three, but we will only edit the first and last of these lines;
linux /boot/vmlinuz-3.12-6.towo-siduction-amd64 root=UUID=244bab70-ce04-4b50-b546-6b55cc72e15e ro quiet
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-3.12-6.towo-siduction-amd64
to
linux /@root/boot/vmlinuz-3.12-6.towo-siduction-amd64 root=UUID=244bab70-ce04-4b50-b546-6b55cc72e15e ro rootflags=subvol=@root quiet
echo 'Loading initial ramdisk ...'
initrd /@root/boot/initrd.img-3.12-6.towo-siduction-amd64
Ok save and exit. Now lets create our snapshots sub volumes.
sudo btrfs subvolume snapshot /mnt/ /mnt/@root
Ok since we have mounted sda3 earlier to mnt, we are creating a subvolume called @root under the root subvolume that we installed siduction under. Now its also a snapshot as well which is what we want. It this operation shouldn't take longer than a few seconds.
Now lets do create a file in the new '/' so we can confirm if we have actually booted into this subvolume.
sudo touch /mnt/@root/snapshot-01-12-2014
This creates an empty file, in that subvolume we will use to verify we are in the right subvolume. Now if you cd into /mnt and do an ls, you should see @root as a regular folder. Now if you cd into @root, you should see the same folder structure, (without @root) and that empty file we created as a sanity check.
Ok now if you are doing the same hing with home, we can mount /dev/sda4 to /mnt/home and create a subvolume snapshot.
sudo mount /dev/sda4 /mnt/home
sudo btrfs subvolume snapshot /mnt/home /mnt/home/@home
Ok now we need to re-install grub and tell it to boot using the /boot in the @root subvolume.
sudo grub-install –boot-directory=/mnt/@root/boot /dev/sda
Ok great now lets reboot and leave the live disc and into our new siduction install on the hard drive. Once you login switch to the root user, cd to '/' and do a ls.
Two things you should notice first that @root is not that and second there is a file called snapshot-01-12-2014. If you do then, perfect, now lets mount that root subvolume, clean it up and then update grub.
Now the other thing is if you cat /proc/self/mountinfo you can also confirm you have booted and correctly are in the @root subvolume.
ok so now we mount the root subvolume to /mnt and clean it up.
mount /dev/sda3 /mnt
Now this may seem confusing since we have mounted sda3 but we have actually mounted a subvolume in on sda3. Now cd to /mnt
cd /mnt
Now be very careful, we are going to delete the folders in here but we DO NOT want to delete the subvolume. The subvolume appears as a regular folder in btrfs. Here is the output from ls, not that we won't delete @root but will delete everything else.
root@siductionbox-xfce:/mnt# ls
bin dev home lib64 mnt proc @root sbin srv tmp var
boot etc lib media opt root run selinux sys usr
If you have a better way to delete the folders, without deleting @root, let me know but I just rm -rf each folder.
So when you are done you should have @root as the only folder left. Also for me it makes sense to use @ at the front of a volume name or _ that way you know its subvolume and not a folder.
now lets fix our home folder
umount /mnt
mount /dev/sda4 /mnt
now in when I go into /mnt I should see two folders one named @home and the other my username of course. delete the folder named your username, in my case;
rm -rf terroreek
did the trick for me.
ok now unmount /mnt and run update-grub, this will properly fix all the grub options to use the subvolume.
umount /mnt
update-grub
That's it. Reboot and you should be good.
Once you have confirmed everything is working properly you can do this edit your fstab and do something like this, mount sda3 to /mnt/root/ and prior to performing an update do this as root
btrfs subvolume snapshot /mnt/root/@root /mnt/root/@root_snap-01-12-2014
Now upgrade, if your system breaks, you can simply roll back by doing this
[code]mv /mnt/root/@root /mnt/root/@badroot
mv /mnt/root/@root_snap-01-12-2014 /mnt/root/@root
reboot, and you are back into a working state. then you just need to
btrfs subvolume delete /mnt/root/@badroot
The thing you should be aware of is that snapshots are block level changes and it doesn't show free disk properly. So becareful with using snapshots.