I have summarized the procedure when the root file system of Ubuntu Server 20.04 is set to Btrfs.
Btrfs subvolumes can be mounted individually and displayed as subdirectories. In addition, Btrfs snapshots can be quickly created with the copy-on-write (CoW) function.
OpenSUSE is a good reference for the layout of Btrfs subvolumes. The default file system for openSUSE uses Btrfs.
In the storage layout settings, select Custom storage layout
.
Create a partition for the boot device.
Add a GPT partition.
Format with btrfs and mount point to /
.
Write the partition table to disk and continue the installation.
After the installation is complete, proceed to the next step without rebooting.
After the installation is complete, press ALT
+ F2
without rebooting to switch to the console. Here is the route.
sudo -i
Shows the mounted devices. Ubuntu is installed in / target
.
mount -l | grep /target
Unmount / target
and mount the disk on / mnt
.
umount -l /target
mount /dev/vda2 /mnt
You can view the list of block devices with lsblk
.
Create a subvolume.
cd /mnt
btrfs subvolume create @
btrfs subvolume create @/home
btrfs subvolume create @/opt
btrfs subvolume create @/root
btrfs subvolume create @/srv
btrfs subvolume create @/tmp
chmod 1777 @/tmp
mkdir @/usr
btrfs subvolume create @/usr/local
btrfs subvolume create @/var
btrfs subvolume create @/swap
Disable copy-on-write (CoW) on / var
to improve performance.
chattr +C /mnt/@/var
Move all files and folders to a subvolume.
shopt -s dotglob
mv home/* @/home
mv root/* @/root
mv usr/local/* @/usr/local
mv var/* @/var
rmdir home opt root srv usr/local tmp var
ls | grep -v @ | xargs mv -t @
Unmount / mnt
to mount all the devices needed for your system.
umount /mnt
mount -o subvol=@ /dev/vda2 /target
mount /dev/vda2 /target/boot/efi
mount --bind /proc /target/proc
mount --bind /dev /target/dev
mount --bind /sys /target/sys
Press ALT
+ F3
to switch to the third window and chroot
to switch the system.
sudo -i
chroot /target
Edit fstab to set the appropriate mount point for the subvolume.
vi /etc/fstab
UUID=xxxx / btrfs defaults,ssd,noatime,space_cache,commit=120,compress=zstd,subvol=@ 0 1
/swap/swapfile none swap sw 0 0
Copy-on-write (CoW) must be disabled to create a swap file on a Btrfs subvolume. However, if there are files with copy-on-write (CoW) disabled, you will not be able to take snapshots. Therefore, create a subvolume for the swap file and create a swap file there.
touch /swap/swapfile
chmod 0600 /swap/swapfile
chattr +C /swap/swapfile
fallocate /swap/swapfile -l 2g
mkswap /swap/swapfile
Finally update GRUB.
update-initramfs -u -k all
grub-install --recheck /dev/sda
update-grub
Press ALT
+ F1
to switch to the first window and reboot.
Recommended Posts