Sharing Directories across Multiple Distros of Linux
I use seven different distros of Linux, which means there are seven home directories, which means seven different backups, and files scattered everywhere. I once tried have one shared partition that I mounted on each distro. With different desktops, different configuration files, there was hidden file chaos, and upgrades where a nightmare. I finally worked out a solution that works without depending on a network connection to share individual directories.
My goals were very simple:
- Share directories across multiple distributions of Linux
- A single backup for shared directories
- Easy to implement when installing a new distro of Linux
- Optimize the use of disk space
It is actually easy to implement as the following steps show:
Step 1: Add a new group. The name is not important, but the GID is. To be compatible across all distros, I set the GID to 1001. Just be sure that this GID is not used by any distro. Most distros have a graphical utility that manages Groups. With Ubuntu, you will have to use the addgroup command.
Step 2: Add the shared group to each user account that you want to use this group, as a secondary group. It should not be the primary group. You can use a graphical utility or the following command:
$ sudo usermod -aG <shared group> <account name>
Step 3: You will need to log off and log back on for the new group to be included in your login attributes. You can check that it is work by just typing:
$ id
Step 4: Create a separate partition formatted with ext3, or ext4. Since the distributions I use support ext4, I went with ext4 and created an 80 gigabyte partition. This should hold me for awhile.
Step 5: Create a mount point for the partition, and mount it:
$ sudo mkdir /share $ sudo mount /dev/sdXY # where X is the drive and Y the partition - sda10
Step 6: Change the group on the mount point to the name of the shared group. The shared group is going to provide the access to this directory. It makes no difference who is the owner of the directory. The command is:
$ sudo chgrp <shared group name> /share
Step 7: Change the permissions on the directory so that group has read, write, execute, and setGID. The setGID permission changes the effective group to the shared group, so that all user accounts can have access to the directory, without worry about the UID. By enabling the setGID permissions on the top level directory, all subdirectories will inherit this permission. This makes directories to the shared directory a lot easier. I always remove permission for others. If you have multiple users accessing the directory, you may want to set the sticky bit, so that only the owner of the file, and root, can delete it. Following are examples of both commands:
$ sudo chmod g=rwxs,o= # if only one account access the directory $ sudo chmod g=rwxs,0=t # if multiple accounts access the directory
Step 8: Now you can populate the /share drive with the directories that you wish to share across all the distributions. You can use either the graphical file manager, or you can use the following command to copy the popular directories:
cp -R Documents Downloads Music Pictures Public Videos /share
You can copy any other directories that you wish to share. For most desktops, the Desktop directory only contains files saved to the desktop. However, the KDE desktop use the Desktop directory to store information about each plasma desktop. Consequently, I do not share this directory.
When you look at the permissions in the /share directory, you will find that the owner is the same, but the group is now the shared group. Also, all directories have the setGID permission set.
Step 9: The following test is non-destructive, but a good way to verify that everything is working.
$ sudo mount --bind /share/Documents ~/Documents $ ls -ld Documents drwxr-s--- 13 <your account> share 4096 Dec 30 14:34 Documents/ $ ls Documents # it should be the same contents $ sudo umount /share/Documents
If it passed this test, you are ready for the next step.
Step 10: Since the /share directory is now a mirror image of the directories that you copied, you can remove the contents of those directories with the command:
$ rm -rf Documents/* Downloads/* Music/* Pictures/* Public/* Videos/*
The asterisk is important, as you are only removing the contents of the directory and not the directory, itself. You still need the directories as mount points.
Step 11: This step automates the mounting of the directories, by modifying /etc/fstab. Most distros use the UUID to identify the partition. If you look at /dev/disk/by-uuid, you will find that UUID values, but it is hard to identify the associated partition. The following example for /dev/sda10. show the easy way to find the UUID:
$ sudo blkid /dev/sda10 /dev/sda10: LABEL="share" UUID="a9e600f0-6384-40a5-ae65-bd4d7a6cb458" TYPE="ext4"
You are now ready to append the following lines to /etc/fstab.
# /dev/sda10 on /share
UUID=a9e600f0-6384-40a5-ae65-bd4d7a6cb458 /share ext4 nosuid,nodev,acl,user_xattr 1 2
/share/Documents /home/<your account>/Documents none bind
/share/Downloads /home/<your account>/Downloads none bind
/share/Music /home/<your account>/Music none bind
/share/Pictures /home/<your account>/Pictures none bind
/share/Public /home/<your account>/Public none bind
/share/Videos /home/<your account>/Videos none bind
To test the changes, you just need to enter the following command:
$ sudo mount -a
If there are any errors, just fix the entry in /etc/fstab and execute the above command again. Once everything mounts correctly, you can verify by checking the directory information in your account as you did in step 9.
Step 12: The hard work is done. The rest is purely repetition to the other distros. You just need to repeat steps 1, 2, 3, 5 (you don’t need to mount /share), and 11. Since I don’t like typing, I copied the relevant lines from one /etc/fstab to the next using the following commands from the distro you are changing:
$ sudo mount /dev/sdax /mnt # where X is the root directory of a distro already changed $ sudo vi /mnt/etc/fstab /etc/fstab
From /mnt/etc/fstab, I yanked the lines I wanted, an then entered :n to switch to /etc/fstab. In /etc/fstab, I just pasted the lines to the end of the file. After appending the lines to the new /etc/fstab, you can run the following command:
$ sudo mount -a
If everything works, you can then unmount the partition on /mnt. You are now ready to boot into the next distro, and repeat this step.
Now, I get to reclaim the partitions that I used for the home directory for some distros. Since the shared directories are automatically mounted, it is easier to make the change from another distro. By so doing, the home directory is nothing more than a mount point for the home partition. I just need to remove the mount entry from /etc/fstab, and copy the accounts from the home partition to the home directory in the root partition. For this step, it is safer to use the -aR option of the cp command. Once I reclaim the partitions for other uses, I always verify that the UUID of the shared partition did not change. If it did, I need to make the appropriate changes in each /etc/fstab.

