9

I'm using btrfs successfully and have luckily separate home and system partitions.

Using Ubuntu 13.10 and wanting to test 14.04, how can I do this using the btrfs file system?

The system has an EFI partition, but no extra boot partition. /boot is inside the system partition (/@/boot).

3
  • If you make a live CD or bootable USB it should give you the option of installing Ubuntu 14.04 alongside Ubuntu 13.10 without the need for btrfs, does it not?
    – Stephen
    Jan 5, 2014 at 13:27
  • Both are alongside then on the same partition? How does this work? Just knew it using separate partitions.
    – Borph
    Jan 5, 2014 at 14:46
  • 1
    Yes, this approach requires a separate partition, or overwrites the preexisting Ubuntu. -1: does not answer the question, and spreads the incorrect assumption that one should avoid btrfs
    – ignis
    Jan 6, 2014 at 9:09

1 Answer 1

13

Yes, you can. This is what I use at the very moment. The other cool thing is that you can bedup the partition after you have installed many similar OSes (like Ubuntu and Linux Mint) to conserve a lot of hard disk space.

The trick is to rename the default subvolumes: @ and @home into something unique to the distribution installation, e.g. @ -> @mint or @trusty and @home into @homemint or @hometrusty.

This can be done at any moment after the installation of the first system, before the installation of the second. The most error-safe way is to take a snapshot of the subvolumes, for instance like this:

  1. mount root subvolume of the system btrfs partition (assumed to be /dev/sda3) somewhere, e.g. to /mnt: sudo mount btrfs /dev/sda3 /mnt
  2. Optional: list the already existing subvolumes - just check you don't create name conflicts in the following steps: sudo btrfs subvolume list /mnt
  3. Clone the main @ subvolume: sudo btrfs subvolume snapshot /mnt/@ /mnt/@trusty
  4. Clone the home. I strongly don't recommend sharing the whole home subvolume across different systems. (For shared documents create another subvolume, or even better a separate partition, link it with ~/Documents, ~/Desktop etc. and share that): sudo btrfs subvolume snapshot /mnt/@home /mnt/@trustyhome
  5. Edit /mnt/@trusty/etc/fstab on the new root @trusty to reflect the change the @home -> @trustyhome subvolume (and @ -> @trusty, but that step is not strictly necessary, because by the time the system reads @trusty/etc/fstab it must have already assumed the correct subvolume for root).
  6. Edit /boot/grub/grub.cfg: modify all lines that call the current kernel (they look like this: linux /vmlinuz-3.16.0-50-generic.efi.signed root=UUID=9e571eab-4c88-4913-baa3-8d41d94f73d5 ro recovery nomodeset rootflags=subvol=@) and change the rootflags=subvol=@ into rootflags=subvol=@trusty, so the kernel knows what to boot. Rather miraculously this setting will be preserved when you do update-grub.
  7. Reboot and do sudo mount and verify that the correct new subvolumes are used instead of @ and @home <- This is step is really important, otherwise you will loose your data

And once you renamed the subvolumes, and made sure that system boots, and made sure that there is no @ and @home - install the next OS, with one modification: use a separate /boot partition (800MB should be enough). It helps if your partitions use GPT rather than MBR, which fortunately has became a norm. (To quickly tell if you are using GPT is to see if you boot with UEFI on the motherboard BIOS setup. UEFI works only with partitions set-up in GPT format.

If you don't set up the separate /boot partition - the system will not boot, but you can fix it if you follow the @HullCityFan852 comment:

If you don't have a separate /boot partition then the reboot in Step 7 will fail and you will be left at the grub rescue prompt. At this prompt, type set prefix=($root)/@mint/boot/grub (replace @mint with the path to your distro's subvolume) and then type insmod normal and finally normal to load the Grub menu and boot your distro. Once booted, type sudo update-grub && sudo grub-install to make the change permanent

At the partitioning dialog, use custom partitioning and install the system on the same partition as the first OS. Just be sure, that you tell the installer not to format that partition!

After the installation you can set up chainloading the grubs, so you can select the grub from one installation as an entry on the other and vice versa (how? see What is the recommended way to chainload separate Ubuntu /boot partition).

By having separate /boot partitions I don't have to worry about one Linux messing grub for the other Linux during the automated kernel upgrade.

4
  • I'm doing this as well, with no issues. This also works with Linux Mint and Zorin OS (which are derived from Ubuntu), and even Debian and openSUSE (which does not install in a subvolume by default, currently). Another cool thing is, you can test a dist-upgrade while keeping a bootable snapshot of the old version.
    – ignis
    Jan 6, 2014 at 8:45
  • 1
    I prefer to use this layout for subvolumes: /mint/@ and /mint/@home or /trusty/@ and /trusty/@home, etc. This puts each distro in its own directory and keeps the default names for the subvolumes. May 1, 2019 at 14:30
  • 1
    If you don't have a separate /boot partition then the reboot in Step 7 will fail and you will be left at the grub rescue prompt. At this prompt, type set prefix=($root)/@mint/boot/grub (replace @mint with the path to your distro's subvolume) and then type insmod normal and finally normal to load the Grub menu and boot your distro. Once booted, type sudo update-grub && sudo grub-install to make the change permanent. May 1, 2019 at 15:47
  • 1
    This guide lacks one VERY important step, explaining how to delete the original subvolumes. It may not be immediately apparent to everyone that once you create a snapshot, you can safely delete the original. Also, I spent quite a bit of time deleting the snapshots that were based on the original @. You need to know subvolume delte isn't recursive and you need to delete the child snapshots first, before you can delete the @ subvolume.
    – velis
    Oct 16, 2020 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .