I was in the situation dealing with a Linux box with two hard disks:
/dev/sda
: fast hard drive (SSD), small size (~200 GB)/dev/sdb
: very big hard drive (HDD), large size (~4 TB)
The operating system was installed on /dev/sda
, so I had /dev/sdb
empty. I knew I could create a mount point (e.g. /storage) and mount it to /dev/sdb
, but after reading Intelligent partitioning and the recommended Debian partitioning scheme I thought about moving:
/var
/home
/tmp
to the big hard drive /dev/sdb
The process described here is completely different from just putting a mount point to a partition in /etc/fstab: in our solution, we will use one disk (or one partition) to store multiple root subdirectories (/var, /home, /tmp). With the fstab “usual” method, you put one subdirectory in one disk or partition or volume.
The solution to this problem is a bind mount: the three original directories will exist in the root disk (/dev/sda
) but they will be empty. Those directories will live into the second disk (/dev/sdb
) and, upon mount
ing, a bind will be created between the root filesystem and the directories in the second disk.
The process is easy:
- Backup your data
- Boot from a live distribution (e.g. KNOPPIX)
- Mount your hard drives:
mkdir /mnt/sd{a,b}1
mount /dev/sda1 /mnt/sda1
mount /dev/sdb1 /mnt/sdb1 - Copy the directories from
sda
tosdb
:cp -ax /mnt/sda1/{home,tmp,var} /mnt/sdb1/
- Rename the old directories you just copied and create the new mount points:
mv /mnt/sda1/home /mnt/sda1/home.old
mv /mnt/sda1/tmp /mnt/sda1/tmp.old
mv /mnt/sda1/var /mnt/sda1/var.old
mkdir /mnt/sda1/{home,tmp,var} - Update your fstab with the new locations:Mount the second hard drive:
/dev/sdb1 /mnt/sdb1 ext4 defaults 0 2
Then create the bind mounts for the 3 subdirectories you moved:
/mnt/sdb1/home /home none defaults,bind 0 0
/mnt/sdb1/tmp /tmp none defaults,bind 0 0
/mnt/sdb1/var /var none defaults,bind 0 0 umount
your hard drives and reboot- Check that everything under
/home
,/var
and/tmp
is working as expected. You may also want to clean up and delete/home.old
,/var.old
, and/tmp.old
.
This process can be repeated for any subdirectory you want to move (except, obviously, /boot
).
Closing notes: if you are brave enough:
- you are not required to boot from a live distribution, just boot into single-user mode (adapt the paths of the following guide though!)
- you can also skip booting into single user mode if you are using LVM: just create a new logical volume and copying subdirectories into it
Great resource that help me a lot with my VPS. Thanks a lot