2

Originally I had a 50GB disk where the root / was mounted to a 6 GB partition on it. The partition was running out of room so I created a second partition with the rest of the free space (44 GB). Here's what it looked like originally

NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  50G  0 disk
└─xvda1 202:1    0   6G  0 part /

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      6.0G  6.0G   20K 100% /
devtmpfs         30G     0   30G   0% /dev
tmpfs            30G     0   30G   0% /dev/shm
tmpfs            30G  121M   30G   1% /run
tmpfs            30G     0   30G   0% /sys/fs/cgroup

Within the root file system I had a directory /opt which used 3.4 GB of space and is where I am doing much of my work so /opt will continue to grow. After backing up all of my files, I mounted the second partition onto /opt

mount /dev/xvda2 /opt

After doing this, the new /opt is 0 GB and the partition 1 is still 6 GB with no way for me to access the 3.4 GB that was originally in /opt.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      6.0G  6.0G   20K  100% /
devtmpfs         30G  6.1G   24G  21% /dev 
tmpfs            30G     0   30G   0% /dev/shm
tmpfs            30G  129M   30G   1% /run
tmpfs            30G     0   30G   0% /sys/fs/cgroup
/dev/xvda2       44G     0   44G   0% /opt

I have recovered the files from my backup but how can I delete the 3.4 GB that is not being used in partition 1? For future reference, what is the correct way to mount a new partition to a directory that is currently inside of another partition?

1
  • Just mount the new fs somewhere else than /opt temporarily so you can clean up (or just unmount it while you clean up). – Mat Nov 7 '14 at 16:04
0

When you mount another filesystem on /opt, the previous content of /opt is inaccessible through that path, but it doesn't go away. On Linux, you can make it available by mounting it elsewhere, thanks to mount --bind.

mkdir /whole-root
mount --bind / /whole-root
mv /whole-root/opt/* /opt/
umount /whole-root

There is of course an alternate method: mount the new partition temporarily to an empty directory (/mnt is traditionally used for this purpose: a short-lived mount point), move the files, then unmount the new partition and mount it at its final location.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.