5

I want to install an Ubuntu Server with a btrfs filesystem (in a RAID1 way).

The problem is that I can't see the option in the installer to make more subvolumes. The installer creates two by default: @ and @home, and I want to separate also @var, @tmp, ...

Is there any option to do this? Maybe with the shell... but I think the installer doesn't understand the subvolumes feature of btrfs, so you can't mount each partition in each subvolume...

2 Answers 2

3

This should be easy enough to change after you have finished your initial install.

  • One neat way is to take two snapshots of @, calling them @var and @tmp.
  • Then delete everything in @var except for @var/var, them move the contents of @var/var/* up to @var/* and delete @var/var. Same for @tmp/tmp/.
  • Then modify /etc/fstab with the new subvolume mount points for /var and /tmp.
  • Reboot.
  • Finally (I'm not so sure about this last bit) you should be able to delete the original contents of @/var and @/tmp by mounting the subvolume @ under /mnt (so the same subvolume is mounted twice, once as / and once as /mnt) and deleting /mnt/var and /mnt/tmp.
1
3

You're right, the installer is not aware of BTRFS subvolumes, and this is still the case for 18.04.

Using a separate subvolume for /var/log/ allows to restore a snapshot of / without loosing the logs.

  • Do the server setup as usual, at the Finish installation step, select Go Back and Execute a shell.
  • List all your target file systems:

    mount | grep target
    
    /dev/md-0 on /target type btrfs (rw,noatime,space_cache,subvolid=257,subvol=/@)
    /dev/md-0 on /target/home type btrfs (rw,noatime,space_cache,subvolid=258,subvol=/@home)
    proc on /target/proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /target/dev type devtmpfs (rw,nosuid,relatime,size=475608k,nr_inodes=118902,mode=755)
    
  • Take a note of the btrfs device, in this example /dev/dm-0.

  • Now un-mount all of your mounted file systems.

    umount /target/dev
    umount /target/proc
    umount /target/boot/efi
    umount /target/home
    umount /target/
    
  • Mount your flat btrfs filesystem :

    cd /tmp
    mkdir work
    mount /dev/dm-0 work
    cd work
    
  • Verify the mount is correct (should show @ and @home):

    ls 
    
    @ @home
    
  • Create your additional subvolumes (@tmp, @var, @var-log)

    btrfs subvolume create @tmp
    btrfs subvolume create @var
    btrfs subvolume create @var-log
    
  • Move the data

    mv @/var/log/* @var-log/
    mv @/var/* @var/
    
    # Remove data from tmp
    rm @/tmp/* @/tmp/.*
    
    # For 18.04, remove the swapfile since it won't work on btrfs
    rm @/swapfile
    
  • Add the new subvolumes to fstab, the device part may be different than the previous mount command, copy the device part from the already existing mount points.

    ...
    /dev/mapper/root-root /               btrfs   noatime,subvol=@ 0       1
    /dev/mapper/root-root /home           btrfs   noatime,subvol=@home 0       2
    /dev/mapper/root-root /var            btrfs   noatime,subvol=@var 0       2
    /dev/mapper/root-root /var/log        btrfs   noatime,subvol=@var-log 0       2
    
  • Unmount

    cd /tmp
    umount work
    sync
    
  • exit, then Finish the installation

  • Install and configure snapper, a great tool for automatizing snapshots.

You must log in to answer this question.

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