Tuesday, November 24, 2015

partitioning - Mount partition to several directories in Linux



I have a PC with an SSD and an HDD. I'm running Linux. I wish to put all the static (very rarely changing) files on the SSD and the rest on the HDD. To achieve that I'd like to have /boot, /usr, /lib, /bin, /etc, /opt on the SSD and the rest - /var, /tmp, /home on the HDD. However, I don't want to create a separate partition for each of them, I want each group to be on its own partition. I suppose that I could mount the SSD to /, the HDD to /mnt/hdd and symlink /home, etc. to point to /mnt/hdd/home, etc.




Are there problems I can expect with such a setup? Such as a program attempting to read from/write to /var early in the boot process before the HDD is mounted? Will logging work as normal if /var (and /var/log) aren't on the root partition?



What would be the best way to solve this?


Answer



So, after more digging around, I found this is the correct incantation for a systemd-based setup:



# 
# /etc/fstab: static file system information
#

#

devpts /dev/pts devpts defaults 0 0
shm /dev/shm tmpfs nodev,nosuid 0 0

UUID=246b032f-0633-459a-867c-6013304c5b8d swap swap defaults 0 0
UUID=64ed9a87-7860-4538-bef6-05eff29ed5c1 / ext4 defaults,noatime,nodiratime,iversion,fail 0 1
UUID=e3b656bf-69c8-4b2a-bad8-6c051559b43f /mnt/hdd ext4 defaults,noatime,nodiratime,iversion,x-initrd.mount,fail 0 1
/mnt/hdd/home /home none rw,rbind,x-systemd.automount,fail 0 0
/mnt/hdd/root /root none rw,rbind,x-systemd.automount,fail 0 0
/mnt/hdd/tmp /tmp none rw,rbind,x-initrd.mount,fail 0 0

/mnt/hdd/var /var none rw,rbind,x-initrd.mount,fail 0 0
UUID=B084-4D66 /boot/efi vfat defaults,noauto,noatime,nodiratime,iversion 0 2


For whatever reason, tmp and var have to be x-initrd.mount, while home and root have to be x-systemd.automount. Hope this helps someone else.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...