This How To will guide you to having an Ubuntu install with the default subvolumes of @ and @home as previous Ubuntu installs had.
I recently learned that the Ubuntu 24.04 installer no longer uses subvolumes when selecting BTRFS as a file system. IMO, there's very little point to using BTRFS without subvolumes.
Subvolumes allow you to separate parts of your installation which can make snapshots and backups easier and quicker (smaller) and use tools like "timeshift" or "snapper". Subvolumes are like separate partitions but have the ability to expand or contract in size as needed because, unlike partitions, subvolumes freely share all the available space of your file system. You can also use subvolumes to boot multiple distros from the same BTRFS file system. I have 5 distros installed to the same file system.
After initial install, you have / with the entirety of Ubuntu installed to the root BTRFS file system. This How To will convert your install into a subvolume installation as Ubuntu used in the past. This will allow the use of Timeshift and Snapper and make root and home snapshots and backups easier.
Bonus: Convert EXT4 to BTRFS, then follow this guide.
Although it's technically "no longer supported", the "btrfs-convert" tool still works to convert EXT4 to BTRFS. Historically, one of the complaints about this tool was that if left you with a root install (no subvolumes) like the latest Ubuntu does. To move from EXT4 to BTRFS, the steps are:
Note: If you are using a swap file for swap on EXT4, it will not work after conversion to BTRFS. See the "Some notes about Swap" section near the end for more info.
General Warning: Anytime you are messing with file systems or partitions, etc., you risk losing data or crashing your install. Make sure you have a usable backup of anything you don't want to risk losing. This How To has been tested and written based on a new installation but if you are using an existing install that you have modified, you'd better have a backup before proceeding.
Notes:
This How To was done on a non-UEFI install. If you are an UEFI expert please chime in on what other steps might be necessary.
To complete this successfully you must know the device name where you installed grub.
For the purposes of this How To, I will use "/dev/sda/" but your installation will likely be different.
If you are NOT SURE which drive GRUB is installed to, DO NOT proceed until you do.
STEP 1: Create the @ and @home subvolumes and make it bootable.
While running from Ubuntu using Terminal:
Create the @home subvolume:
Make the @ subvolume bootable by editing /etc/grub inside the @ snapshot:
Edit the root entry from this :
to this:
Add a new line exactly the same as the above, but change the mount point and subvolume names for home:
Move the contents of the /home folder from @ into the home subvolume:
You now have the two needed subvolumes.
STEP 2: Boot to the root subvolume
To expose the GRUB menu to make booting to the subvolume easier, edit /etc/default/grub;
and change:
to
Then update grub to use your edits:
If you're comfortable activating the GRUB menu without this edit, feel free to skip the above part.
Reboot.
When the GRUB menu appears, press the "e" key to edit the GRUB menu.
At the line that begins with "linux" add the subvolume name so it looks like this:
and near the end of that line, put this between "ro" and "quiet splash"
so it looks like this:
It doesn't actually have to be between them. It just has to be after the kernel version "root=UUID=..." part.
Edit the line that begins with "initrd" the same way we did the "linux" line at the beginning:
and press F10 to boot.
If you did everything right, it should immediately boot to your install from the subvolume. If not, reboot and start over at "Reboot" above.
STEP 3: Verify you are running from the subvolume and update grub:
To verify this worked, open Terminal again and enter:
The output should look like:
There will be more options inside the parenthesis but this is the only one that matters.
If you see this, you have booted successfully into the subvolume!
The final task is to update and re-install GRUB so the subvolume is the default boot from now on.
***NON-EFI USERS*** aka "Legacy" or "BIOS" boot:
***EFI USERS*** use this instead of the above set of commands:
Note that since we edited /etc/default/grub AFTER we took our snapshot, GRUB will hide the boot menu on reboot as before.
If you'd like, go through the above "verify" step again before preceding with the clean up. Do it now.
This is also a good time to reboot once again just to verify GRUB is all good.
STEP 4: Clean up the old install files to reclaim space.
First, we must mount the root file system:
Do the "ll" to verify you're on in the root file system. You will see what looks like your install but you will also see your subvolumes in the output:
Now delete everything except '@' and '@home' :
Now you may resume use of the system with your install inside a subvolume.
Some notes about SWAP:
If you are using a swap partition, no changes are necessary to swap. However, if you are using a swap file you must remove it and replace it with a swap subvolume that contains a correctly prepared swap file or you will not be able to take snapshots of @ and your swap will become corrupted. Documentation here: https://btrfs.readthedocs.io/en/latest/Swapfile.html
Remember you must mount the root file system to have access to it to add more subvolumes. This will allow access to the subvolumes for taking snapshots and making backups.
I recently learned that the Ubuntu 24.04 installer no longer uses subvolumes when selecting BTRFS as a file system. IMO, there's very little point to using BTRFS without subvolumes.
Subvolumes allow you to separate parts of your installation which can make snapshots and backups easier and quicker (smaller) and use tools like "timeshift" or "snapper". Subvolumes are like separate partitions but have the ability to expand or contract in size as needed because, unlike partitions, subvolumes freely share all the available space of your file system. You can also use subvolumes to boot multiple distros from the same BTRFS file system. I have 5 distros installed to the same file system.
After initial install, you have / with the entirety of Ubuntu installed to the root BTRFS file system. This How To will convert your install into a subvolume installation as Ubuntu used in the past. This will allow the use of Timeshift and Snapper and make root and home snapshots and backups easier.
Bonus: Convert EXT4 to BTRFS, then follow this guide.
Although it's technically "no longer supported", the "btrfs-convert" tool still works to convert EXT4 to BTRFS. Historically, one of the complaints about this tool was that if left you with a root install (no subvolumes) like the latest Ubuntu does. To move from EXT4 to BTRFS, the steps are:
- Run "grub-install --modules=btrfs" before converting.
- Shutdown and boot to a live USB or other install.
- Mount and run btrfs-convert on your EXT4 root file system. Use the "--uuid copy" option.
- Edit /etc/fstab to reflect the change from ext4 to btrfs.
- If you are using a swap file, while editing fstab also remark out (add # as the first character) the line for swap. If you are using a swap partition, you may skip this step.
- Reboot to your install.
- Run "sudo update-grub" insert BTRFS in grub.cfg.
Note: If you are using a swap file for swap on EXT4, it will not work after conversion to BTRFS. See the "Some notes about Swap" section near the end for more info.
General Warning: Anytime you are messing with file systems or partitions, etc., you risk losing data or crashing your install. Make sure you have a usable backup of anything you don't want to risk losing. This How To has been tested and written based on a new installation but if you are using an existing install that you have modified, you'd better have a backup before proceeding.
Notes:
This How To was done on a non-UEFI install. If you are an UEFI expert please chime in on what other steps might be necessary.
To complete this successfully you must know the device name where you installed grub.
For the purposes of this How To, I will use "/dev/sda/" but your installation will likely be different.
If you are NOT SURE which drive GRUB is installed to, DO NOT proceed until you do.
STEP 1: Create the @ and @home subvolumes and make it bootable.
While running from Ubuntu using Terminal:
Code:
sudo btrfs subvolume snapshot / /@
Code:
sudo btrfs subvolume create /@home
Code:
sudo nano /@/etc/fstab
Code:
/dev/disk/by-uuid/<UUID> / btrfs defaults 0 1
Code:
/dev/disk/by-uuid/<UUID> / btrfs subvol=@,defaults 0 1
Code:
/dev/disk/by-uuid/<UUID> /home btrfs subvol=@home,defaults 0 1
Code:
sudo mv /@/home/* /@home/
STEP 2: Boot to the root subvolume
To expose the GRUB menu to make booting to the subvolume easier, edit /etc/default/grub;
Code:
sudo nano /etc/default/grub
Code:
GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0
Code:
GRUB_TIMEOUT_STYLE=menu GRUB_TIMEOUT=10
Code:
sudo update-grub
Reboot.
When the GRUB menu appears, press the "e" key to edit the GRUB menu.
At the line that begins with "linux" add the subvolume name so it looks like this:
Code:
linux /@/boot/...
Code:
rootflags=subvol=@
Code:
ro rootflags=subvol=@ quiet splash
Edit the line that begins with "initrd" the same way we did the "linux" line at the beginning:
Code:
initrd /@/boot/...
If you did everything right, it should immediately boot to your install from the subvolume. If not, reboot and start over at "Reboot" above.
STEP 3: Verify you are running from the subvolume and update grub:
To verify this worked, open Terminal again and enter:
Code:
mount |grep ' / '
Code:
/dev/sda2 on / type btrfs (...subvol=/@...)
If you see this, you have booted successfully into the subvolume!
The final task is to update and re-install GRUB so the subvolume is the default boot from now on.
***NON-EFI USERS*** aka "Legacy" or "BIOS" boot:
Code:
sudo update-grub sudo grub-install /dev/sda reboot
Code:
sudo update-grub grub-install --efi-directory=/boot/efi reboot
If you'd like, go through the above "verify" step again before preceding with the clean up. Do it now.
This is also a good time to reboot once again just to verify GRUB is all good.
STEP 4: Clean up the old install files to reclaim space.
First, we must mount the root file system:
Code:
sudo mount /dev/sda2 /mnt cd /mnt ll
Code:
... '@'/ '@home' bin ...
Code:
shopt -s extglob sudo rm -rf !(@*) shopt -u extglob
Some notes about SWAP:
If you are using a swap partition, no changes are necessary to swap. However, if you are using a swap file you must remove it and replace it with a swap subvolume that contains a correctly prepared swap file or you will not be able to take snapshots of @ and your swap will become corrupted. Documentation here: https://btrfs.readthedocs.io/en/latest/Swapfile.html
Remember you must mount the root file system to have access to it to add more subvolumes. This will allow access to the subvolumes for taking snapshots and making backups.
Comment