Translation(s): English
FileSystem > Btrfs > Btrfs migration
Here is a simple tutorial guide of system migration from ext4 to btrfs. This migration should be safer with dual boot system.
Contents
Overview
Although you can boot the system with a USB memory stick with Debian installer and do essentially the same to migrate system to btrfs, it is safer strategy to migrate a system while making system dual boot.
Dual boot preparation
Here is required preparation before running sudo update-grub to set up grub menu.
More through boot system update for UEFI system with NVRAM variables is offered by sudo dpkg-reconfigure grub-efi-amd64.
Semi-manual grub configuration
So far, grub auto OS detection is flaky for btrfs, Let me recap simple semi-manual grub configuration.
I usually add following as /etc/grub.d/40_fixed_linux (The first line should be #!/bin/bash without space. Intentional mistype to avoid missing line):
# !/bin/sh exec tail -n +3 $0 # This file provides an easy way to add custom menu entries. Simply type the # menu entries you want to add after this comment. Be careful not to change # the 'exec tail' line above. menuentry 'Debian GNU/Linux --- main SSD' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-fixed-fe3e1db5-6454-46d6-a14c-071208ebe4b1' { load_video insmod gzio if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi insmod part_gpt insmod btrfs search --no-floppy --fs-uuid --set=root fe3e1db5-6454-46d6-a14c-071208ebe4b1 echo 'Loading Linux from /dev/nvme0n1p5 ...' linux /@rootfs/vmlinuz root=UUID=fe3e1db5-6454-46d6-a14c-071208ebe4b1 ro rootflags=subvol=@rootfs quiet echo 'Loading initial ramdisk from /dev/nvme0n1p5 ...' initrd /@rootfs/initrd.img } menuentry 'Debian GNU/Linux --- sub SSD' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-fixed-51f9cd11-30b3-4d99-b2ed-fe411fa22ee6' { load_video insmod gzio if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi insmod part_gpt insmod btrfs search --no-floppy --fs-uuid --set=root 51f9cd11-30b3-4d99-b2ed-fe411fa22ee6 echo 'Loading Linux from /dev/nvme1n1p1 ...' linux /@rootfs/vmlinuz root=UUID=51f9cd11-30b3-4d99-b2ed-fe411fa22ee6 ro rootflags=subvol=@rootfs quiet echo 'Loading initial ramdisk from /dev/nvme1n1p1 ...' initrd /@rootfs/initrd.img }
Here UUID needs to be adjusted accordingly. If one of the system is ext4, adjustment needs to be made.
Note on `/boot/efi/EFI/debian/grub.cfg`
If you install multiple Debian systems to dual boot, this becomes quite tricky.
The first line search.fs_uuid fe3e1db5-6454-46d6-a14c-071208ebe4b1 root specifies the root file system seen by grub.
- If the UUID in the above is not the one for your currently running system root device, you need to make it to match it.
Otherwise, /boot/grub/grub.conf updated by running update-grub will not update grub menu.
Install 2nd OS
The debian-installer can installs Debian system to btrfs partition and it uses @rootfs subvolume (bullseye).
Migration of the existing root filesystem to Btrfs
- Boot the 2nd Linux system.
Convert the partition containing the primary old Linux system from ext4 to btrfs using btrfs-convert.
Migrate the system root filesystem to /@rootfs for the primary Linux system.
sudo btrfs subvolume snapshot / /@rootfs
sudo btrfs subvolume set-default /@rootfs
- This converts the top level subvolume (id=5) of the btrfs as the new system root filesystem.
- Check the new UUID of the partition containing the primary Linux system.
Update /etc/fstab of the secondary Linux system.
Change from ext4 errors=remount-ro to btrfs defaults
Update /boot/grub/grub.cfg.
Change insmod ext2 to insmod btrfs
Update /boot/efi/EFI/debian/grub.cfg
Add /etc/grub.d/40_fixed_linux
Execute sudo update-grub
- Confirm the successful booting of the new primary Linux system on btrfs.
- Boot the primary Linux system.
Update /etc/fstab of the secondary Linux system.
Change from ext4 errors=remount-ro to btrfs defaults
Update /boot/grub/grub.cfg.
Change insmod ext2 to insmod btrfs
Update /boot/efi/EFI/debian/grub.cfg
Add /etc/grub.d/40_fixed_linux
Execute sudo dpkg-reconfigure grub-efi-amd64
Debian grub auto configuration script (as of 2022/buster) is compatible with this usage.
Debain uses subvol=@rootfs for root filesystem for btrfs.
Both Suse and Ubuntu seem to use subvol=@ for root filesystem for btrfs.
Ubuntu's current /etc/grub.d/30_os-prober checks @ and bind mount it as root if it exists to avoid missing the system installation.
Keeping the root filesystem in a subvolume makes it more flexible. I usually deploy flat layout to keep my home directory /home/<username> as an independent subvolume /@<username> and explicitly mount it via /etc/fstab. You may alternatively keep the whole /home as a subvolume.
Use snapshot with btrfs
One of the greatest feature of btrfs is snapshot. There are a few interesting packages in Debian:
btrbk -- perl based
timeshift -- GUI, Ubuntu specific? (Debian needs patch since its use of @rootfs)
snapper -- CLI, Suse orign
For maximum flexibility and simplicity, I am using my shell scripts bss .