Skip to content

Instantly share code, notes, and snippets.

@rustybird
Last active April 20, 2021 14:42
Show Gist options
  • Save rustybird/0ccb0131deace38231c02429f08762f5 to your computer and use it in GitHub Desktop.
Save rustybird/0ccb0131deace38231c02429f08762f5 to your computer and use it in GitHub Desktop.

EXPERIMENTAL: Convert a Qubes R4.0 installation from file on ext4 to file-reflink on btrfs

  1. Ensure that you have a working backup of all VMs.

  2. Find the UUID of the LUKS device hosting the dom0 ext4 root filesystem:

    grep -Eo '^/dev/mapper/luks-[0-9a-f-]{36} / ext4 ' /proc/mounts | cut -b 18-54
    

    Write down the output on a piece of paper.

  3. For those dom0 kernels with btrfs support built as a module, include it in their initrds:

    sudo dracut --regenerate-all --force --add-drivers btrfs
    
  4. Reboot into a Qubes R4.1 installer (not R4.0, which has a severely broken btrfs-convert version!), and switch to a console.

  5. Decrypt the ext4 root filesystem:

    cryptsetup open /dev/disk/by-uuid/YOUR-LUKS-UUID-FROM-STEP-ONE rootfs
    
  6. Convert the decrypted filesystem to btrfs, and restore its old filesystem UUID:

    FSUUID=$(blkid -s UUID -o value /dev/mapper/rootfs)
    echo $FSUUID
    
    e2fsck -f     /dev/mapper/rootfs
    btrfs-convert /dev/mapper/rootfs
    btrfs check   /dev/mapper/rootfs
    
    btrfstune -U $FSUUID /dev/mapper/rootfs
    
  7. Switch the varlibqubes pool driver from file to file-reflink:

    mkdir /mnt/rootfs
    mount /dev/mapper/rootfs /mnt/rootfs
    
    sed '/ name="varlibqubes"/s/ driver="file"/ driver="file-reflink"/' -i.bak /mnt/rootfs/var/lib/qubes/qubes.xml
    diff -u /mnt/rootfs/var/lib/qubes/qubes.xml{.bak,}
    
    umount /mnt/rootfs
    
  8. Reboot into Qubes

  9. Check that the varlibqubes pool has been switched to file-reflink:

    qvm-pool
    
  10. Everything's working? Then clean up the remaining file/ext4 cruft:

    sudo rm -f /var/lib/qubes/*/*/*-cow.img*
    sudo btrfs subvolume delete /ext2_saved
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment