How to move the /root directory on Debian

6,543

Solution 1

You should avoid symlinks, it can make nasty bugs to appear... one day. And very hard to debug.

Use mount --bind:

# as root
cp -a /root /home/
echo "" >> /etc/fstab
echo "/home/root /root none defaults,bind 0 0" >> /etc/fstab

# do it now
cd / ; mv /root /root.old; mkdir /root; mount -a

it will be made at every reboots which you should do now if you want to catch errors soon

Solution 2

Never tried it, but you shouldn't have a problem with:
cd / to make sure you're not in the directory to be moved
mv /root /home/root
ln -s /home/root /root symlink it back to the original location.

Share:
6,543

Related videos on Youtube

nicholas.alipaz
Author by

nicholas.alipaz

Updated on September 17, 2022

Comments

  • nicholas.alipaz
    nicholas.alipaz over 1 year

    I would like to move my root user's directory to a larger partition. Sometimes "he" runs out of space when performing tasks.

    Here are my partitions:

    host3:~# df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/sda1               334460    320649         0 100% /
    tmpfs                   514128         0    514128   0% /lib/init/rw
    udev                     10240       720      9520   8% /dev
    tmpfs                   514128         0    514128   0% /dev/shm
    /dev/sda9            228978900   1534900 215812540   1% /home
    /dev/sda8               381138     10305    351155   3% /tmp
    /dev/sda5              4806904    956852   3605868  21% /usr
    /dev/sda6              2885780   2281584    457608  84% /var
    

    The root user's home directory is /root. I would like to relocate this, and any other user's home directories to a new location, perhaps on sda9. How do I go about this?

    • Admin
      Admin over 13 years
      Do you need to have /root on a separate partition, or would it be enough to simply copy the contents somewhere else and set up a symbolic link? (Disclaimer: I've never tried this, but it should work.)
  • nicholas.alipaz
    nicholas.alipaz over 13 years
    booting from a live cd is unfortunately not an option for a remote server, which this is the case here.
  • nicholas.alipaz
    nicholas.alipaz over 13 years
    I have tried this and all seems to be fine so far. Thanks shellholic.
  • shellholic
    shellholic over 13 years
    You're welcome. But remember moving /root is a bad practice. Perhaps you could change a bit and make /home/bigrootfiles and mount/link it to some directory inside /root. If your "big files" are for some service. The best practice on Debian is to put them in /var/lib/somename
  • nicholas.alipaz
    nicholas.alipaz over 13 years
    I see. Ultimately root login should not be used IMO. I guess I still might forgo moving /root entirely since it is not really very good to do. I just need to setup some new sudoer users with directories on the right partition and setup keyed authentication for better security. That would be the best solution I think.
  • shellholic
    shellholic over 13 years
    Perhaps make a new question describing the purpose of your case and you could come with great answers.
  • user855443
    user855443 almost 4 years
    I think that worked in the past - if you do update-grub and grub-install at the end. However, with debian 10 grub sends me back to have my old partition as the root.