Novell Home

Install Linux Frequently, Without the Hassle

Novell Cool Solutions: Feature
By Bart Whiteley

Digg This - Slashdot This

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.

1.1. Assumptions

The rest of this document makes the following assumptions:

  • The system has a single hard disk: /dev/hda
  • Windows is installed on /dev/hda1
  • Your hard disk is sufficiently large, relative to your needs, that you can leave at least one 5 to 10 GB partition unused at any given time
  • You know how to install Linux, including repartitioning

    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. Partitioning

    2.1. Swap

    Use /dev/hda2 for the Linux swap partition.  It is usually recommended to have a swap partition 2x the size of physical RAM.  So, if you have 1GB RAM, make a 2GB swap partition.

    2.2. Root Partitions

    You'll want at least two root partitions so you can install a new version of the distribution, a different distribution, or a new build (or example, the next beta) without losing the Linux system you currently use.  This way you can always instantly rollback to the previous system without loosing any data.  Depending on the size of your hard disk, you'll probably want to make these partitions 5 to 10 GB each. 

    2.3. Data Partition

    Create one more Linux partition consuming the remainder of the hard disk.  This is where data will be stored so that it will not be lost when the OS is reinstalled onto one or the root partitions, and so that multiple systems can share the same data.

    2.4. Variations

    You can have other partitions if you like.  Perhaps you want to have a separate partition for VMWare images.  This isn't really necessary though since everything can be lumped under the Data partition, and symbolic links can be used if you want things to appear to be somewhere else.  If you want to share data between Linux and Windows, you may need an extra FAT32 partition.  Linux can read from NTFS volumes, but not write to them (last time the author checked).  By having an extra FAT32 partition (drive D: on Windows), you can put data on this partition and access it from either Windows or Linux. 

    2.5. Partition Table Summary

    Once finished partitioning, your partition table might look like this (output of fdisk -l /dev/hda):
      
         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. 

    3.1. Install Target

    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.

    3.2. Bootloader Location

    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. 

    3.3. Mount the Data Partition

    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.

    4.1. Move Bootloader Files

    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.

    4.2. Install GRUB in the Boot Sector of the Root Partition

    Now, assuming the root partition is /dev/hda3, type:
      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.

    4.3. Edit the Boot Menu

    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
      

    4.4. Booting the Linux OS

    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. 

    5.1. Setup the Data Partition

    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. 

    5.2. Symlinking to the Data Partition

    As the non-root user, create a symbolic link from $HOME to the data partition, and then symlink the dotfiles back to $HOME:
      
      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.

    5.3. Using the Customized Home Directory

    Put files that you want to be persistent across reinstalls under $HOME/data.

    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). 

    6.1. Bootloader Location

    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.

    6.2. Mounting the Data Partition

    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.

    6.3. Creating the Symbolic Links

    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. 

    7.1. Beta Snapshots

    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

    8.1. Third-party Applications

    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.

    8.1. Make the Most of Symbolic Links

    You might want to create symbolic links for other items in $HOME. For example, a symlink from $HOME/Documents to $HOME/data/Documents may be useful since many file dialogs default to $HOME/Documents.  You may also want to have multiple dot-files in $HOME/data/.etc for different versions of window managers.  For example, for a SUSE 9.2 system, you might have a symlink from $HOME/.kde to $HOME/data/.etc/.kde-3.3.  Then, when you install SUSE 9.3 beta1, create a symlink from $HOME/.kde to $HOME/data/.etc/.kde-3.4.  This way you can dual boot SUSE 9.2 and SUSE 9.3 and each system has its own set of preferences for KDE.  You should only have to set up KDE once for all of the betas and RCs for SUSE 9.3, since the minor KDE changes between betas and RCs are likely to be backward compatible with the configuration files.

    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.


    Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

  • © 2014 Novell