[SOLVED] safely mv directory to another partition and replace with symlink
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
safely mv directory to another partition and replace with symlink
Hi, all.
So I'm running a little Slackware LAMP server.
I have a couple partitions:
Code:
Filesystem Size Mounted on
/dev/root 49G /
/dev/md1 147G /www #website and stuff
I'd like to store my databases on /www, as it's raided and not likely to be accidentally formatted if I reinstall the OS.
Currently, they're stored in /var/lib/mysql.
What I'd like to do is something like
mv /var/lib/mysql /www/mysql
and then
ln -s /www/mysql /var/lib/mysql
(I probably messed up that syntax.)
Before I do something really stupid, though, I want to filter this idea with you guys.
So, uh, do I have the right mv and ln syntax? Will mysql explode when it encounters a symlink?
Or, even better, is there an option in my.cnf or a similar file that lets me change the directory properly? I didn't see anything, but mysql has a huge man page...
(Currently, there's no data I cherish in the databases, but I figure I should probably learn to do this right before I have to move actually valuable data.)
Looks all good to me; whether or not MySQL will throw a hissy-fit (I don't think it will)
I don't know; same w/ simply changing a config-setting. But if all else fails you can
always revert back ;}
You might want to consider the use of a hard link rather than a soft link. If you're using a Linux file system (like ext, btrfs, etc.) that uses inodes, a hard link to a file increase the "in use" number of the nodes in the file by one. If the "in use" number is greater than zero, the node is not deleted when it's change by writing to the file. Instead, a new free (i.e., node with a zero "in use" number) is used. The "in use" number will not decrease to zero until the the hard link is deleted.
Thus a hard link to a file creates, essentially, a "snapshot" of the file. This minimizes the amount of disk space used by the backup, since only the changed nodes need actual disk space. That's unlike a copy that uses a new node for every node in the base file.
This, by the way, is how it's possible to write to a file (like, e.g., a system file) that's being used by a running Linus system, since the kernel, in essence, hard links opened files, and uses the "virtual hard link" when it references the file, releasing it when the file is closed.
The OP appears to want to move to a new partition; hard links can only exist in one partition as each partition has its own inode list (ie same ids as any other partition).
IOW, you can symlink across partitions, but not hard link.
Oops! I meant to post that to a different thread where that OP was asking about writing into a file, but was afraid that he might get it "wrong." (And I found the wrong thread when I looked for it after I woke up the next day with the realization that the hard link might be a good solution for that OP.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.