Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
if ur new driver have another file system don't think about hard links. and if u open the man of ln u can found these lines : -d, -F, --directory allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser) –  eyadof May 19 '12 at 13:19
1  
@eyadof The restriction on making hard links (of any kind, file or directory) to "other filesystems" means that you cannot link across devices at all, not that you can only do it if their filesystems are formatted the same way (e.g., both ext4). –  Eliah Kagan May 19 '12 at 13:30
add comment

2 Answers

up vote 4 down vote accepted

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 called unlink 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 I cd to a directory called bar. If directory hard links are not allowed, then I know I can get back to foo with cd ... But if directory hard links are allowed, then bar 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 of bar.

On the other hand, soft links to directories are perfectly permitted. A directory foo can contain a soft link called bar 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, use ln -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 of echo $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.)

share|improve this answer
    
That answers my question, thanks. I briefly considered symlinks, but if I delete a file in e.g. Dropbox I want it to truly be deleted and I don't think I get that with a symlink. I had not previously thought about the distinction between linking files and linking directories, so thanks for that also. –  Ari B. Friedman May 19 '12 at 14:01
    
@gsk3 Why would symlinks be a problem for dropbox? (I'm not saying they won't; I don't use dropbox. But...) The symlink would just be from the old home directory location to the new home directory. The files inside would not all be symlinks. If foo is a symlink to a directory bar which contains a file (or subdirectory) baz, then foo/baz is baz, not a symlink to baz. –  Eliah Kagan May 19 '12 at 14:09
1  
Good point. Tried it, and it appears to be working. +3 internets to you. –  Ari B. Friedman May 19 '12 at 14:54
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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