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.

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.

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

Debian grub auto configuration script (as of 2022/buster) is compatible with this usage.

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:

For maximum flexibility and simplicity, I am using my shell scripts bss .