How To Install Lilo on Debian under QEMU
by Mike Levin SEO & Datamaster, 07/27/2010
Okay, as the previous posts pointed out ad nauseam, the result of running debootstrap is not actually a booted system. Because I believe my audience is new to the whole Linux, and perhaps even configuring hardware to boot, I’m going to break it down one step at a time, and follow the proper sequential order of operations. With each instruction now, QEMU should be able to boot a little bit farther.
It’s worth pointing out, since I keep copying-and-pasting this command each time I’m booting this QEMU session to boot off of the Knoppix ISO image, I’m typing:
qemu -hda harddrive.raw -cdrom knoppix.iso -boot d
But the idea is to make it boot without the Knoppix image, so our objective is to get it to boot with the command:
qemu -hda harddrive.raw
This presumes getting harddrive.raw, which contains a boot and a swap partition, totally self-sufficient (requiring only QEMU itself, of course). And for that, we have to start with the boot loader.
There are 2 boot loaders in Linux-land. The first and default is Lilo. The other is Grub. Grub has more features, and is frankly easier to install and configure. But since Lilo is the default, we’re going to go with it.
Remember at this point, we are chroot’ed into our new location. It’s hard to tell if you’re chrooted or not. Just try to keep track of it. If you’re unsure, you can type exit. If your prompt suddenly ends in a dollar-sign ($) instead of a number-sign (#) then you were not chrooted, and you’re back to your unprivileged login, and you will have to sudo su and chroot again. If it stays a number-sign, then you were chrooted, and you just have to re-chroot again.
This is fine, because you’re going to have to get used to chroot’ing into /mnt/sda1 and exiting out several times before we are done. Best to get used to it now.
Once you’re sure you’re chrooted into /mnt/sda1, it’s time to use the aptitude, or apt-get, command for the first time, in order to get the Lilo boot loader. But before getting Lilo itself, you want to make sure that your local copy of Debian release software is up-to-date, so type:
A bunch of stuff will scroll by on your screen. It’s simply updating your local catalog of Debian software that’s available. One of the cool things about Debian is that it tracks all software that’s been compiled and tested to run well, and their dependencies. By installing software through the apt-get system, Debian makes sure you don’t have any missing dependencies or conflicts. Now to install Lilo, simply type:
apt-get install lilo
It will check a bunch of stuff, then prompt you to confirm that you want it installed, saying something like “After this operation, 1913kB of additional disk space will be used. Do you want to continue [Y/n]?” Because we’re on such a bare-bones install, it’s nice to install as little additonal things as possible, so it’s good to take these warnings seriously. For example, we are NOT going to be building this up into a LAMP system with MySQL. Each thing we install now, we do it cautiously, trying to keep the footprint and surface area of our system as small as possible.
Hit Y and [Enter]
It may ask you whether you want to install the packages without verification. Answer yes. The chances are very slim that your system has been hacked already, or that the Debian repositories have been hacked. You will then see this screen:
Now you can go ahead and try to follow the blue screen instructions on running liloconfig, but take my word for it, it won’t work. You have a chicken-and-egg problem, because Lilo needs your kernel information to configure properly. Lilo will detect that you are trying to configure the “base file system”:
I can only assume by this, it knows that it’s missing the kernel, which is critical to configuring Lilo. This is easily remedied, but requires a few words of discussion.
Linux kernels are specifically optimized for particular hardware and usage. There are a ton of choices, and if you would like to see them, you can type (this won’t do anything to your system):
apt-cache search linux-image
A bunch of choices will scroll past you. It’s hard to tell which to use for your QEMU installation. You can’t even stop it from scrolling past you, because the system is so minimal, that we can’t pipe the output to “less”. Fortunately, we’re working off of a Knoppix boot image, which has a good, modern kernel. For the sake of simplicity, we’re going to copy that and its supporting files over to where we’re chrooted. We can always update the kernel later more easily than figuring out the correct one now.
Remember that advice about getting used to exiting from a chrooted location? Well, we have to do it now to have access to the original booted system to perform the copy to put the Linux kernel in place.
So, type exit. You should still have a hash-symbol (#) at the end of your prompt. This means that you are still logged in as root, and un-chrooted from the new location. So what we have to do now is copy your kernel files FROM your Knoppix boot dist TO the location we’re working with using chroot. You should be able to just execute the following commands:
cp /boot/vmlinuz* /mnt/sda1/boot/ cp /boot/System.map* /mnt/sda1/boot/ cp -R /lib/modules/* /mnt/sda1/lib/modules/
…and now we’re ready to configure Lilo…