Installing CentOS 5.1 on a USB Drive

I wanted to install Linux on a USB drive that I could carry with me from place to place and use to boot a system wherever I happened to be with my bookmarks and files and no worry about using a possibly infected Windows system. So I installed CentOS 5.1 from a LiveCD (it was actually a DVD in this case). I used the i386 version, so I could use it to boot from either a 32-bit or 64-bit system.

I attached the 80 GB external USB drive I wanted to use to a Windows system that already had two internal IDE drives in it. I didn't want those modified at all, however.

To prevent the CentOS installation process from seeing those drives, I went into the system's BIOS and configured the BIOS so the two drives were listed as "not detected". One of the drives was the primary master and the other was the secondary slave. After modifying the BIOS settings, I then booted from the CentOS 5.1 Live CD.

When I booted the system from the LiveCD, I chose the option to install in graphical mode by hitting Enter. I skipped the test of the DVD I used as the LiveCD, since I had tested it previously.

Even though I had told the BIOS that the two internal drives were "not detected", CentOS saw them. It listed all 3 drives and asked me about which one I wanted to use for the installation.

hda157065 MBHDS722516VLAT80
hdd114471 MBST3120026A
sda76317 MBHTS5410R 0G9AT00

Linux identifies IDE drives with an "hd" designator, so the primary master was hda. There was no primary slave drive, so there was no hdb drive listed. The hdc drive was a DVD writer, so it wasn't shown. The hdd drive was the secondary slave. Linux identifies SATA and USB drives with "sd", so the external USB drive was listed as sda.

I selected the sda drive for the installation by checking it. I left the other two drives unchecked. When I started the partitioning process, I saw the following error:

Error Partitioning

Could not allocate requested partitions. Partitioning failed. Could not allocate partitions as primary partitions.

Not enough space left to create partition for /boot.

I realized the problem was due to the drive already being partitioned, so I needed to delete the existing partition. I hit Ctrl-Alt-Del to switch to a second terminal window. I then ran fdisk and checked the partition on the external USB drive, which is identified as /dev/sda. I then deleted the partition, wrote the change to disk, and exited from the shell.

sh-3# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = 80 cylinders of 16065 * 512 = 8225280 bytes

   Device Boot         Start         End      Blocks  Id  System
/dev/sda1                  1        9729    78148161   7  HPFS/NTFS

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = 80 cylinders of 16065 * 512 = 8225280 bytes

   Device Boot         Start         End      Blocks  Id  System

Command (m for help): w
The partition table has been altered!

Calling iotcl() to re-read partition table.
Syncing disks.

sh-3.1# exit
logout

I then hit Ctrl-Alt-F6 to return to the graphical installation window. I then clicked on the Next button again to create a default partition layout on sda. Again, I was warned about loss of data on the drive:

You have chosen to remove all Linux partitions (and ALL DATA on them) on the following drives:

/dev/sda

Are you sure you want to do this?

I chose "Yes".

The next screen showed the partition layout on all 3 drives. The format column was checked only for /dev/sda. The following was shown for that drive:

DeviceMount Point/
RAID/Volume
TypeFormat Size
(MB)
Start End
/dev/sda
   /dev/sda1/bootext3 101113
   /dev/sda2VolGroup00 LVM PV76214149729

I then clicked on the Next button where I saw two options:

The GRUB boot loader will be installed on /dev/hda.
No boot loader will be installed.

You can configure the boot loader to boot other operating systems. It will allow you to select an operating system to boot from the list. To add additional operating systems, which are not automatically detected, click 'Add.' To change the operating system boted by defaut, select 'Default' by the desired operating system.

GRUB stands for "GRand Unified Boot Loader". A bootloader is loaded from the Master Boot Record (MBR) on a hard disk. It is the first software that runs after the Basic Input Output System (BIOS) is loaded into memory. GRUB will load the linux kernel, which starts the boot process for Linux. For further information on GRUB see Getting Started with GRUB.

