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, 2015 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. Aug 11, 2015 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. Aug 11, 2015 at 14:44
  • Why not just leave the usb drive mounted? Aug 11, 2015 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. Aug 11, 2015 at 14:53

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .