Perform Tricks for Your GRUB

By Carla Schroder | Apr 22, 2004 | Print this Page
http://www.enterprisenetworkingplanet.com/netos/article.php/3344241/Perform-Tricks-for-Your-GRUB.htm
Last week, we looked at migrating from Linux Loader (LILO) to Grand Unified Bootloader (GRUB). This week's scintillating agenda includes the following:
  • installing GRUB without a floppy disk
  • restoring GRUB from a Knoppix CD
  • easily restoring LILO
  • multi-booting
  • booting a RAID 1 array

Root Devices and Root Filesystems
Once again, excellent readers come with useful stuff. A couple of readers wrote to clear up the confusion over root devices, and root filesystems. Here is a typical menu.lst entry:

title       Libranet GNU/Linux, kernel 2.4.21
root      (hd0,5)
kernel      /boot/vmlinuz-2.4.21 ro root=/dev/hda6

The root device is the location of the boot images: stage1 and stage2, the kernel, and other boot files. These are in the /boot directory. /dev/hda6, on the kernel line, is the path to the root filesystem. The root device is a GRUB argument, so it needs GRUB nomenclature. The root filesystem is a kernel argument, so it needs kernel nomenclature.

These are most commonly on the same filesystem. However, they do not have to be — you can have your /boot directory and root filesystem on different partitions. For example, if you have a separate boot partition.

Installing GRUB Without A Floppy Disk
An increasing number of systems are shipping without floppy drives, especially notebooks. How to install GRUB without a floppy drive? First, install or upgrade GRUB on your system. Then open a root shell, and open GRUB's command shell:

root@windbag:/# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.94 (640K lower / 3072K 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>

Now run these three commands:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Reboot, and you will be greeted by the GRUB command shell. Note that the root value is variable, depending on where GRUB is installed on your system. (See "The Dog Ate lilo.conf" in part 1 for how to find root devices from the GRUB command line.) setup (hd0) installs GRUB to the MBR (master boot record), and quit exits GRUB.

Restoring GRUB From A Knoppix CD
Having a GRUB floppy disk is the fastest way to fix boot problems. However, if you have no floppy drive, that doesn't really do you a lot of good. Fear not, for the endlessly useful Knoppix bootable Linux CD will take care of things. To restore GRUB to the MBR, boot up Knoppix and open a shell. Then su to root (there is no password), and run the same commands as above.

Continued on Page 2: Easily Restoring LILOContinued From Page 1

Easily Restoring LILO
Don't uninstall LILO — leave it intact, including lilo.conf. The /boot directory will get cluttered with both LILO and GRUB files, but that doesn't hurt anything. You can have both on your system, and easily switch back-and-forth simply by installing the one you want to the MBR. Of course old LILO hands know how to do this:

# /sbin/lilo -v

Multi-booting
GRUB really shines at multi-booting. GRUB operates independently of any operating system. So you can create a separate boot partition, then add and remove operating systems at will, without disturbing the bootloader. It's a great way to build a compact testing network, using native environments. With three machines — two desktops and a notebook — you can combine many combinations of Linux, Windows, and any other operating systems you like, and test things like networking, proxying, mail servers, web servers, terminal servers, VPNs, firewalls, routings — anything at all. Throwing a notebook into the mix is a good idea, as they usually have weirdo proprietary hardware, so it's a good way to test it.

Here's how to do it:

Starting from scratch, install a new Linux. During installation, create a 100-MB boot partition. Make this a primary partition. When the installation is completed, you'll be able to delete the root filesystem, and still have a functioning bootloader. There won't be anything to boot to, but you can now add other operating systems, and have your boot files and configuration safely isolated. And, you can mount the boot partition in any Linux, and edit menu.lst as you need.

Another option is to have a minimal Linux installation on its own primary partition, to use as your stable "host" operating system, containing GRUB's active /boot directory. Debian and Red Hat have minimal installations of around 500 megabytes; give them a 1-gigabyte partition to allow room for log and tmp files, and any data you wish to store.

Multi-booting Windows
GRUB makes multi-booting Linux and Windows NT/2000/XP a whole lot easier. The easy way is to install Windows first, or multiple Windowses, then install Linux last. If you're going to run more than one Windows, you need to install them in order, oldest first. Windows NT/2000/XP will recognize other installed Windows, and add them to its own bootloader. When you finish off the installation spree with Linux, be to sure to install GRUB to the MBR. It will automatically create a menu entry for Windows.

Linux will happily boot from logical partitions, Windows will not. To run multiple Windows, you need one primary partition, then create as many additional logical partitions as you need. The easiest way is leave free space on the drive, then use the Windows NT/2000/XP installer to create and format the new partitions.

You can add Windows NT/2000/XP after Linux, because it is smart enough to not freak out at the sight of your Linux partitions. Windows will overwrite the bootloader, so use the steps outlined above to restore GRUB to the bootloader.

Windows 95/98/ME is much stupider, and requires the use of GRUB's partition hiding to install on a Linux system. This is too complex to go into here, I'll write it up in a future article if there is enough interest. The easy way is to install Windows 95/98/ME first, then Linux.

Windows must be on the first hard disk. It will not boot from a secondary IDE disk, nor from the second primary IDE disk. GRUB will let you map the drives, and fake Windows out into thinking the second drive is the first one, but it's really simpler and better to use the first physical disk.

Booting A RAID Array
If you're running Linux's software RAID, you know that you can use either SCSI or IDE disks. Booting RAID can be a bit tricky, especially when you get people yelling at you about how evil it is to have root filesystems on RAID arrays, and software RAID is evil, and blah blah blah. Here's a simple GRUB trick for booting a two-disk RAID 1 (mirror) array. Install the GRUB boot records on both drives. Configure an identical menu.lst on each drive. Be sure to include the fallback option:

# first entry is the boot default
default 0

# fallback to the second entry
fallback 1

So if the first drive fails, the second one will automatically boot. This is useful for IDE RAID 1, as a quick 'n dirty failover for workstations and low-to-medium duty servers. Sometime down the road we'll do a how-to article on using Linux RAID, and some nifty booting hacks to make sure drives and modules and services load up in the correct order.

Resources
The GRUB Manual