Use same home directory on multiple Ubuntu-mate computers

Im not a savy IT person, but I have been using Ubuntu-Mate on my Acer laptop for 2 years and on my PI3 for 1 year. I now have an additional laptop and I’m equally running Ubuntu-Mate 18:04 on it.

Here is what I want to achieve: Currently, I run around with my USB stick and stick it into the computer I’m working with. This is not very convenient especially for emails. Is there a possibility to put the “home directory folder” on an USB stick and each “tell” each time the computer to use the “home directory folder” from the USB.

Thank you.

Linux can mount a filesystem on top of another system. So, when you insert the USB stick, it is probably auto mounted under /media/(username)/(USBDeviceLabel). If you issue the command ‘$ mount --bind /media/(username)/(USBDeviceLabel) /home/(username)’ then your home directory will now point to the USB stick.

But, I’m going to tell you–this is a REALLY bad idea. If you ever use your original home directory on any machine, the hidden config files will be updated on the hard disk, not the USB. Likewise, some of those config files may be hardware specific, so when you plug in the USB stick’s version of the files, it won’t match the hardware of the machine.

Also, USB sticks are notoriously prone to failure or just losing them. How will you back up? If you lose the stick, you will lose all your settings. You will also be storing all your online passwords on the stick, perhaps in the Firefox profile. What if someone gets that?

A much better plan is to use rsync to copy the data onto the stick and off the stick each time you change machines. You could write a little script for that. Copy all your home directory, but exclude any hidden files ‘.*’ . There is also software called Unison to do exactly this function, as well. (I use rsync, so I can’t tell you any more about Unison).

Charles Nix

1 Like

Thank you for sharing your thoughts, especially the REALLY bad idea. I will definitely will stay away from it. Very good guidance.
For Unison I checked already on a few websites and will investigate further.
For writing a little script with rsync, I’m afraid this is (currently) out of my ability. But I’m interested in learning. Any similar script I can find here in the blog? Or is there even a tutorial since it should be a common problem for other users.

I think you could start with a little script for bash (the most common command line interpreter). So it would have two lines
rsync (rest of rsync command here)

Open a terminal window and type
$man rsync
to see the rsync options and many examples of use or google for examples. rsync is a very complete, robust program. It can check to see if a file has changed, and only transfer the changed files. The exact command you need to use can vary greatly with your individual setup and with what filesystem is on the USB stick.

Assuming you have ext2/3/4 on your hard disks, and FAT32 on the USB, and that all your home directories are in single partitions, something like this will get you close:

$rsync -rtivv --modify-widow=2 --delete --exclude=’.*’ /home/(username)/ /media/(username)/(USBLabel)

Options you should study would be --dry-run (or -n) --delete --exclude-from=FILE and -c. Also understand exactly what the options I’ve included are doing before you use them, particularly --delete. If the USB is, indeed, FAT32, there is no need to use -a (or -l -p -g -o -D) because FAT32 doesn’t have file permissions, owners, groups, or links. (Some of the preceding is not completely true, but it is for your purposes).

And that brings up another potential catch. When you transfer files from one machine to another using a FAT32 USB, you will lose all those file attributes. Restoring them on another ext2/3/4 file system will recreate the attributes from the new machine’s user umask.

If you are ONLY using the USB on Linux machines, it would be better to reformat it as ext2/3/4. Then you can use rsync with the options -av --delete, and preserve all the information. You should be sure that your owner and group names are the same on all concerned machines, and that they translate to the same numerical userid and groupid. If you are the only (and first) user on each machine, then they will match up. You can check the numerical ids in the /etc/passwd and /etc/group files.

Also, if any of your machines are on the same network, you can transfer directly from one to the other with rsync, and not go through the USB stick.

I would suggest trying out rsync options at the command line first to get to know what you are doing. When you are happy with the results, creating a script is as simple as putting the #!/bin/bash line and the rsync line in your favorite text editor, saving the file, and making it executable. To use it, open a command line, and type:

1 Like

Charles, thank you for the very detailed explanation, hence the motivation to get this done. I will use the USB stick only on Linux machines so my first step will be to reformat the USB as ext2/3/4. I still have one machine running on Ubuntu-Mate 16.04 which I will upgrade to 18:04 (I suppose otherwise I suspect problems). After that I will start a few experiments and training sessions rsync as suggested. Only caveat is I’m based out of China so Google is not available but I should find examples on yahoo. Over the weekend I will start practicing. I will keep you updated on the progress! Have a great weekend!