[ Content contribution] [Btrfs Now] Installing rootfs with btrfs & Set the restore env
Technology Exchange 870 views · 0 replies ·
Ziggy
deepin
2024-03-27 10:57
Author
[Btrfs Now] Installing the rootfs into the btrfs subvols for deepin & Set the restore env
Pre-preparation
Installation Preparation
Prepare a installation image and flash it with a mobile storage device, a kernel with version 5.10+ is recommend, which has a better support for btrfs.
Set 2 partitations in advance.
A btrfs partitation as the main rootfs.
A live system with full functions.
An independent partition to install the initial system. It could be installed into an extranal hard disk instead. When the hard disk where btrfs located is broken, it can be restored as a rootb backup. Use non-btrfs format for differentiation(Recommended)
Create subvols for btrfs partitation.
Mount the btrfs partitation to /mnt,then create some required subvols.
The btrfs partitation is /dev/sdb3 according to the lsblk,then mount it.
root@ziggy-PC:~# mount /dev/sdb3 /mnt/
When the btrfs partition is mounted as /mnt,/mnt is the btrfs rootfs and does not have any subvolume functions. In addition, btrfs is still in developing and depends on the boot sequence of btrfs grub, it is recommended to set up a root subvolume separately from the system subvolume to serve as the boot one.
The following example sets the subvolumes in sequence "@main(btrfs rootfs),@home (users home directory),@opt (applications directory),@root(the home of root, optional)"
Boot the installation flash, select non-btrfs format volumes as "/" mount points for installation, and select only "/" mount points for installation during installation to facilitate subsequent data migration. Suggested mount examples: "/" root directory (required), swap files (optional),efi (if UEFI boot)
Data Syns
For two well-known reasons, after installing the initial system, if we want the system to run normally on the btrfs volume and enable the snapshot function, we need to manually sync the installed system to the btrfs subvols.
The deepin-installer does support to install the system into the btrfs subvols so far.
The initial system env is the most clean one before the configure step.
Check the lsblk result,the "/dev/sda1" is the initial system path while "/dev/sdb3/@main" is the main rootfs of the btrfs subvols.
After confirmation, use the rsync to sync the data. Since "@ home,@ opt,@ root" are divided separately in this example, the data of the corresponding directory in the initial system also needs to be synchronized to the subvol.
After the data sync is complete, several configuration files need to be reconfigured due to the inconsistency between the btrfs subvols and the original installation path.
/boot
The grub.cfg boot file needs to be modified in the/boot directory, which can be divided into several steps.
"Firmware==>efi files==>Grub==>Btrfs rootfs==>the Grub of Btrfs subvols==>The rootfs of Btrfs subvols"
Replace the UUID of the initial system with the UUID of the btrfs partitation by searching.
Observe the reference to the absolute path of the system in the grub.cfg file and add "/@ main" before "/" to indicate that the path is the path in the subvolume after modification.
Add "rootflags=subvol=@main" to the linux line to indicate that the @main subvols would be boot.
linux /@main/boot/vmlinuz-6.1.32-amd64-desktop-hwe root=UUID=68e253cf-9282-47b3-b087-9c5910950c88 ro splash quiet rootflags=subvol=@main DEEPIN_GFXMODE=$DEEPIN_GFXMODE
initrd /@main/boot/initrd.img-6.1.32-amd64-desktop-hwe
/etc
Modify the fstab file and modify the mount information according to the actual subvolume and requirements. The core here is the root directory mount point setting. Other mount points can be modified by referring to the root directory mount point. Only the subvol pointing to the subvolume needs to be modified.
Modify the/etc/default/grub file and add "rootflags=subvol=@main" to the "GRUB_CMDLINE_LINUX_DEFAULT" field, so that the startup command will be automatically added to the new grub file after run "update-grub"
root@ziggy-PC:/boot/grub# cat /etc/default/grub
# Written by org.deepin.dde.Grub2
GRUB_CMDLINE_LINUX_DEFAULT="splash quiet rootflags=subvol=@main"
EFI(If UEFI boot)
Get the UUID of the partition where the/boot/efi mount point is located through lsblk and mount it to/mnt
root@ziggy-PC:/boot/grub#mount /dev/sdb1 /mnt
Enter to the/mnt , find the boot and deepin directories, and modify the grub.cfg file. Change "search.fs_uuid" to the UUID information corresponding to the btrfs parent volume, and add the path corresponding to the subvolume to "set prefix"
Since the @main subvolume mentioned earlier is used for the rootfs and is not intended to be used as a common system subvolume, create a @sys snapshot subvolume on that basis to use as a daily environment.
After the snapshot is created, as the subvolume has changed, you need to repeat the "### file configuration" step to adjust the contents of the new subvolume, but the common file does not need to be changed.
/boot
Modify the grub.cfg file in the @sys subvolume, and add "rootflags=subvol=@sys" to the linux line to indicate that grub boots the @sys subvolume in the btrfs parent volume, and both initrd and linux paths in the boot entry need to be modified to the current system @sys subvolume
/etc
Modify the fstab file in the @sys subvolume and modify the mount information according to the actual subvolume and requirements. The core here is the root directory mount point setting. Other mount points can be modified by referring to the root directory mount point. Only the subvol pointing to the subvolume required to be modified.
Modify the/etc/default/grub file and add "rootflags=subvol=@sys" to the "GRUB_CMDLINE_LINUX_DEFAULT" field, so that the startup command will be automatically added to the new grub file after run "update-grub"
Restore ENV Setup
Since the "initialization" environment is still essentially as the form of snapshot subvolumes, you only need to create a snapshot as the @main like other snapshot subvols.That is a read-only snapshot of the @sys subvolume can by using "@snaps/@ restore subvolume" under the same btrfs parent volume (supporting customization of personal habits) and modifying the corresponding files of/etc. The "-r" parameter of the snapshots means that is a read-only snapshot.
Since the system installed through the installer usually has an "advanced menu", I suggest to use the advanced menu directly and modify its description to "Restore",initrd and linux paths to their own initialization environment subvolumes. This allows you to enter the initialization environment when you select the Restore menu to boot.
**However, it is worth noting that it is recommended to snaps "@restore subvolume" to a new subvolume in the form of snapshot before performing user configuration operations, which can greatly avoid the initialization environment from being broken. * *
[Btrfs Now] Installing the rootfs into the btrfs subvols for deepin & Set the restore env
Pre-preparation
Installation Preparation
Create subvols for btrfs partitation.
The btrfs partitation is /dev/sdb3 according to the lsblk,then mount it.
System Setup
Initial System Installation
Data Syns
For two well-known reasons, after installing the initial system, if we want the system to run normally on the btrfs volume and enable the snapshot function, we need to manually sync the installed system to the btrfs subvols.
Files Reconfiging
After the data sync is complete, several configuration files need to be reconfigured due to the inconsistency between the btrfs subvols and the original installation path.
/boot
The grub.cfg boot file needs to be modified in the/boot directory, which can be divided into several steps.
"Firmware==>efi files==>Grub==>Btrfs rootfs==>the Grub of Btrfs subvols==>The rootfs of Btrfs subvols"
Replace the UUID of the initial system with the UUID of the btrfs partitation by searching.
Observe the reference to the absolute path of the system in the grub.cfg file and add "/@ main" before "/" to indicate that the path is the path in the subvolume after modification.
Add "rootflags=subvol=@main" to the linux line to indicate that the @main subvols would be boot.
/etc
EFI(If UEFI boot)
Snapshots Setup
Since the @main subvolume mentioned earlier is used for the rootfs and is not intended to be used as a common system subvolume, create a @sys snapshot subvolume on that basis to use as a daily environment.
After the snapshot is created, as the subvolume has changed, you need to repeat the "### file configuration" step to adjust the contents of the new subvolume, but the common file does not need to be changed.
/boot
/etc
Restore ENV Setup
Since the "initialization" environment is still essentially as the form of snapshot subvolumes, you only need to create a snapshot as the @main like other snapshot subvols.That is a read-only snapshot of the @sys subvolume can by using "@snaps/@ restore subvolume" under the same btrfs parent volume (supporting customization of personal habits) and modifying the corresponding files of/etc. The "-r" parameter of the snapshots means that is a read-only snapshot.
Since the system installed through the installer usually has an "advanced menu", I suggest to use the advanced menu directly and modify its description to "Restore",initrd and linux paths to their own initialization environment subvolumes. This allows you to enter the initialization environment when you select the Restore menu to boot.
**However, it is worth noting that it is recommended to snaps "@restore subvolume" to a new subvolume in the form of snapshot before performing user configuration operations, which can greatly avoid the initialization environment from being broken. * *