|
Getting Some GRUB For Linux
Preparation"I was going to go off on a cute riff about "Lilo and Stitch," but after enduring a rant from a friend about how the movie had NOTHING to do with bootloaders, I reckon I'll just stick to the point. Darned over-literal geeks anyway. "If you're still lumbering along with the antique Linux Loader LILO, you really ought to consider migrating to GRUB, the Grand Unified Bootloader. LILO is quite good, and, as the saying goes, if it ain't broke... But GRUB has some advantages that make it, in my opinion, the Bootloader of today's generation. Here's why:
First, you'll need to know a few things about your system:
Make a hard copy of your lilo.conf, it contains information you need. For extra insurance in case things go majorly haywire, backup your existing MBR: # dd if=/dev/hda of=/archive/hda.mbr bs=512 count=1 "The output file (
InstallationFirst, install GRUB. Build from sources, install from packages, I care not, just install it however you choose. So far, you are not fully committed just installing it to your system does not install it to the MBR.
Next, find out where in the heck your particular Linux parked the GRUB boot image files. The official location is Installation From A GRUB FloppyThis is the way to install GRUB to the MBR, and create a boot floppy at the same time. Change to your/grub/$ARCH directory, and copy the stage1 and stage2 boot images to a floppy disk:
# dd if=stage1 of=/dev/fd0 bs=512 count=1 Now reboot to the floppy disk. You should be greeted by the nice blue GRUB screen: GRUB version 0.93 (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> First, find the location of the boot files: grub> find /boot/grub/stage1 Now set the root device:
grub> root (hd0,0) A Digression Into Partition NumberingGRUB uses its own unique partition numbering scheme; it starts from 0.hd0,0 means the first partition of the first drive, or hda1. Both SCSI and IDE drives are represented by hd. GRUB numbers sequentially, from zero:
hda2 hd0,1 But that's not all. Remember, the standard Linux partition table is like this:
1-4 primary partitions In GRUB, it's like this:
0-3 primary partitions Additional drives are hd1, hd2, etc.
Completing the InstallationNow install GRUB to the MBR. This is the point of no return. Well, not really, because you can always restore the MBR from your backup. Isn't Linux cool? grub> setup (hd0) This installs it to the first sector of the first drive. Now we must finish booting. If you already know the location of your kernel, now is the time to use it: grub> root (hd0,0)
Let's dissect the kernel line, as it is a source of confusion and woe for GRUB newbies.
Then type the boot command, and away you go.
The Dog Ate lilo.confYou can discover the kernel and root information from the GRUB command line, with tab-completion. Typegrub> root (hd0, and hit the tab key. Stuff will appear: Possible partitions are: Well, which one is it? It's trivial to try both. Type grub> root (hd0,1) Then search for the kernel image, type: grub> kernel /boot/vmlinuz root=/dev/hda1 ro and hit the tab key. If there is no /boot directory, GRUB will tell you: Error 15: File not found So, just do it over: grub> root (hd0,0) Type: grub> kernel /boot/vmlinuz-2.4.21 and away you go. Weirdo Kernel Namesvmlinuz is the traditional name for Linux kernels, but they can be named anything at all- fred, kernel-mustard, my-frikken-kewl-kernel, anything at all. To be sure of catching all possible kernels in /boot, widen your search:
grub> kernel /boot/
and hit the tab key. This will list all the files in Making The Changes PermanentYou probably don't want to do this every time you boot up, so find your GRUB configuration file, and make all this stuff happen automatically. In Debian,/boot/grub/menu.lst. In Red Hat, /boot/grub/grub.conf. Our entry looks like this:
title Libranet GNU/Linux, kernel 2.4.21 The title is anything you want. But What About LILO?You can leave LILO on your system, or remove it, as you like. GRUB owns the MBR now, so LILO is in retirement. Later in this article you'll learn how to restore LILO, should you wish.
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
title Libranet GNU/Linux, kernel 2.4.21
The root device is the location of the boot images: stage1 and stage2, the kernel, and other boot files. These are in the
These are most commonly on the same filesystem. However, they do not have to be you can have your Installing GRUB Without A Floppy DiskAn 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 Now run these three commands: grub> root (hd0,0) 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 CDHaving 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.
Easily Restoring LILODon't uninstall LILO leave it intact, including # /sbin/lilo -v Multi-bootingGRUB 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
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 Multi-booting WindowsGRUB 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 ArrayIf 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 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. Words to Live by"Thus far, you have been adrift in the sheltered harbor of my patience." From Lilo & Stitch, to show it's worth watching, even though it has no bootloaders. [Editor's Note: This article originally appeared on CrossNodes, a JupiterWeb site. -BKP]
|