Install Ubuntu Server 20.04 on Btrfs

Install Ubuntu Server 20.04 on Btrfs

I have summarized the procedure when the root file system of Ubuntu Server 20.04 is set to Btrfs.

About Btrfs subvolumes

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.

About the layout of Btrfs subvolumes

OpenSUSE is a good reference for the layout of Btrfs subvolumes. The default file system for openSUSE uses Btrfs.

Storage layout settings

In the storage layout settings, select Custom storage layout.

Screenshot_ubuntu20.04_2020-10-18_01:01:40.png

Create a partition for the boot device.

Screenshot_ubuntu20.04_2020-10-18_01:01:55.png

Add a GPT partition.

Screenshot_ubuntu20.04_2020-10-18_01:02:12.png

Format with btrfs and mount point to /.

Screenshot_ubuntu20.04_2020-10-18_01:02:23.png

Write the partition table to disk and continue the installation.

Screenshot_ubuntu20.04_2020-10-18_01:02:36.png

After the installation is complete, proceed to the next step without rebooting.

Screenshot_ubuntu20.04_2020-10-18_09:02:29.png

Creating a Btrfs subvolume

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

Screenshot_ubuntu20.04_2020-10-18_09:07:45.png

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.

Screenshot_ubuntu20.04_2020-10-18_09:15:38.png

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

Creating a swap file

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.

Screenshot_ubuntu20.04_2020-10-18_09:02:29.png

References

  1. Install Ubuntu 18.04 Server on btrfs - work-work.work
  2. 18.04 - Where are my BTRFS subvolumes? - Ask Ubuntu
  3. Ubuntu 20.04 with btrfs-luks-RAID1 full disk encryption including /boot and auto-apt snapshots with Timeshift | Willi Mutschler
  4. Using Btrfs for Easy Backup and Rollback | John Ramsden
  5. Creating openSUSE-style btrfs root partition & subvolumes
  6. SDB:BTRFS - openSUSE Wiki
  7. swap - Can I have a swapfile on btrfs? - Ask Ubuntu

Recommended Posts

Install Ubuntu Server 20.04 on Btrfs
Install Docker on Ubuntu Server 20.04
Install pyqt5 on ubuntu
Install Autoware on Ubuntu 18.04.5
Install Homebrew on Ubuntu 20.04
Build VNC Server on Ubuntu 20.04
Install zabbix agent (5.0) on Ubuntu 18.04
Install Arudino IDE on Ubuntu 20
Install Ubuntu Desktop 20.10 on RaspberryPi4
Install raspi-config on Ubuntu 20.04 (LTS)
Install WordPress 5.5 on Ubuntu 20.04 LTS
Note: Install PostgreSQL 9.5 on Ubuntu 18.04
Install AWS IoT Greengrass on Ubuntu
Install JDK and JRE on Ubuntu 16.10
Install ngrok on ubuntu16.04 using Vagrant
How to install WildFly on Ubuntu 18.04
Install MQTT broker Mosquitto on Ubuntu 18.04
Install SonarQube on ECS instance on Ubuntu 16.04
Install ruby on Ubuntu 20.04 with rbenv
How to install production Metabase on Ubuntu
I want to install PHP 7.2 on Ubuntu 20.04.
Install Realtek network driver on Ubuntu Note
Install Ubuntu Server 20.04 in VirtualBox on Mac and connect with SSH
tmux on Ubuntu
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Install Ubuntu Core 18 on Raspberry Pi 2 Model B
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
Set up an SSH server on WSL2 Ubuntu 20.04
How to install multiple JDKs on Ubuntu 18.04 LTS
Install and switch between multiple Javas on Ubuntu
Install the latest version of Jenkins on Ubuntu 16
Screen recording on Ubuntu 20.04
Web Bluetooth on Ubuntu20.04
Install gradle on mac
Install OpenJDK on macOS
Try DisplayLink on Ubuntu 20.04
Reinstall Kubernetes on Ubuntu 19.10
Install Java on Mac
Install Golang on CentOS 8
Use Flutter on Ubuntu
Install Neo4j 4.1.3 on centOS
Install ROS Noetic ubuntu20.04
Install Vertica 10.0 on CentOS 6.10
Install Gradle with ubuntu16.04
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Setting JAVA_HOME on Ubuntu
Put JetBrains on Ubuntu
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Use mkdir on ubuntu
Use cpplapack on ubuntu
ubuntu on wsl part 10
Run tiscamera on Ubuntu 18.04
Install Redmine 4.1.1 on CentOS 7
Install OpenJDK 8 on mac
Smokeping Install on CentOS7
Build Zabbix on Ubuntu 20.04
Install PostgreSQL 13 on CentOS 7.5