Since I didn't want any changes to the existing internal hard drives in the system, one of which was /dev/hda, I chose the option "No boot loader will be installed." I then clicked on the Next button.

At the next screen, I chose to use DHCP for the network settings, so just clicked on Next and then went through the other configuration options. Prior to the installation commencing, I saw the following:

A complete log of the installation can be found in the file /root/install.log' after rebooting your system.

A kickstart file containing the installation options selected can be found in the file 'root'anaconda-ks.cfg' after rebooting your system.

When the installation completed, the LiveCD was ejected. When the system rebooted, I went into the BIOS, which was an American Megatrends, Inc. (AMI) v02.53 BIOS, again to verify the system was configured to try booting from an external USB drive. The BIOS showed the following for the boot device priority:


Boot Device Priority
1st Boot Device [SM-Memorex DVD16+/] 2nd Boot Device [Removable Dev] 3rd Boot Device [HTS54108 0G9AT00]

The system was configured to attempt booting from the USB drive, which is model number HTS54108 0G9AT00, but I received a "Missing operating system" message when I attempted to boot from it.

I booted from the LiveCD again and typed linux rescue and hit Enter at the boot: prompt. After prompts regarding network support, I saw the following:

The rescue environment will now attempt to find
your Linux installation and mount it under the
directory /mnt/sysimage.  You can then make any
changes required to your system.  If you want
to proceed with this step choose 'Continue'.
You can also choose to mount your file systems
read-only insted of read-write by choosing 'Read-Only'.

If for some reson this process failes you can
choose 'Skip' and this step will be skipped and
you will go dirctly to a command shell.

I chose the "Continue" option rather than the "Read-Only" or "Skip" options. I then saw the following:

Your system has been mounted under
/mnt/sysimage.

Press  to get a shell. If you
would like to make your system the
root environment, run the command:

        chroot /mnt/sysimage

The system will reboot auotmatically
when you exit from the shell.

I hit Enter to get a shell. I then entered the command chroot /mnt/sysimage. I then issued the command grub-install /dev/sda.

sh-3# grub-install /dev/sda
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script 'grub-install'.

