Skip to content

Instantly share code, notes, and snippets.

@hippotized
Forked from pakyrs/ext4_to_btrfs
Created October 23, 2022 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hippotized/ca332b6fa60e47273473dab31047b117 to your computer and use it in GitHub Desktop.
Save hippotized/ca332b6fa60e47273473dab31047b117 to your computer and use it in GitHub Desktop.
Convert root ext4 to btrfs including subvolumes and snapper
# on your ext4 distro
sudo su
apt install btrfs-progs
shutdown now
# switch to a linux live environment
sudo su
fsck -f /dev/vda3
# BTRFS convert
btrfs-convert /dev/vda3
# Move the Root filesystem from rescue
mount /dev/vda3 /mnt
btrfs subvol create /mnt/@
btrfs subvolume delete /mnt/ext2_saved
mv /mnt/* /mnt/@/
btrfs subvol create /mnt/@home
mv /mnt/@/home/* /mnt/@home/
# FSTAB
blkid /dev/vda3 | awk '{print $2}'
vim /mnt/@/etc/fstab
--- comment the / ext4 line
UUID=9fb8437d-783c-4f2c-8c38-56290764b1ad / btrfs subvol=/@ 0 1
UUID=9fb8437d-783c-4f2c-8c38-56290764b1ad /home btrfs subvol=/@home 0 2
---
# CHROOT
umount -l /mnt/
mount /dev/vda3 /mnt/ -t btrfs -o subvol=@
for fs in proc sys dev dev/pts; do mount --bind /$fs /mnt/$fs; done
chroot /mnt /bin/bash
# GRUB
mount /boot/efi
grub-install --no-nvram /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg
# list subvolumes
btrfs subvolume list / -t
# finish
exit
reboot
# check
sudo su
btrfs subvolume list / -t
btrfs filesystem df /
## SNAPPER:
sudo snapper -c root create-config /
sudo sed -i 's/^ALLOW_USERS=.*/ALLOW_USERS="pacadmin"/' /etc/snapper/configs/root
# Change permissions and ownership to snapshot directory:
sudo chmod a=rx /.snapshots/
sudo chown :pacadmin /.snapshots/
# Create snapshots:
snapper -c root create --description AfterMigration
# List snapshots under root config:
snapper -c root list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment