Official website for Linux User & Developer
FOLLOW US ON:
Sep
21

Create shared space for your multi-boot system

by Joey Bernard

We take a look at the steps needed to create a unified directory that you can use from any of your multi-boot installations

Many people set up their machines to boot up into multiple Linux distributions. This may be because they are developing software that they wish to test under different distributions, or they might just be interested in trying out new distributions and seeing what they offer. One issue that comes up is that files created while you are in one distribution aren’t easily accessible once you reboot into another one.

In this tutorial, we’ll look at the steps needed to create a shared space to store your files so that you have access to them, regardless of which distribution you boot into. In this way, you will still have a separate home directory in each installation to hold all of your application settings, along with a shared data directory that will contain all of the files that you want to have access to in all of the installations.

Step by Step

Partition Shared Space Fstab
Looking for extra space

Step 1 Where to set up

You will want to create a common data area that will be accessible from all of the installed OSs on your system. This could be on an external drive, like a USB key. However, this means that you would need to make sure that this external media was plugged in any time you wanted access. A better solution would be to create a partition on the internal drive to house this data area.

Step 2 Booting a live CD
Going this route means making changes to the partition table. This will require the disk partitions to be unmounted so that they can be altered. To do this, you will need to boot up from a live CD. A good first choice is SystemRescueCd. This CD will give you all of the tools you could possibly need to resize your current partitions and create a new one to hold your data directory. The easiest way to utilise it is to use UNetbootin to create a bootable USB key. There is also Parted Magic, which is one of the options available in UNetbootin.

Step 3 Resizing a partition

Most people use all of the available drive space when they install their OSs of choice, so this means that you will need to shrink at least one of the existing partitions to make space. With GParted, you can right-click on a partition and select ‘resize’.

Step 4 Resizing tip

When resizing partitions, be sure that you pick the right one. If you have a FAT or VFAT partition, be sure to defrag it first. If you end up resizing a partition on the middle of the disk, you will only be able to use the space up until the next partition.

Step 5 Creating a new partition

Once you have some free space available on your drive, you can go ahead and create a new partition to hold your data directory.

Note that there are two types of partitions: primary and logical. You can only have up to four primary partitions – so if you have more than this, you will need to make your new partition a logical one.

You can simply highlight the unused space section and click the ‘add’ icon in the top-left corner. This will pop up a dialog where you can set the size, whether it is a primary or logical partition, and what file system to format the new partition with.

Step 6 Reboot

Once you have created and formatted your new partition, you will want to write these changes to the disk and reboot back into your primary operating system or distribution.

This will then leave you ready to start using this new disk partition in all of your installed distributions.

Step 7 Creating a mount point

In order to use a disk partition, it has to be mounted to some point in your root file system. Since this will be used for your data in your regular user account, you will probably want to place it somewhere in your home directory. A good spot might be a subdirectory called my_data.

You would create this subdirectory with the following command:

mkdir ~/my_data

Partition Shared Space Fstab
Checking on which partitions are mounted

Step 8 Sudo

The next step is to be sure that the new partition is actually accessible. To do this, you will want to try mounting it manually.

On most Linux distributions, only the root user can do this. But, if your user account is set up as an administrator, you should have access to use the sudo command. This lets you run commands as if you were root.

Sudo will ask for your password in order to verify that it really is you.

Step 9 Manual mounting

Mounting the new partition is achieved using a single command:

sudo mount /dev/sdaX ~/my_data

…where X is the partition number of the new partition you just created.

In most cases, the mount tool is smart enough to see what file system is being used on the partition and use that. In the cases where it can’t, or you want to force it to use something else, you can hand it the ‘-t’ option and explicitly set the file system type.

Step 10 Changing ownership

When you mount a filesystem with sudo, the new subdirectory will end up being owned by root. This is not very useful to you, since you won’t be able to read or write to it. You can fix this by changing the ownership. Simply execute:

sudo chown -R jbernard.jbernard ~/ my_data

Note that you should replace ‘jbernard’ with your own username.

Step 11 Checking your mounts

You can verify your mounted partitions with the mount command. If you execute ‘mount’ with no options, it will present all of the mounted disk partitions and where on the file system these partitions are mounted to. The output for each mounted partition will look like:

/dev/sda3 on /home type ext4 (rw)

where any mount options are listed in brackets at the end.

Step 12 Unmounting

Once you are satisfied with everything, you can go ahead and unmount your data directory. You can either execute:

umount /dev/sda4

or

umount ~/my_data

You may get an error if this mount point is still in active use. For example, if you have a file browser open in the directory. Be sure to close any programs open in the data directory.

Step 13 Finding open files

Sometimes you may not realise what files are being held open, stopping you from unmounting the file system. The program lsof gives you a list of open files. You can execute:

lsof ~/my_data

to get a listing of all of the files in the subdirectory my_data that are being used by a program. This should help you identify and close down any troublesome program, and allow you to successfully unmount the data partition.

Step 14 Automating mounts

On boot, Linux looks at file ‘/etc/fstab’ to decide what partitions are to be mounted and where they are to be mounted to on the file system. This is where you will find the mount options for things like the root file system, or the home directories if they reside in their own partition. You can add a new line here for your data directory so that it too will get automatically mounted at boot time.

Partitioning Shared Space
Adding your own extra line

Step 15 Fstab options

The new line in fstab should look something like:

/dev/sda4 /home/jbernard/my_data
ext3 user,defaults 0 0

where you would enter the partition and directory names appropriate to your setup. The third field is the file system type. The fourth field is a comma-separated list of options. The two you will want to use are ‘user’ and ‘defaults’, which will set some sane defaults and also let the data partition be mounted by regular users.

