IntroductionThis guide covers converting a current siduction installation with the ext4 file system to the Btrfs file system. All data and configurations of the user should be preserved. The goal is to get a siduction on Btrfs that is as close as possible to a new installation.
In contrast to many instructions that can be found on the Internet, I refer here to the requirements and specifics of the siduction installation.
I tested this guide several times with a freshly installed siduction (KDE flavor) and then successfully applied it to one of my siduction installations (XFCE flavor).
Please read the man page btrfs-convert first, and note that a rollback of the conversion is not possible after the command 'btrfs balance' has been executed.
WarningWhen working on the file system, there is always a risk of data loss. It is strongly recommended to back up all important and personal data to an external medium.
Requirements- "/" on only one partition (in our example /dev/sda3)
- The "/" partition should be at least 50 GB in size.
- The total size of the "/" partition must also be at least 2.5 times the disk space currently being used, because an image of the previous system is created during the conversion.
- Where possible, clear the cache.
- The system must be up-to-date. (apt update && apt full-upgrade)
- Unused kernels (kernel-remover) and orphaned packages (apt autoremove) should be removed.
- Minimize system journal. (journalctl --vacuum-size 100M)
- Afterwards do "apt clean".
Perform conversiona)
Install the siduction-btrfs package if it is not already present.b)
Download siduction and create a bootable medium.c)
Reboot into live system, open a terminal, become root.d)
Filesystem Check /dev/sda3 (not mounted):# fsck.ext4 -f /dev/sda3
e)
Convert to Btrfs:# btrfs-convert /dev/sda3
This may take some time.
Attention: The UUID of the /dev/sda3 partition changed
f)
Mount the new Btrfs filesystem:# mount -t btrfs /dev/sda3 /mnt/
# cd /mnt/
Show Btrfs subvolume:
/mnt# btrfs subvolume list .
ID 256 gen 3 top level 5 path ext2_saved
The content, now with ext2_saved, and .snapshots:
/mnt# ls -a
. fll media sys
.. home mnt tmp
.autorelabel initrd.img opt usr
bin initrd.img.old proc var
boot lib root vmlinuz
dev lib32 run vmlinuz.old
disks lib64 sbin .xorgconfig-was-here
etc libx32 .snapshots
ext2_saved lost+found srv
g)
Create the recommended Btrfs subvolumes:/mnt# btrfs subvolume create @
Create subvolume './@'
/mnt# btrfs subvolume create @home
Create subvolume './@home'
/mnt# btrfs subvolume create @root
Create subvolume './@root'
/mnt# btrfs subvolume create @var@log
Create subvolume './@var@log'
/mnt# btrfs subvolume create @snapshots
Create subvolume './@snapshots'
/mnt# btrfs subvolume create @tmp
Create subvolume './@tmp'
Move the data to the subvolumes:
Be sure to follow the order, because we need the empty /home, /root and /var/log folders in the @ subvolume as mount points.
/mnt# rmdir lost+found (not necessary in Btrfs)
/mnt# mv home/* @home/
/mnt# mv root/.* @root/
if /root also contains files without leading dot
/mnt# mv root/* @root/
/mnt# mv var/log/* @var@log/
/mnt# mv [b-d]* @/
/mnt# mv [f-z]* @/
/mnt# mv etc @/
/mnt# mv .[!s]* @/
The result should be like this:
/mnt# ls -a
. .. @ ext2_saved @home @root .snapshots @snapshots @tmp @var@log
Set the subvolume @ as default:
/mnt# btrfs subvolume set-default @
The ext2_saved folder contains the backup image of the previous ext4 file system. This subvolume also includes the '.snapshots' folder. Beyond that, we see only the new subvolumes.
Optionally, use @data instead of @home. The /home directory remains in @. Move all personal data of the /home/<user> directory to @data and link them in /home/<user>. The configuration remains in /home. This way the user's configuration is also captured by system snapshots.
h)
Customize the /etc/fstab: Backup fstab:
# cd @/etc/
/mnt/@/etc# cp fstab fstab-bac
Comment out the old tmp entry:
/mnt/@/etc# sed -i 's!^tmp!# tmp!' fstab
Search for old UUID of /:
/mnt/@/etc# grep '^UU.* / ' fstab
UUID=0b99b209-fa46-4ae3-ab70-b247653ad6c1 / ext4 defaults,noatime 0 1
Search for new UUID of /:
/mnt/@/etc# blkid | grep sda3
/dev/sda3: UUID="d9772d13-bd51-4d48-9f55-60fea4d369e5" UUID_SUB="ea8...
Change / to new UUID, filesystemtyp, and options:
(use
your exact UUIDs and use copy&past from the output
above to insert the UUID)
/mnt/@/etc# sed -i 's!<old UUID>!<new UUID>!' fstab
/mnt/@/etc# sed -i 's!ext4.*!btrfs subvol=@,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1!' fstab
Add entries for the other subvolumes:
/mnt/@/etc# grep ' / ' fstab | sed -e 's!/ !/home!' -e 's!=@!=@home!' >>fstab
/mnt/@/etc# grep ' / ' fstab | sed -e 's!/ !/root!' -e 's!=@!=@root!' >>fstab
/mnt/@/etc# grep ' / ' fstab | sed -e 's!/ !/var/log!' -e 's!=@!=@var@log!' >>fstab
/mnt/@/etc# grep ' / ' fstab | sed -e 's!/ !/tmp!' -e 's!=@!=@tmp!' >>fstab
/mnt/@/etc# grep ' / ' fstab | sed -e 's!/ !/.snapshots!' -e 's!=@!=@snapshots!' -e 's!^!#!' >>fstab
The fstab file should look like this:
/mnt/@/etc# cat fstab
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=<new-UUID> / btrfs subvol=@,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
# tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
UUID=<new-UUID> /root btrfs subvol=@root,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
UUID=<new-UUID> /home btrfs subvol=@home,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
UUID=<new-UUID> /var/log btrfs subvol=@var@log,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
UUID=<new-UUID> /tmp btrfs subvol=@tmp,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
#UUID=<new-UUID> /.snapshots btrfs subvol=@snapshots,defaults,noatime,space_cache=v2,autodefrag,compress=zstd 0 1
i)
Unmount the new Brtfs filesystem and exit the terminal:/mnt/@/etc# cd /
# umount /mnt
# exit
j)
chroot into siduction on Btrfs with the desktop icon "siduction chroot helper"
k)
Backup initrd and create a new one: (use
your exact kernel label)
# cp /boot/initrd.img-6.2.9-1-siduction-amd64 /boot/initrd.img-6.2.9-1-siduction-amd64-bac
# mkinitramfs -o /boot/initrd.img-6.2.9-1-siduction-amd64 6.2.9-1-siduction-amd64
l)
Update the bootloader GRUB:# mount /boot/efi/ (only necessary with UEFI/GPT)
Backup grub.cfg
# cp /boot/grub/grub.cfg /boot/grub/grub.cfg-bac
Reactivate the file 09_siduction-btrfs and remove any systemd masking links.
# chmod 755 /etc/grub.d/09_siduction-btrfs
# rm /etc/systemd/system/siduction_btrfs* 2>/dev/null
Update and install Grub:
# update-grub
# grub-install
or,
with BIOS/MBR, and UEFI/GPT with multiple hard disks in the PC.
# grub-install /dev/sda
m)
Leave chroot and reboot into siduction on Btrfs.n)
Configure snapper: Open a terminal and become root.
Create the configuration for the directory '/' with the new name 'root':
# snapper -c root create-config -t default /
Here, errors occasionally occurred with Snapper during the tests. No configuration could be created.
The only remedy was to remove the packages in question using 'purge' and reinstall them.
# apt purge snapper* siduction-btrfs libbtrfs0 libsnapper6
# apt install snapper* siduction-btrfs libbtrfs0 libsnapper6
Now edit the file /etc/fstab in an editor with root privileges.
Remove the comment character '#' before the line with /.snapsnots. Save the file and close the editor.
Mount the subvolume '@snapshots' and reload systemd:
# mount /.snapshots/
# systenctl daemon-reload
Then change some key-value pairs of the snapper configuration for '/'.
# snapper -c root set-config ALLOW_USERS=<Username>
# snapper -c root set-config TIMELINE_CREATE=no
Now Snapper is active for the directory "/".
The Snapper configuration should be done with the help of the instructions at
https://manual.siduction.org/ "System Administration > Snapper".
to adapt it to your own needs.
o)
Emergency rollback of btrfs-convert: If significant problems occur, it is possible to roll back the conversion.
Reboot into the live system, open a terminal and become root.
# btrfs-convert -r /dev/sda3
The '.snapshots' folder must be removed manually.
# rmdir /.snapshots
p)
Remove backup flies: When the system works properly, we remove the backup copies created during the conversion.
Open a terminal, become root.
Remove the files:
# rm /etc/fstab-bac
# rm /boot/initrd.img-6.2.9-1-siduction-amd64-bac
# rm /boot/grub/grub.cfg-bac
Show Btrfs subvolume:
# btrfs subvolume list /
ID 256 gen 3 top level 5 path ext2_saved
ID 257 gen 283 top level 5 path @
ID 258 gen 286 top level 5 path @home
ID 269 gen 319 top level 5 path @root
ID 260 gen 328 top level 5 path @var@log
ID 261 gen 196 top level 5 path @snapshots
ID 262 gen 228 top level 5 path @tmp
Remove the backup subvolume ext2_saved, using its ID.
# btrfs subvolume delete --subvolid 256 /
Delete subvolume (no-commit): '//ext2_saved'
EVERYTHING DONEI hope the instructions were helpful.
If you have any questions, please post them here in the forum.