Install Linux Often or Boot Multiple Linux Systems with Minimal Effort
By Bart Whiteley
Posted: 23 Mar 2005
Abstract
With RPM-based Linux distributions, version-to-version upgrades often don't work very well. A fresh installation may be the better choice. One may be reluctant to do this, because of the potential loss of data, preferences, configuration, and third-party applications. Also, if you don't like the newly installed system, the thought of reinstalling the old system to switch back to it is not a pleasant thought either.
This document describes a means of reinstalling Linux frequently, while minimizing the effort needed to become productive on a new system. It also allows you to instantly and effortlessly rollback to a previous Linux OS if you aren't happy with a newly installed system. Some possible applications of these suggestions include trying a new Linux distribution, or staying up-to-date with the latest beta release of your favorite Linux distribution.
Table of Contents
- 1. Introduction
- 1.1. Assumptions
- 2. Partitioning
- 2.1. Swap
- 2.2. Root Partitions
- 2.3. Data Partition
- 2.4. Variations
- 2.5. Partition Table Summary
- 3. Installing The First Instance of Linux
- 3.1. Install Target
- 3.2. Bootloader Location
- 3.3. Mount the Data Partition
- 4. Fixing the Bootloader
- 4.1. Move Bootloader Files
- 4.2. Install GRUB in the Boot Sector of the Root Partition
- 4.3. Edit the Boot Menu
- 4.4. Booting the Linux OS
- 5. Home Directory Maintenance
- 5.1. Setup the Data Partition
- 5.2. Symlinking to the Data Partition
- 5.3. Using the Customized Home Directory
- 6. Installing More Linux Systems
- 6.1. Bootloader Location
- 6.2. Mounting the Data Partition
- 6.3. Creating the Symbolic Links
- 7. Practical Use
- 7.1. Beta Snapshots
- 8. Other Hints
- 8.1. Third-party Applications
- 8.2. Make the Most of Symbolic Links
- 9. Summary
1. Introduction
If a little extra care is taken when first installing Linux on a system, it can require far less maintenance over the lifetime of the system. This document presents suggestions for using partitions and symbolic links to your advantage to minimize the effort required to test-drive a new Linux distribution.The rest of this document makes the following assumptions:
If your system differs from this, you'll need to make appropriate
adjustments to the examples that follow. For example, if you do
not have windows installed, the swap partition can be /dev/hda1 instead
of /dev/hda2. If you actually think you can find a use for the
entirety of your modern, huge hard disk, this document is not
for you. 2.1. Swap 4.2. Install GRUB in the Boot Sector of the Root Partition 5.2. Symlinking to the Data Partition 5.3. Using the Customized Home Directory 8.1. Make the Most of Symbolic Links
2. Partitioning
Device Start End Blocks Id System
/dev/hda1 1 xxxxx 18000000 7 HPFS/NTFS
/dev/hda2 xxxxx xxxxx 2000000 82 Linux swap
/dev/hda3 xxxxx xxxxx 10000000 83 Linux <-- root 1
/dev/hda4 xxxxx xxxxx 50000000 5 Extended
/dev/hda5 xxxxx xxxxx 2000000 c W95 FAT32 (LBA)
/dev/hda6 xxxxx xxxxx 10000000 83 Linux <-- root 2
/dev/hda7 xxxxx xxxxx 10000000 83 Linux <-- root 3
/dev/hda8 xxxxx xxxxx 28000000 83 Linux <-- data
If you don't have Windows installed, it might look like this:
Device Start End Blocks Id System
/dev/hda1 1 xxxxx 2000000 82 Linux swap
/dev/hda2 xxxxx xxxxx 10000000 83 Linux <-- root 1
/dev/hda3 xxxxx xxxxx 10000000 83 Linux <-- root 2
/dev/hda4 xxxxx xxxxx 68000000 5 Extended
/dev/hda5 xxxxx xxxxx 10000000 83 Linux <-- root 3
/dev/hda6 xxxxx xxxxx 58000000 83 Linux <-- data
3. Installing The First Instance of Linux
Once the partition table has been prepared as described above, you are
ready to install the first Linux system.
Install into the first root partition. If you want, you can also select the data partition
at this point, and specify the mount point of /data. This doesn't
need to be done at install time. You can format and mount this
partition after the system is installed if you prefer. If you select
the data partition during the install, it will be formatted and mounted,
but it will remain empty.
When installing the first system, you'll need to install GRUB into
the Master Boot Record (MBR). This is probably the default. Note
that this is the only time you will install the bootloader into the
MBR. Every Linux install hereafter you will need to take care to
install GRUB into the boot sector of the root partition, not the MBR.
Once the first Linux system is installed, ensure that the data
partition is mounted
at /data. If this wasn't taken care of during the install, format
the data partition now. Mount it and put it in /etc/fstab so that
it will be automatically mounted at boot-time.
4. Fixing the Bootloader
You need to move the bootloader files to the data partition, since
this partition won't be formatted again, but our Linux root partition
will eventually be reformatted and reinstalled. The MBR needs to
point to GRUB files that won't be destroyed during future reinstalls.
Create a directory /data/boot. Copy the files stage1,
stage2, and menu.lst
from /boot/grub to /data/boot:
cp /boot/grub/{stage1,stage2,menu.lst} /data/boot/
Now launch the GRUB shell (type grub) and enter the
following command:
install (hd0,7)/boot/stage1 d (hd0) (hd0,7)/boot/stage2 (hd0,7)/boot/menu.lst
You may have to adjust this command based on which partition is /data.
Note that GRUB partitions are zero indexed, so /dev/hda6 is (hd0,5),
and /dev/hda8 is (hd0,7). Within the GRUB shell, type
help install for more information.
grub-install /dev/hda3
You may be confused why you installed
GRUB into both the MBR, and the boot sector of the root partition.
In the next step, you'll configure the bootloader in the MBR to "chain"
to the various Linux systems.
Edit /data/boot/menu.lst. The only menu items should be a series
of "chainloader" directives, and possibly an item to launch future
network installs without a CD. For example:
title Windows XP
chainloader (hd0,0)+1
title Linux on hda3
chainloader (hd0,2)+1
title Linux on hda6
chainloader (hd0,5)+1
title Linux on hda7
chainloader (hd0,6)+1
title Install
root (hd0,7)
kernel /boot/linux.inst install=ftp://<your_net_install_path> vga=791
initrd /boot/initrd.inst
Now when you boot the system you will see a menu containing
Windows (possibly), several Linux systems, and possibly an install
option. When you select a Linux system, you are faced with another
GRUB menu. This is the only drawback of this system -- there is an
extra delay in the boot process because the first GRUB menu leads to
another GRUB menu. This problem can be minimized by decreasing the
delay in the second GRUB menu (the GRUB menu for each Linux system).
5. Home Directory Maintenance
One might ask, "Why not just make /home a separate partition,
instead of making a separate /data partition?" The answer is
simple, though unfortunate. There are user-specific configuration
items stored in "dotfiles" (filenames starting with '.')
in each user's home directory. For example, all KDE preferences are
stored under the directory $HOME/.kde/. These files are
often not backward compatible between versions of applications.
The preference files in $HOME/.kde/ for KDE 3.2 are probably not
compatible with KDE 3.3. This is even more true for Desktop preference
files between different Linux distributions.
While logged in as root,
create a directory under /data for each user, and chown the
directory to that user.
mkdir /data/djones
chown djones /data/djones
You may also want to chmod the directory to mode 700 to give it
greater protection. Now log in as the non-root user, and create
a directory /data/djones/.etc. Move selected dotfiles
from $HOME to this directory. For example, .ssh, .vmware, and
.vslick.
mv $HOME/{.ssh,.vmware,.vslick} /data/djones/.etc/
If these dotfiles don't exist yet, create empty directories
in /data/djones/.etc/ instead of moving existing directories there.
The idea is to select dotfiles which are known to maintain
the same format and syntax between versions of the application, and
which are painful to lose (such as .ssh). Through experience you
will learn which dotfiles can safely be used across multiple versions
of multiple distributions.
ln -s /data/djones $HOME/data
cd $HOME
ln -s data/.etc/.[a-z]* .
You may need to remove the corresponding existing dotfiles
from $HOME before doing this.
6. Installing More Linux Systems
Now you can install more Linux systems. For example, you may
want to install a different Linux distribution in root 2 (/dev/hda6),
and root 3 (/dev/hda7).
The most important thing to remember while preparing to install a
new Linux OS is to install the bootloader into the boot sector of the root partition,
not the MBR. The default is probably the MBR, so you'll have to
change this setting.
You can either mount the data partition under /data during the
install, or after the install. If done during the install, make
sure you deselect the format flag. Perhaps it is better just to
do a single-partition install, then manually add /data to /etc/fstab
and mount it once the install is complete.
Now repeat step 5.2 to create symbolic links from $HOME to
/data.
7. Practical Use
Now that you have taken these initial steps, you can reinstall
your system, or install additional systems quite easily. The
time needed to get a new system in a usable state is minimized,
and your data files are always available to any system.
This system is particularly useful for beta snapshots. For
example, perhaps you have been running SUSE 9.2 for some time.
SUSE 9.3 beta1 becomes available. You would like to try it.
Perhaps it is sufficiently stable to replace SUSE 9.2 as your
main Linux OS, but perhaps not. This system lets you try
SUSE 9.3, while reserving the option to immediately rollback to
your old SUSE 9.2 system. If you have been using SUSE 9.2 on
root 1, simply install SUSE 9.3 beta1 on root 2. If you try it
for a while, and decide it is usable, continue using it. All
of your data is present. After you are comfortable running
9.3 beta1, you can install something else (perhaps SUSE 9.3 beta2)
onto root 1. You need not worry about reformatting and reinstalling
root 1, because the only thing on /dev/hda3 is the base system. All
of your data is on the data partition.
8. Other Hints
To maximize the efficiency of this system, make sure to install
all third-party applications under $HOME/data. For example, you might
install Visual Slickedit into $HOME/data/vslick. If you also
symlink $HOME/.vslick to $HOME/data/.etc/.vslick, Visual
Slickedit will be immediately usable when a new Linux OS
is installed, with all of your preferences and projects preserved.
9. Summary
If the steps of this document are followed, it is easy to reinstall
a new Linux system without risk, and you can quickly become productive
on the new Linux OS.