Mount a partition to two mount points

I have a partition called sda4.

And I want to store the mysql data and xml files on that partition because the partition which mysql and domain are installed has little space.

So I'm planning to have two subfolders under the sda4, one for mysql and one for xml. Then I want to mount the subfolders respectively like this:

mount -t auto /dev/sda4/mysql /var/lib/mysql

mount -t auto /dev/sda4/xml /home/user/domain/public_html/xml

Is my plan doable? Can mount a partition to two mount points?


Solution 1:

Short answer: no, you can't.

Longer answer: mount /dev/sda4 on one mount point, and do a soft link from the other mount point. Or mount it on a third, application-neutral point, and soft link from both the application points.

Edit: re a tutorial, try:

mount /dev/sda4 /mnt
ln -s /mnt/mysql /var/lib/mysql
ln -s /mnt/xml /home/user/domain/public_html/xml

NB: it is necessary that neither /var/lib/mysql or /home/user/domain/public_html/xml exist, or the ln -s will do something predictable but unexpected.

Edit 2: it's OK that that stuff exists, you'll need to move it to one side. Having mounted /dev/sda4 on /mnt (see above), try

mv /var/lib/mysql /var/lib/mysql.mark
mv /home/user/domain/public_html/xml /home/user/domain/public_html/xml.mark

(do the soft links, as above)

mv /var/lib/mysql.mark/* /var/lib/mysql
mv /home/user/domain/public_html/xml.mark/* /home/user/domain/public_html/xml

which should leave you with two empty .mark directories that can now be removed. Do not do this while the applications are running!