2

I'd like to mount a folder on another partition (/dev/sda) named /usr to my local /usr, but I failed.

Here's my attempt:

  1. Use a live CD and select try ubuntu.

  2. Mount the partition using sudo mount -s /dev/sda /d

  3. sudo mkdir /d/usr, and copy the content to it using rsync -avH usr /d/usr

  4. remove the original /usr folder rm -rf usr

  5. add this line to etc/fstab:

UUID=74e1363e-5493-4522-977f-c267751e9d1a /d ext4 defaults 0 2

in which the 74e.... is the uuid of the partition

  1. add a symlink using sudo ln -s /d/usr .

  2. restart the computer.

this doesn't work for me and the computer can't start normally.

how can I solve this and mount a folder to /usr correctly?

ygy
  • 151
  • 6

2 Answers2

1

Copy everything in your /d/usr folder at the root of your /d partition if it's possible.

Then, instead of using a symlink, you can directly specify the /usr folder as the target mount folder in your fstab:

UUID=74e1363e-5493-4522-977f-c267751e9d1a /usr              ext4    defaults        0       2

You can refer to why can't /usr be a symbolic link on how to mount a folder in an already mounted partition.

Musinux
  • 136
  • 3
  • so /usr can't be a symbolic link right? then that's why I failed. I may need to use that mount -o option right? – ygy May 24 '20 at 10:02
  • I think so, never tried it though. Check how to use the bind parameter directly in the fstab file here: https://serverfault.com/questions/613179/how-do-i-do-mount-bind-in-etc-fstab – Musinux May 24 '20 at 11:07
  • 1
    I done a little bit of testing and I do think this can work, I'm restarting my computer. Thanks! – ygy May 24 '20 at 11:11
1

Surprisingly, you can mount bind folders in fstab using

/olddir /newdir none bind

this is a reference to the manpages.

thanks for musinux for telling me about binding.

ygy
  • 151
  • 6