Tuesday, September 25, 2012

Create shared space for your multi-boot system

http://www.linuxuser.co.uk/tutorials/create-shared-space-for-your-multi-boot-system


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.

No comments:

Post a Comment