Step 16 Tip about external drives

All of these instructions can be applied to an external drive, like a USB key. If you do this, you need to be sure to have it plugged in before booting. Otherwise, the system will fail to mount it and hang. You can get around this by adding ‘noauto’ to the fstab listing, but then you are responsible for remembering to plug it in before trying to use it.

Step 17 UUIDs

In step 15, we used the entry:

/dev/sda4

to identify the partition we wanted to mount. This might not work if we also use other removable media, since this could change the partition numbers that Linux uses. In these cases you can use the UUID, which is a unique identification for each device and partition. You can find it by executing

sudo vol_id -uuid /dev/sda4

You can then replace

/dev/sda4

in fstab with the entry

“UUID=xxxxxxxx”

where the Xs are the UUID alphanumeric characters of the device.

Step 18 Next system

Once you have this sorted out for the first distribution, doing the same for the other distributions is much easier. In each of the other distributions, you will need to create the same subdirectory named the same way.

You will also need to add the extra line to the file ‘/etc/fstab’. This will make your new data partition available under each of these installed distributions.

Step 19 Windows?

A lot of people also use Windows in their multi-boot systems. So what do you do? If you stick with more standard file systems, like ext2, then there are drivers and programs available that will allow you to mount this data partition and access your files.

You now have no excuse for not getting your work done, regardless of which OS you happen to be booted into. Remember that the ext3 and ext4 file systems are downwards-compatible to ext2, so they should still be available.

  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.
    • http://linuxblog.darkduck.com darkduck

      If you use Windows, than you need a FAT / NTFS partition.

      In my own 4-boot environment, I simply keep Windows partition as a data storage which every system can access.

    • ant

      I also use NTFS for all systems. But I also better solution : samba server. Windows can see it, linux can see it, and network speed is enough to browse files – use-stream files, even with 100mb link.

    • Nonya

      Simpler solution is a separate data partition. If you want to access it from Windows it will have to be a fat32 or ntfs partition. This has the added benefit that if one OS gets dammaged beyond use (without damage to the drive), your files are not corrupted or deleted.

      Of course backups are important too.

    • pcoq

      I have been using this method for years and years.

      I don’t bother making a separate /home partition, since it just has configuration files.

      I have an entire drive with all of my stuff on it (you could use a partition, but I like to keep my data totally separate from all of the partitioning that installers sometimes do). In each distro, I mount my data partition to ~/Documents at boot with this line in fstab:

      UUID= /home/me/Documents ext4 defaults 1 2

      I also have these lines in fstab:

      /home/me/Documents/downloads /home/me/Downloads none bind
      /home/me/Documents/music /home/me/Music none bind
      /home/me/Documents/pictures /home/me/Pictures none bind
      /home/me/Documents/videos /home/me/Videos none bind

      The way I store my stuff on my drive does not have to conform to the expectations of XDG and I don’t need to move it around, yet it is accessible by programs using this standard. I don’t need to modify /etc/xdg/user-dirs.defaults.

    • Ridgeland

      I use /Data mounted in each OS with /etc/fstab. Each OS gets about a 10GB root partition. I use home via bind to /Data/.home/OS_Partition_Identifier. Images, Music, Writer and Calc files are simple directories in /Data.
      Internet files for Firefox and Thunderbird are more sensitive to which version is running in which OS. I keep their files in /Data/.Internet/ and use a link in ~/.mozilla/firefox ~/.thunderbird but have copies for various versions. Fewer than one copy per OS_Partition but more than just one copy. Edit profiles.ini as needed. Then bookmarks and email are shared without sharing /home.
      Also be careful how new files are created. Default is only the file creator can edit the file. This can be a problem when you share files via NFS with other users. I use /etc/exports to allow 192.168.1.120 to see /Data/Music for example.

    • Pingback: Links 24/9/2012: | Techrights

    • Pingback: Links 24/9/2012: New Distros, GNOM 3.7 is Coming | Techrights

    • heracles

      Thanks for the nice article. I have a suggestion that will help those who try your command for finding the UUID of a device: “sudo vol_id -uuid /dev/sda4″. That command doesn’t work on my system, Ubuntu 10.04, nor is it in my repos. Here is what my /etc/fstab suggests:
      “blkid -o value -s UUID /dev/sda5″
      Use your own device name, drop the quotes, and, in my system, sudo isn’t required.

      The comments were also informative, but the ones by the experts pcoq and Ridgeland were not so useful to those of us who need more information to understand them well enough to actually use them. Maybe someone, or linuxuser, could discuss them more fully because they look as though they could be quite useful.

    • Pingback: Share space on your multiboot system « 0ddn1x: tricks with *nix

    • Pingback: Links 29/9/2012: GeeXboX 3.0, Distros Screenshots | Techrights

    • Pingback: Roommates penguins: sharing home (or a partition) in GNU/Linux « Extended Reality

    • Andries

      I’ve stumbled upon a strange issue. Got a 3TB Western Digital Green drive that I want to use as my shared drive. I partitioned it with Windows 7 (using the GPT partitioning scheme, which you need for >2TB).
      Unfortunately Linux (Ubuntu 12.04) doesn’t recognise the partition. fdisk sees the place holder all-blocks “partition” and tells me to use parted, but parted claims the disk is unpartitioned.
      The issue seems to be that Windows 7 addresses the disk with 4K/sector, but Linux uses 512 bytes/sector, which means Linux can’t find the GPT partition entries’ LBA locations.
      Any idea how to make this work?