1

I need to write a script that can mount /home in an USB drive at the boot and keep all the files in the USB drive after ejecting it.

At every boot, if there is an USB drive plugged in, the script has to check if there is a directory called /home in the USB drive and mount it.

In another words, I need to use my USB drive as /home and keep all the files there.

How can I mount /home in an USB drive and keep all the files there, even after umount /home ?

  • 1
    what did you tried so far? which distro are you using? – RSFalcon7 Aug 11 '15 at 14:34
  • I am using Ubuntu 14.10. I can mount /home in the usb drive, but the files do not stay there after umount it. I also tried to mount and use rsync to copy the files mounted to the usb drive but that is a kind of slow. – user3721266 Aug 11 '15 at 14:41
  • If you are unmounting the usb drive, then as far as the OS is concerned, the files do not exist. You can mount the drive somewhere else and copy the files to /home. Changes to /home will not show up on the usb drive. – Robert Jacobs Aug 11 '15 at 14:44
  • Why not just leave the usb drive mounted? – Robert Jacobs Aug 11 '15 at 14:45
  • 1
    If the computers are networked, then I would suggest sharing the directory and mounting them remotely. Otherwise you are stuck making copies and having issues with synchronization. – Robert Jacobs Aug 11 '15 at 14:53
0

After trying a lot of things, I found the solution:

If I want to mount /home/user on a USB drive and keep all the files there after ejecting it, I have to first mount the USB drive like:

mount -o uid=user /dev/sdb1 /hometemp 

Then, I have to mount the directory /hometemp on home/user like this:

mount --bind /hometemp /home/user

It works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.