Note: Converting rootfs to BTRFS via
btrfs-convertdoes not work at this time. System succesfully boots, however an exception is thrown by the kernel and rootfs is re-mounted readonly.
Note2: You don't have to rent a temporary disk volume, you may use a storage over network if you like. Adapt the below procedure accordingly if you prefer to do so.
-
Rent a second disk volume.
-
Boot in Rescue Mode. Finnix OS will be launched in a few seconds.
- Be sure you attached the newly rent disk before booting in rescue mode
-
Backup your rootfs:
mkfs.btrfs /dev/sdc mkdir /mnt/a /mnt/c mount /dev/sda /mnt/a mount /dev/sdc /mnt/c rsync -avP /mnt/a/ /mnt/c/ -
Format the rootfs disk:
umount /dev/sda mkfs.btrfs /dev/sda mount /dev/sda /mnt/a -
Copy your rootfs files back to /dev/sda
rsync -avP /mnt/c/ /mnt/a/ -
Edit
/mnt/a/etc/fstabaccordingly to change rootfs type to BTRFS:/dev/sda / btrfs defaults 0 1 -
Use the UUID value of the following command in the next step:
blkid | grep /dev/sda -
Edit
/mnt/a/boot/grub/grub.cfgto replace UUID of/dev/sdain the menuentries accordingly -
Reboot the system
-
If you successfully booted, update grub.cfg properly:
update-grub -
Do not forget to install btrfs-tools:
apt-get install btrfs-tools
-
btrfs sub snap / /rootfs -
Create the new top subvolume mountpoint:
mkdir /rootfs/mnt/myhost -
Edit the
/etc/fstabnow (to save one reboot):/dev/sda / btrfs subvol=/rootfs,rw,noatime 0 1 /dev/sda /mnt/myhost btrfs subvolid=5,noatime 0 1 -
Edit the
linux ...lines in/boot/grub/grub.cfgaccordingly to mount /rootfs subvolume at boot time:... rootflags=subvol=rootfs ... -
Reboot
-
Check if everything went fine so far:
-
Check if there is any BTRFS error:
# cat /var/log/messages | grep -i btrfs | grep -i error -
Check that our new / is the rootfs subvolume:
# btrfs subvolume show / Name: rootfs ...
-
-
If everything went fine, update grub to reflect the appropriate changes:
### do not forget to backup your /boot/grub/grub.cfg first # update-grub -
Reboot
-
If everything still okay, cleanup the old files:
# find /mnt/myhost -maxdepth 1 -mindepth 1 -not -name rootfs -exec rm -r {} \; -
Fix your Grub
configfilelocation:You can load your configfile inside Grub Rescue Shell by the following command:
configfile (hd0)/rootfs/boot/grub/grub.cfg-
btrfs sub create /mnt/myhost/boot -
mv /boot/* /mnt/myhost/boot/ -
Add the following line to
/etc/fstabto mount/bootfrom/mnt/myhost/boot:/dev/sda /boot btrfs subvol=/boot,rw,noatime 0 1 -
update-grub
-