More specifically, I want to have the user folder for my home account another disk that has more space, but keep my other smaller accounts on my ssd. I was able to copy my user folder to another disk, but now I need to link it to the home folder on my ssd, I want it accessible from a normal boot, and please don't tell me that what I did was not the best thing, I just want an answer. How do I get it to create a link that goes from /home/username to /extra-home/username and is recognised by the system when loading the user folders?
4 Answers
Remember that your permissions will need to be the same. In addition to symlink, on more recent distros and filesystems, as root you can also use bind-mount:
mkdir /home/username
mount --bind --verbose /extra-home/username /home/username
This is useful for allowing access "through" the /home
directory to subdirs via daemons that are otherwise configured to avoid pathing through symlinks (apache, ftpd, etc.).
You have to remember (or init script) to bind upon restarts, of course.
-
I wasn't aware that symlinks could create such issues. How do such daemons treat
/var/run/
?– PaulCommented May 16, 2014 at 16:27 -
1The servers are designed to restrict access to the local filesystem, to avoid compromising the system. You can think of this as "things allowed to remote users". They need not restrict themselves from accessing /var/run (typically at startup/shutdown) as "things allowed to this process". See Apache's FollowSymLinks directive for an example of how to allow the served filesystem to traverse symlinks, if desired. Commented Jun 3, 2014 at 17:51
-
can we also expand /bin and /lib in the same way (can be useful in small filesystem) ?– ranshCommented Jan 29, 2018 at 12:25
-
Does your system need
/bin
and/lib
at initialization (i.e. before you can run themount
command)? If so, then you cannot employ this strategy. Commented Jan 31, 2018 at 21:43 -
9Adding info here, as I had to search for it, once that is done to add init in /etc/fstab here is the form. When using the method Joe described
mount --bind --verbose /extra-home/username /home/username
, the line in/etc/fstab
would be/extra-home/username /home/username none defaults,bind 0 0
– WilkenCommented May 20, 2018 at 17:20
According to this question on Super User this is possible.
You can create a symbolic link using:
ln -s /extra-home/username /home/username
If it doesn't work for some reason you can just delete the symbolic link, move the directory back and reboot your computer.
-
If it's a simple folder you have to start with /media/{hardrive_name}/{your folder} I have just tried this on a debian server and it works. Commented Jan 13, 2017 at 1:24
I would try this:
While logged in as a different user, in a root shell (e.g. sudo -i
), copy over the contents of /home/username
to /extra-home/username
and make sure the new location is owned by username
:
# cp -p /home/username /extra-home/
# chown username:username /extra-home/username
Move the original /home/username/
directory to a safe place:
# mv /home/username /root/
Create the symlink:
# ln -s /extra-home/username /home/username
Verify it's working as expected by opening another terminal window and running su
:
$ sudo su username
If everything looks good, at least from the terminal (contents of /home/username/
appear as expected), then log out and log back in (I'm assuming you're on Ubuntu desktop) and it should be working normally. However, if it isn't, just delete the symlink and move the archived home folder back to its original location.
-
1Old answer, but +1 for clear instructions with a fallback. Thank you.– SimonCommented Jan 24, 2021 at 4:05
My experience on this is: it never doesn't work well with symlinks. Permissions, user services and so on sometime doesn't follow or work with symlinks: so you may get sudo doesn't working, user configuration app doesn't working correctly and so on...
The best solution, in my humble opinion, is to put all the homes on the same partition and mount it on /home. If you have more than a spare disk you can:
- to buy a RAID card
- put all the disks you want to use for users home on the RAID card.
- Configure RAID as JBOD (disks will sum the space). During PC boot, RAID cards start a BIOS to configure drives before the OS starts. There are other RAID configurations, but it depends on your needs.
- Now you have like a new single huge disk just for /home
sudo copy -pr
the /home folder on the new drive- edit /ect/fstab to mount the drive on /home
This way you can grow the /home size incredibly any time you need, just adding another drive to the RAID.