Skip to content

Instantly share code, notes, and snippets.

@deltanart
Created March 15, 2025 15:18
Show Gist options
  • Select an option

  • Save deltanart/ee3ca75181b8ea9d58b7cd1ddfb6c585 to your computer and use it in GitHub Desktop.

Select an option

Save deltanart/ee3ca75181b8ea9d58b7cd1ddfb6c585 to your computer and use it in GitHub Desktop.
convert ext4 to btrfs

convert a partition from ext4 to btrfs

Sources (March 2025):

Important

these steps worked for me! your milage may vary!
remember that these steps could lead to an UNBOOTABLE system or to DATALOSS.
take nessesary precaution and backups!

boot into a live envirionment

  • create a backup of the disc with dd
  • convert the ext4 volume into a new btrfs volume
sudo btrfs-convert <DISK>
  • mount the new volume and navigate into it.
sudo mount -o subvol=@ /dev/sdxY /mnt
  • create a new btrfs sub volume
sudo btrfs subvol create @

Important

For Timeshift to work the root subvolume must be named @.
(optional) More Subvolumes can be created like @home, @cache and so on.

  • move / into the new subvolume.
    • (the error, that @ cannot be moved into itself can be ignored)
sudo mv * @/

chroot into the new btrfs partition

mount the root partition

sudo mount -o subvol=@ /dev/sdxY /mnt

mount the boot partition

sudo mount /dev/sdzY /mnt/boot

mount the efi partition (UEFI Boot)

sudo mount /dev/sdwY /mnt/boot/efi

mount system

for dir in /dev /dev/pts /proc /sys /run; do sudo mount --bind $dir /mnt$dir; done

chroot into the installation

sudo chroot /mnt /bin/bash

change /etc/fstab

  • set UUID of the new disc
  • type von ext4 zu btrfs ändern.
  • set these options:
    • defaults,noatime,space_cache=v2,compress=zstd:3,subvol=@
  • defrag the btrfs filesystem and compress it:
sudo btrfs fi defragment / -r -czstd

Important

the root partition is now compressed. To mount it in the future use:

sudo mount -o subvol=@ -o compress=zstd /dev/sdxY /mnt

update grub

when chroot'ed into the system it should be enough to just update the grub config:

sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo update-grub

otherwise try:

edit the file `/boot/efi/EFI/ubuntu/grub.cfg

  • set the new UUID of the Root-Partition
  • update the path with the prefix /@

update the grub launcher directly:

  • File location: /boot/grub/grub.cfg
  • search for submenu
    • old value: /boot/vmlinuz...
    • new value: /@/boot/vmlinuz...
    • update the UUID
    • add rootflags=subvol=@ after ro

update initramfs

  • if a swap-partition and the file /etc/initramfs-tools/conf.d/resume exists, update the UUID inside this file.
  • install btrfs-progs if not already present: sudo apt install btrfs-progs
  • finally sudo update-initramfs -u

now reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment