I found this tutorial on how to move to home to a separate partition now that I feel I should also move /usr, /tmp and /var
to the same partition, can I just do that in a similar manner. Add another two lines in fstab for tmp and usr with the UUID same as /home
as described in the article and it'll be done? How to go about it?
1 Answer
While you cannot directly mount multiple filesystems from the same partition because each partition can only contain one filesystem, you can use LVM.
LVM-based solution
For example, with an unused partition, say /dev/sda3, you can do something like this:
pvcreate /dev/sda3
vgcreate vg0 /dev/sda3
lvcreate -ay -L5G vg0 lv-home
lvcreate -ay -L5G vg0 lv-usr
lvcreate -ay -L5G vg0 lv-tmp
lvcreate -ay -L5G vg0 lv-var
mkfs.ext4 -L HOME /dev/vg0/lv-home
mkfs.ext4 -L USR /dev/vg0/lv-usr
mkfs.ext4 -L TMP /dev/vg0/lv-tmp
mkfs.ext4 -L VAR /dev/vg0/lv-var
The commands above:
- Turns the partition into an LVM physical volume
- Creates an LVM volume group with the physical volume.
- Creates a logical volume for each filesystem.
- Puts a filesystem on each logical volume (with labels)
Next, setup fstab to mount each of the filesystems. Something like this:
LABEL=HOME /home ext4 defaults 0 2
LABEL=USR /usr ext4 defaults 0 2
...
PS
I don't recommend fragmenting your installation this way because you'll eventually end up with more not enough space errors, but nevertheless, that's one way to do it. Frankly, I'm a single-filesystem sort of guy, so if I were using Ubuntu I'd simply backup /home
and restore it after an upgrade; no monkey business with partitions or logical volumes.
Warning
With both the original article and my instructions above, do your research BEFORE you run the commands. Understand what the commands do and their consequences. man
is your friend.
/usr
etc.