Permanently mount multiple directories from different disks under /

I have SSD and HDD. Some directories like /var, /srv and /tmp should be on HDD, while /boot, /usr and /lib on SSD. But do I have to create separate partition for every single directory? I want to have 2 or so partitions. One for each disk and distribute directories as needed. Is it possible and how?

I've heard about symlinks, mount --bind, mhddfs but:

  • symlinks are treated differently by tools like cp, so I'm not sure if it's safe to have main system directories symlinked
  • I have no idea how can I use mount --bind or mhddfs in fstab
1

3 Answers

If you don't want to have lots of partitions and you also want the flexibility of moving things around, I recommend using LVM.

Create the /boot partition on the SSD and another 2 large partitions: one on the HDD, the another one on the SSD. These 2 partitions will be physical volumes (PVs) for the LVM. Add them to a volume group (VG), then create a logical volume (LV) for each directory on the desired PV. If you discover later that /var should be on the SSD, not on the HDD, you can use pvmove to move its corresponding LV from the HDD to the SSD.

Example:

pvcreate /dev/disk/by-id/hdd-part1
pvcreate /dev/disk/by-id/sdd-part2 # part1 is /boot
vgcreate my_vg /dev/disk/by-id/hdd-part1 /dev/disk/by-id/sdd-part2
lvcreate -n root -L 6G my_vg /dev/disk/by-id/sdd-part2
lvcreate -n var -L 2G my_vg /dev/disk/by-id/hdd-part1
lvcreate -n srv -L 10G my_vg /dev/disk/by-id/hdd-part1
pvmove -n var /dev/disk/by-id/hdd-part2 /dev/disk/by-id/sdd-part2

I want to emphasize that pvmove can also move only fragments of a PV called physical extents (PEs). The default size of a PE is 4 MiB and it can be set when the VG is created.

I never used this but I guess you can mount / directory at ssd device. Then create a folder named /hdd After, create your desired folders like /hdd/var /hdd/srv /hdd/tmp.

And use the bind mount to update those entries

mount --bind /hdd/var /var
mount --bind /hdd/tmp /tmp

For the just create the /boot, /usr, /lib folders. No need for remount.

Bind mounts should accomplish what you are trying to do. You can use bind mounts with ease in fstab: a bind mount fstab entry looks like

/path/to/original /mount/point none bind 0 0

Just note that you need something mounted to / to begin with, so I would recommend mounting your SSD to /, and then bind mounting various directories from your HDD as you see fit. So an fstab like (assuming ext4 partitions, change as necessary)

### /etc/fstab ###
# Mount SSD to /
/dev/disk/by-uuid/your-ssd-partition-uuid / ext4 0 1
# Mount HDD somewhere (in this case /mnt/hdd)
/dev/disk/by-uuid/your-hdd-partition-uuid /mnt/hdd ext4 0 2
# Bind mounts
/mnt/hdd/var /var none bind 0 0
/mnt/hdd/srv /srv none bind 0 0
/mnt/hdd/tmp /tmp none bind 0 0

You can also have a dedicated "root" directory for /, say on your ssd, this would make fstab look like

### /etc/fstab ###
# Mount SSD somewhere
/dev/disk/by-uuid/your-ssd-partition-uuid /mnt/ssd ext4 0 1
# Mount HDD somewhere (in this case /mnt/hdd)
/dev/disk/by-uuid/your-hdd-partition-uuid /mnt/hdd ext4 0 2
# Mount /
/mnt/ssd/root / none bind 0 0
# Other Bind mounts
/mnt/hdd/var /var none bind 0 0
/mnt/hdd/srv /srv none bind 0 0
/mnt/hdd/tmp /tmp none bind 0 0
/mnt/ssd/lib /lib none bind 0 0
/mnt/ssd/usr /usr none bind 0 0
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like