(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdd
(hd2) /dev/sda
sh-3.1#

When I entered the command cd /boot/grub, I then saw 14 files there where only splash.xpm.gz had been there previously. One of those was device.map, which contained the fd0 through hd2 lines shown above.

I checked the /boot directory and saw the following, along with other files.

initrd-2.6.18-53.el5.img
vmlinuz-2.6.18-53.el5

I then typed reboot and removed the DVD as the system started to boot. I then saw the following when the system rebooted:

   GNU GRUB  version 0.97  (639K lower / 1047232K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
  lists possible command completions.  Anywhere else TAB lists the possible
  completions of a device/filename.]

grub> 

I entered the GRUB commands to load the Linux kernel and boot the system.

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /vmlinuz-2.6.18-53.el5 root=/dev/sda1
   [Linux-bzImage, setup=0x1e00, size=0x1b3634]

grub> boot

...
VFS: Cannot open root device "sda1" or unknown-block(0,0)
Please append a correct "root=" boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

When I tried root (hd2,0) before trying root (hd0,0), I saw the message Error 21: Selected disk does not exist. Note: you can type kernel /vmlinuz and hit Tab to have the rest of the vmlinuz filename completed automatically for you.

Since the system was crashing and none of the options I tried for root= with the kernel command worked. I went back into the BIOS and configured it to detect the two internal drives again, thinking that might be causing the confusion, since I now had to use root (hd0,0) even though the /boot/grub/device.map file on the USB drive had the following:

(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdd
(hd2) /dev/sda

I also specified the hard disk drive priority to have the external USB drive as the first hard drive to check. In the version of the AMI BIOS on the system I was using, there is a Hard Disk Drives option under Boot to specify the priority for using hard disk drives to boot [Note: I noticed, if I removed the external USB drive and then plugged it in again later, I had to move it to the 1st Drive spot in the list again, since it would be listed last by default].

I then saved the BIOS settings and rebooted. I then tried using an init command, since I found a comment at Grub from the Ground Up, that adding one could sometimes help when a system would display a "kernel panic" message, but that didn't help.

   GNU GRUB  version 0.97  (639K lower / 1047232K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
  lists possible command completions.  Anywhere else TAB lists the possible
  completions of a device/filename.]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /vmlinuz-2.6.18-53.el5 root=/dev/sda1
   [Linux-bzImage, setup=0x1e00, size=0x1b3634]

grub> initrd /initrd-2.6.18-53.el5.img
   [Linux-initrd @ 0x37cfc000, 0x2f3391 bytes]

grub> boot
...
WARNING: Can't access (null)
exec of itnit ((null)) failed!!!: Bad address
Kernel panic - not syncing: Attempted to kill init!

I then decided to check the /boot/grub/menu.lst file on a working CentOS 5.1 system. When I did, I saw the following in that file.

title CentOS (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.16.el5 root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M
        initrd /initrd-2.6.18-53.1.14.el5.img

I booted from the USB drive again and entered linux rescue at the boot: prompt. I then tried using the root value I saw in the /boot/grub/menu.lst file I saw on the working CentOS system, which has an internal SATA drive on which CentOS 5.1 is installed.

   GNU GRUB  version 0.97  (639K lower / 1047232K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
  lists possible command completions.  Anywhere else TAB lists the possible
  completions of a device/filename.]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /vmlinuz-2.6.18-53.el5 root=/dev/VolGroup00/LogVol00
   [Linux-bzImage, setup=0x1e00, size=0x1b3634]

grub> initrd /initrd-2.6.18-53.el5.img
   [Linux-initrd @ 0x37cfc000, 0x2f3391 bytes]

grub> boot

This time, when I used kernel /vmlinuz-2.6.18-53.el5 root=/dev/VolGroup00/LogVol00, the system booted into CentOS where I could continue with the setup of CentOS. After answering various prompts to continue with the setup, including creating a user account, I just got a cursor I could move with the mouse on a black background, though. I rebooted with the reset button on the system. I entered the same grub commands again and got to a login screen. I was able to login as root and got a GUI display. The system had picked up an IP address via DHCP and I was notified there were 210 package updates available, which I installed. At first it didn't appear anything was happening when I clicked on the Apply Updates button, but eventually I saw the packages being downloaded and installed.

So that I don't have to enter the grub commands each time I boot from the USB drive, I created a /boot/grub/menu.lst file. Using the version on the working system as a template, I put the following commands in the file.

# GRUB - created on 2008-07-22
#
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M
        initrd /initrd-2.6.18-53.el5.img

I could have just put in the root, kernel, initrd commands and left out the rhgb, quiet, and crashkernel parameters from the kernel command, but I decided to match the other system's configuration options.

The hiddenmenu command hides the menu interface and automatically boots the default entry, unless interrupted by the Escape key.

The ro parameter on the kernel line causes the kernel to mount the drive read-only initially; later the drive will be remounted read/write. This is generally done so fsck can run on / at bootup.

The rhgb on the kernel line stands for "redhat graphical boot". This is a GUI mode booting screen which displays brief information regarding what the computer is doing while booting.

The quiet option on the kernel line hides the majority of boot messages before rhgb starts. According to Re: What is "rhgb" on the grub, kernel line?, "These are supposed to make the common user more comfortable. They get alarmed about seeing the kernel and initializing messages, so they hide them for their comfort." The poster likens the messages that would appear to messages that appear when Windows XP or 2000 are booted into Safe Mode.

The crashkernel option specifies the amount of memory to reseve for the dump-capture kernel, to be used for troubleshooting should something go wrong with the operating system. It is specified in the form crashkernel=Y@X where Y specifies how much memory to reserve and X specifies the beginning of this reserved memory. So, in this case, I'm specifying that 128 Megabytes of memory be reserved at physical address 0x01000000, i.e. the hexadecimal address for 16 MB.

The upgrade of packages provided an update to the kernel as well. When I checked /boot after the packages were installed, prior to rebooting the system, I saw the following files:

config-2.6.18-53.el5
config-2.6.18-92.1.6.el5
initrd-2.6.18-53.el5.img
initrd-2.6.18-92.1.6.el5.img
symvers-2.6.18-53.el5.gz
symvers-2.6.18-92.1.6.el5.gz
System.map-2.6.18-53.el5
System.map-2.6.18-92.1.6.el5
vmlinuz-2.6.18-92.1.6.el5

So, I added a section for the kernel update in /boot/grub/menu.lst above the section for version 2.6.18-53.

# GRUB - created on 2008-07-22
#
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-92.1.6.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-92.1.6.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M
        initrd /initrd-2.6.18-92.1.6.el5.img
title CentOS (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M
        initrd /initrd-2.6.18-53.el5.img

Since I have default=0 in menu.lst and listed the new kernel first in the list, it is the "0" option and will be loaded. Leaving the old one referenced as the second or "1" menu option allows me to boot from it as well, if needed.

After updating menu.lst, I issued the reboot command to reboot. I was presented with the grub prompt again rather than the system booting to CentOS automatically as I expected after I had created menu.lst.

   GNU GRUB  version 0.97  (639K lower / 1047232K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
  lists possible command completions.  Anywhere else TAB lists the possible
  completions of a device/filename.]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /vmlinuz-2.6.18-
 Possible files are: vmlinuz-2.6.18-53.el5 vmlinuz-2.6.18-92.1.6.el5

grub> kernel /vmlinuz-2.6.18-92.1.6.el5 root=/dev/VolGroup00/LogVol00 rhgb quiet crashkernel=128M@16M
   [Linux-bzImage, setup=0x1e00, size=0x1b6cf4]

grub> initrd /initrd-2.6.18-92.1.6.el5.img
   [Linux-initrd @ 0x37cfc000, 0x1 bytes]

grub> boot

This time when I entered kernel /vmlinuz and hit Tab, I saw two options listed for the vmlinuz file. I chose the newer one. After I entered the boot command, the system booted into CentOS 5.1. When I issued the command uname -a, I saw 2.6.18-92.1.6.el5 listed as the kernel version.

I wasn't sure why the system hadn't used menu.lst to automatically select the latest kernel on the systm and boot using it. I looked at the working CentOS system again and found that menu.lst was actually linked to grub.conf.

# ls -l menu.lst
lrwxrwxrwx 1 root root 11 Mar 29 07:40 menu.lst -> ./grub.conf
# ls -l grub.conf
-rw------- 1 root root 811 Mar 29 15:13 grub.conf

So I renamed menu.lst to grub.conf on the USB drive and changed the permissions on grub.conf to match those on the working system. I then created a symbolic link to grub.conf from menu.lst.

# mv menu.lst grub.conf
# chmod 600 grub.conf
# ln -s grub.conf menu.lst

I rebooted the system. This time, the system booted automatically according to the configuration listed in menu.lst, i.e. grub.conf.

References:

  1. Getting started with GRUB
    By Chad Files
    Date: June 14, 2007
    linux.com
  2. Command-line and menu entry commands - GNU GRUB Manual 0.97
    GNU Operating System
  3. Hidden menu interface
    GNU GRUB Manual
  4. GrubHowto
    User Documentation - Community Ubuntu Documentation
  5. Re: What is "rhgb" on the grub, kernel line?
    By: Jim Cornette (jim-cornette_at_insight.rr.com) Date: May 28, 2004
    Der Keiler Linux
  6. Linux Kernel Documentation :: kdump
    Page Generated On: 2008-07-16
    mjm wired
  7. Editing /boot/grub/menu.lst to change the GRUB boot menu
    boff