Multiple Linux OS with Share Swap and Home partition

Home / Multiple Linux OS with Share Swap and Home partition

For some poeple, installing one Linux might be not enough. Some people want to experiment on various Linux distribution on a single machine. Or maybe they are using various distribution for different purpose, for example: Ubuntu for daily use, and Backtrack for special purpose. Hence, you need two (or more) distribution on your machine.

However, problem might arises. Having multiple distribution at single machine means you have to prepare all the requirements, including partitions. What if you have storage shortage? You might set the partition to use as minimum as possible. Let say from 200GB HDD, you might want 120 for Ubuntu and the rest for Backtrack. Not bad. At minimum, each Linux distribution need a root partition and swap (well, some might argue you don’t always need it). Instead of creating a different swap partition for each distribution, why won’t we create a single swap partition and use it for all of our distribution? What if you want a separate /home partition to store data and instead of creating different different /home partition, we can create a single /home for all of our distribution. And that’s what this article for!

In this article we will discuss about to create a shared swap and home partition for multiple Linux distribution. For this purpose I use:

  1. OpenSuse 11.3
  2. Backtrack 5 R2

Warning: before proceeding to next step, make sure you have read and understand what you will do. Slight mistake might risk your entire process and I won’t take any responsibility for it 😀

Essentials

What we want to do:

  1. Creating partition
  2. Install OpenSuse
  3. Install Backtrack
  4. Adjusting

Sounds simple. However, take note that:

  1. Both Linux distro has same id for user and group. This will ensure your system to keep clean and healthy. If you don’t plan to use same username, you can create different username for each distro. However if you plan so, make sure you read Resolve Username Issue section.

Creating Partition

Let’s design how our disk layout will be.

The first step always state what you need. Check how many distribution you want to install and what partition you need. Because we will have share swap and home, then we need 1 swap partition and 1 home partition. Next at least we have separate root partition for each of distribution. In this case we need 1 for OpenSuse and 1 for Backtrack. In total, we need 4 partitions (swap, home, root OpenSuse, root Backtrack).

Now, how these partition would be arranged on disk? Well, it’s up to you. But in our case, we will use following layout:

  1. swap partition
  2. /home partition
  3. OpenSuse’s root partition
  4. Backtrack’s root partition

As my RAM is big enough to hold computation and won’t likely to use swap, unless I want to hibernate.

Now, how many storage should we allocate? Before, I say we have 200GB HDD, so let’s take it as the case. Suppose you have RAM 4GB and following 1.5 rules, we might want to set our swap to 6GB thus left us with 194GB. In this case, OpenSuse will be used mainly, so it won’t be a surprise that it need more space for apps. Let’s give it 80GB. The Backtrack will be used occasionally and the tools we need are already shipped on the disk, so 40GB might enough. Now, the rest (74GB) will be our /home partition. Our data will be stored there, so it’s normal.

Of course this example is for our case. If you want to do it in other way, it’s your choice. However, let’s stick to this 😉

If you have MBR-based disk, you are restricted to have 4 primary partition. If you have GPT based disk, you can have as many primary partition as you like. Unlike Windows, Linux can use extended partition as root partition. For this, let assume all of our partition will be on extended partition 😉

Now, let say our final design would be like this (assuming extended partition is starting from sda5):

  1. sda1 swap 6GB
  2. sda2 /home 74GB
  3. sda5 distro1 / 80GB
  4. sda6 distro2 / 40GB

Installing First Distro

OK, now let’s moving to first phase. Installing first distro would also mean you create the partition to the disk as designed :).

Boot the CD/DVD. Follow all the process like default until you arrive at page partitioning phase (or so). In this phase, use the option to create partition manually.

Create the partition using the design layout. Don’t forget to assign swap and /home partition.

Now continue the installation as normal.

If you follow the guide, at this point we have sda1 as swap, sda2 as /home, and sda5 as / partition.

Installing Second Distro

Might also be used to install third or rest distro if you plan to.

Remember that we already have disk layout as we designed before! Therefore we don’t need to create other partitions, just use the created one.

Boot the second DVD. Follow the instructions until you arrive to partitioning phase. We need to manually define our partitions. Unlike installing first partition, we don’t need to create the partition. Choose the available partition (following our design).

Don’t forget to set the /home and swap partition. At some distro, swap is recognized by default. Don’t format the /home (sda2) ! Just assign it.

Next,  install the distro but make sure when you install the boot loader the first previous distro (s) is recognized by the boot loader. It would be nice if you install same bootloader for all distro (ex: GRUB2 which would be the default bootloader for most distros).

At this point, if you following the guide, we have sda1 as swap, sda2 as /home, and sda5 as distro1 / partition, sda6 as distro2 / partition.

Resolve Username Issue

If you arrive at this point, it means you are either plan to use same username on all distro or just curious.

The problem when you want to set all distro to use same username will lie on the filesystem partitions. Unlike root account which has same default user on whatever distro, common user’s userid will be assigned according to the distro’s policy. It would be disaster if we have same username but in different distro we have different userid. For example: in distro 1 user xathrya‘s id is 1001 while in distro 2 is assigned to 10001. Remember the permissions? What if a  having 644 permission and owned by user xathrya. Created on distro 1, it will be owned by id 1001, but when used in distro 2, xathrya is completely stranger!

Therefore, we strive to resolve the username issue before we start using the system.

I’m assuming the distro’s are fresh installed to avoid unnecessary actions.

First, choose what distro will be base on? It is recommended to use username on frequently used distro and have read/write disk often (at least before we resolve the issue).

Let say, we want xathrya will use id set on distro 1.

Now open /etc/passwd on distro 1 partition. Search for line with xathrya, it should be (and must be) only 1 there. The line will be in following format:

username:x:uid:gid:name,,,:home directory:shell

for example (on my machine):

xathrya:x:1000:100:Xathrya Sabertooth,,,:/home/xathrya:/bin/zsh

Here we see that xathrya is assigned with user id (uid) 1000 and group id (gid) 100.

For each distro you have, open /etc/passwd and search for user you want to resolve (for example xathrya) and adjust its uid and gid.

And that’s all.

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial