Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When doing a installation to a root btrfs filesystem, many linux distributions install to the default subvolume. If left unmodified, this layout will force any snapshots or subvolumes to be created inside the root filesystem, which may be undesirable. Another possible layout would be to have the default subvolume contain a snapshots directory, and a rootfs subvolume, which is the root filesystem. How can I change the distro-default btrfs installation to use this subvolume layout without booting from a livecd?

share|improve this question
add comment

1 Answer 1

Firstly, we'll create the layout we want in the default subvolume:

btrfs subvolume snapshot / /rootfs
mkdir /snapshots

Note that /rootfs will be our new root filesystem, so don't make any changes to the current one after this step.

Edit /rootfs/etc/fstab to make the system use the new rootfs subvolume as root filesystem. For that, you'll need to modify it to include the subvol=rootfs option.

mount our new root filesystem somewhere, mount the relevant fileystems (dev, sys, proc, boot if you have it), chroot to it and update grub:

mount -o subvol=rootfs /dev/sdXX /media/temporary
cd /media/temporary
mount -o bind /dev  dev
mount -o bind /sys  sys
mount -o bind /proc proc
mount -o bind /boot boot
chroot .
update-grub
exit

That's it. Reboot, and your root filesystem should be the rootfs subvolume. If this succeeded, there shouldn't be any /snapshots directory. You can now delete the contents of the old root filesystem in the default subvolume.

If you want, you may make a permanent mount point for the default subvolume:

mkdir /media/btrfs/root

then you can mount -o subvolid=0 /dev/sdXX /media/btrfs/root and create your snapshots/subvolumes.

share|improve this answer
    
Also, note that instead of mounting, chrooting and updating grub, you can simply set the default subvolume to be rootfs with btrfs subvolume set-default ID /. ID can be found using `btrfs subvolume list / –  goncalopp Nov 2 '13 at 23:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.