6

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?

Zanna
  • 72,312
Steve D
  • 267

3 Answers3

7

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.

terdon
  • 104,119
4

I second moving /home, but it's possible to do what you want.

If I understand correctly, you have two drives, one with ubuntu (and possibly some windows stuff) and one with the windows user files. What you would need to do is shrink the windows partition (while I have done this successfully many times, resizing partitions may lead to data loss, so back up your data), and that will free up room on that drive. You can use a program like GParted to resize partitions. Once done, you can take the leftover space and make a new partition (also done with GParted). Then you'll need to copy the contents of /usr/local and /opt over to the new partition (I usually do this part by inserting a live cd and mounting everything and copying). Finally, you'll need to edit /etc/fstab and tell it where to mount /usr/local and /opt.

The link given above on the steps to move /home are the same, so you can follow that guide for moving /usr/local and /opt. What you will need to do is resize the windows partition first.

Hammar
  • 41
  • 2
0

RISKY PROCESS, DATA CAN BE LOST! Make backups

  1. I used this approach on my raspberrypi (just now) with different linux os (raspbian).
  2. setup the existing partition in my case with the same permissions on the folder. It was the only partition that was already mounted to /mnt/existingpartitionfolder/.
  3. Copied with rsync all contents of opt to existingpartitionifolder $sudo rsync -avX /opt/ /mnt/existingpartitionfolder/. Existing data in the existingpartitionfolder would soon becaome part of opt.
  4. I prayed that my symlinks moved relative to the copy process and did not link to the old opt location. I believe -l does this which is included in the -a switch, and they looked ok???
  5. Adjust /etc/fstab entry from /mnt/existingpartitionfolder to /opt
  6. I had an nfs running on that /mnt/ folder so I also adjusted /etc/exports entry to point at /opt which would be the same logical location after reboot.
  7. rename /opt $ sudo mv /opt /optold (my backup)
  8. $sudo reboot now
  9. Everything came back perfect and intact, now just need to delete /optold (deleting the backup, or move it to new /opt) if the space is required, and test.

To do this on other top level folders, may not work if data is moving. The same approach can be taken by putting the HDDs into another machine or running a LIVE disk. Just be carefull with your UUIDs in fstab, and permissions of folders and files. If boot sequence fails it is likely your UUIDs in fstab(big assumption). If you need to copy whole disks use the dd command.

TheArchitecta
  • 321
  • 4
  • 8