I moved my home directory to a subdirectory of a second (mounted) drive using usermod -d ... -m
. Now, most programs work fine, but a few (Dropbox, etc.) do not. I believe this is because there is no /home/myuser directory any more, so programs that are hard-coded to look there fail.
Can I just create a hard link using ln -d
? It seems like hard links are problematic, and I'm not even sure if I can create them across disks anyhow. But I'd like to get this sorted out soon.
Hard links in general are not particularly problematic. But hard links to directories are, which is why you have to use the
-d
flag to attempt to make one, and why you will probably not succeed anyway; the kernel is probably configured (or hard-coded, I'm not sure) to prohibit them.Furthermore, as you've suspected you cannot hard link anything across volumes, so you won't be able to hard link
/home/myuser
to a directory on a different partition.There are two types of links supported by the
ln
command--hard links, and soft links (also called symbolic links or symlinks).A hard link to a file is the file. When you make a hard link, you're making it so that another filename identifies the file. Files in a Unix-style filesystem (like ext4, which Ubuntu uses by default) are identified uniquely by their inode number. When a file has multiple names, that is, multiple hard links (or, we can say, just multiple links), it continues to exist even if one or more of them are deleted, so long as at least one remains. (Then it continues to exist on disk until it is no longer open by any process.) The name of the low-level system function that does the work of
rm
is calledunlink
for this reason.A soft link is not the file. It is instead a special kind of filesystem entry that points to a file by the target file's location and name. If you delete a file pointed to by a soft link, the soft link does not cause the file to continue to exist. If you delete or move/rename a file pointed to by a soft link, the soft link stops working to access the file, and is said to be broken.
Hard linking files across volumes does not work because a hard link is the file, and must be on the volume where the file's data is physically stored.
Hard linking directories (that is, having more than one name corresponding to the same directory inode) is generally a bad idea, and is usually prohibited, because it makes it possible to break basic (and reasonable) assumptions about how directories behave. For example, suppose I am in a directory called
foo
and Icd
to a directory calledbar
. If directory hard links are not allowed, then I know I can get back tofoo
withcd ..
. But if directory hard links are allowed, thenbar
could actually be a hard link to a directory somewhere else. Furthermore, and much more seriously, a hard link is the file, and a hard link to a directory is the directory, so there can then be ambiguity about what directory really is the parent ofbar
.On the other hand, soft links to directories are perfectly permitted. A directory
foo
can contain a soft link calledbar
which links to a directory somewhere else, but this doesn't cause problems because it is always clear what to do. It is always clear because there is an answer to the question what directory am I in really? So when you are treating the present working directory as the name you used to get there, it's the name of the symbolic link. And when you need to know what directory you're really in (for example, to compare two different paths to see if they're the same or one resides in the other), that works too.So, you can make a soft link, or symbolic link, from
/home/myuser
to the new home directory. To make a soft link, useln -s target source
. You do not need to (and should not) specify the-d
flag to make a directory soft link.That might help ameliorate your problem. You could try it. But it would be even better to fix the problem itself. I recommend that you post a new question asking for how to solve the problem of some of your programs not working properly since you migrated your home directory to another partition (assuming that's what you did). Make sure to include specific information about all the programs that are having problems, including the full and exact text of any error messages, and also a description of exactly what changes you made to your Ubuntu configuration that triggered these problems and the complete contents of
/etc/fstab
and the output ofecho $USER $HOME
. (You should also link to this question, so people don't answer telling you just work around the problem by making a symbolic link.)Don't do a hard link. Do a symbolic link.
ln -s /path/to/home /path/to/link
. Hard links can cause problems, especially when it's to a directory.