Partitioning – Move /opt to a Different Drive

dual-boothard drivemountpartitioning

I dual boot Ubuntu 16.04 and Windows 8.1. All of Ubuntu lives on an SSD, and the core Windows stuff lives there too, in a separate partition. The main User folders for Windows (Documents, Downloads, etc.) live on a separate hard drive.

I'm running out of space in Ubuntu. I'd like to move /opt and /usr/local to the hard drive. All the Q&A I've found about this, however, starts with the assumption that these folders are already mounted on a different partition, or that I can format the destination drive. Neither of these is true for me.

I don't remember exactly what I did when I set this computer up, but I do know the hard drive is accessible from Ubuntu (and is at /dev/sdb1, mounted at /media/steve/storage). Is it possible to do what I'm asking?

Best Answer

You can simply link to it:

  1. Move the /opt directory:

    sudo mv /opt /mnt/otherDisk/
    
  2. Create a symlink to the new location:

    sudo ln -s /mnt/OtherDisk/opt /
    

You will now have:

$ ls -ld /opt
lrwxrwxrwx 1 root root 5 Apr  6 14:23 /opt -> /mnt/OtherDisk/opt

As Rinzwind correctly pointed out in the comments, this can break your system if you move a directory containing files needed during boot. For example, you certainly don't want to do this for /bin. /opt should be fine though.

Related Question