The Linux Page

Quintuple Boot

Basics

How to install your system to be able to boot from any Operating System

Problems

Problems with booting... numerous emails & posts about this one, that's for sure!!! Real solutions? Not really... In many cases people end up reinstalling their system from Scratch and once in a while even that doesn't work! But smart people have a way to fix their boot sectors without too much hurdle (instead of the hours it takes to install an OS.)

Yes! There ought to be a reason for things not to work so well once in while. In most cases, if you only have proper Unix systems (Linux, FreeBSD, HURD, etc.) you will be fine since these systems can be anywhere any time and they usually don't walk on each others feet.

Many people, however, want to be able to use MS-Windows with Linux (dual boot) and if possible multiple versions of Windows on the same drive (triple or quadruple boot!). Not wise! some people say, but I do see a great advantage to that: I don't need to have multiple computers or swap hard drives each time I want to boot on a different system.

Quintuple Boot

My new system will have (once complete 8-P) the following systems: Win98, Win2k, WinXP, FC5, RH9.

RH9 is mainly to test new code on older systems and Win98 is for the kids to play older video games which don't work on Win2k or WinXP (or Linux if that matter... 8-P).

System Partition GRUB info
Windows 98 /dev/hda1
unhide (hd0,0)
unhide (hd0,1)
rootnovefiry (hd0,0)
makeactive
chainloader +1
Windows 2000 /dev/hda2
hide (hd0,0)
unhide (hd0,1)
rootnovefiry (hd0,1)
makeactive
chainloader +1
Windows XP /dev/hda3
hide (hd0,0)
hide (hd0,1)
rootnovefiry (hd0,2)
makeactive
chainloader +1
Fedora Core 5 /dev/hda5
unhide (hd0,0)
unhide (hd0,1)
root (hd0,5)
kernel linuz...
rdinit rdinit...
Red Hat 9 /dev/hda6
unhide (hd0,0)
unhide (hd0,1)
root (hd0,5)
kernel linuz...
rdinit rdinit...
My GRUB Setup

In this table, I show you what I use in my GRUB configuration file (menu.conf, menu.lst or grub.conf). I use hide/unhideto hide partitions since MS-Windows boots on C:, no other drive (well, with WinXP they may have ameliorated that a bit, but don't count on it.) So when you boot on /dev/hda2, it is important that /dev/hda1 is not recognized as a Windows partition of any kind. For this reason, I use hide(hd0,0)when I want to start Win2k (note that GRUB [and HURD] see partitions starting at 0 instead of 1; Linux uses 0 as the number representing the whole device rather than the first partition.)

Once the drives are properly hidden/shown, you are ready to boot from them. You need to specify the root drive with rootor rootnoverify. The former will check the file-system which needs to be a valid Unix file-system (per GRUB at least) or you get a warning. Use rootnoverifyfor MS-Windows partitions so it skips the warning.

Another draw back from MS-Windows, they need to have the boot flag active on the partition you're booting from. In other words, the boot flag needs to change between /dev/hda1, /dev/hda2 and /dev/hda3 as I boot Win98, Win2k and WinXP. For the Linux partitions it is not required and plus these are not primary partitions so it's not useful (the boot flag won't work properly on extended partitions anyway.) The makeactivecommand from GRUB is what you use to make a partition bootable (it automatically clears the boot flag from all the other partitions.)

IMPORTANT: There can be only one partition marked as bootable on any given drive, otherwise your BIOS will not know which partition to boot from (this is not really the case, but that's what BIOSes do: check for the boot flag and its unicity.) The reality is that the BIOS will boot using the boot sector, not the partition boot strap or MBR. Actually for Linux there isn't a need for an MBR. But the BIOSes are for M$-Windowz...

Finally, to load the actual MBR to boot Windows, you use the chainloadercommand. The +<number> represents the number of sectors you need to load. In most cases it will be 1, but a few systems use more sectors.

How it works
Voilà! Ready!

Okay! We're ready to run... but what really happens?! Let's see the list of steps to boot your PC:

  • Connect your PC to the power (he! he!)
  • Push the ON button...
  • The processor wakes up with a cold reset; this means that your processor is in real mode and most of the registers are set to a specific value (this depends on your processor); the two important ones are CS and IP which are loaded with 0xF000 and 0x0000FFF0 respectively, and for more recent processors the base descriptor is set to 0xFFFF0000; this is where your BIOS [E]EPROM is visible and thus this is where everything starts!
  • The BIOS scans and tests your PC hardware and builds a list in RAM
  • The BIOS then tries to boot according to the table you defined in it (for example: start with the floppy, then CDROM, then Hard Disk)
  • Whichever you boot with, the BIOS loads the very first sector at 0x7C00 (for CDROMs, it's sector 17... but you need a complete & correct setup for the booting process to work properly of a CDROM anyway and this page is not about CDROM, at least not yet!). That single sector includes code and the drive partitions information. See below for code samples from Linux and MS-Windows. (If you were wondering why your 1st partition had to start on sector 1 and not 0, now you know why... hmmm... except that the 1st partition really starts on block 0x3F on a hard drive; that's sector 63! More on that later.)
  • Okay! So now you have code at 0x7C00 on 0x200 (or 512) bytes (up to 0x7DFF). In general, it will start with a jump instruction to skip some table to the actual code. I'm not too sure why the Linux version has such a table since it's not used. But anyway, the fact is that this code will issue INT 13 interrupts in order to load other sectors. These will represent other boot programs and/or a kernel.
  • The kernel is started... ha! no, if you have LILO or GRUB actually that tool is started! Cool! Now we can do more, such as say we need to load an MBR to really boot this or that OS. That's what happens when you want to load a MS-Windows kernel. It reads sector 0 of the specified partition (the MBR) at the same address as the boot sector (i.e. 0x7C00) and runs it.

But... but... but... I need a driver to boot windows!!!
Ho, yeah... that's because your BIOS has trouble accessing your hard disk. This is a problem whatever the system except that Linux is likely to understand your hard disk without any extra driver. However, if this is the case, you will need to boot from the beginning of your hard drive (from the first 7.6Gb to 8Gb depending on the support you have in your BIOS.)

What the driver does is take over the 0x13 interrupt. This means it will read the structure you pass to it and convert that in the proper read commands for your hard drive. These can in general be used with any systems, but Linux is not likely to recognize such a driver and it will certainly bypass it. (On the other hand you have options to ask Linux to continue to use the BIOS even after it started its kernel in which case it will use that special driver.)

Okay, now let's move on to the hard code stuff. The actual code in your boot strap and MBRs.

RH9

Booting RedHat 9

At this time I still have a problem with my Red Hat install. I moved it from one drive partition 2 (/dev/hda2) to another driver partition 6 (/dev/hda6). Usually, all you have to do is add "root=/dev/hda6" in the Grub configuration file and up it comes. In this one, it has a problem reading files on the root partition (I assume it is the root partition...) as follow:

attempt to read beyond end of device
03:06: rw=0, want=1219858868, limit=2002491
kernel panic: No init found. Try passing init= to kernel.

Before that, we can see nash in action loading everything it is supposed to load with success. So it looks like the loader tries to load my init file from /dev/hda1 (which is limited to 2Gb) instead of /dev/hda6 (which is 10 times bigger with 20Gb and much further away from the beginning of the drive: the partition roughly falls between 40Gb and 60Gb.)

If you ask folks, most of the time they will answer you saying something like this: your disk got fried. I can see my disk just fine since I can mount it from my Fedora Core 5 and I don't even need an fsck. It is just plainly fine. The main problem is that /dev/hda2 assumption (I assume...). I regenerated the initrd file in case it was written in there and it didn't seem to make any difference either.

Argh! So I looked at the script mkinitrd under Red Hat 9 and tried to rebuild my initrd.img file. This was easy, actually no errors at all (see Booting RAID 1... on that one I checked with Debian and I got plenty of errors). This was nice, so now I can add & remove files from the RAM disk. I put ls and checked out what was going on. ls of /dev shown that everything was fine. Correct /dev/root, /dev/hda and /dev/hdc are present as expected. It still panics though. Then after the mount of /dev/root I looked in /sysroot (what it is being mounted under) and all my files are right there; right name, etc. The init file is there too and ls in the RAM disk can see it just fine. Then the RAM disk exists and the kernel barks these out of range errors and panics. I'm kind of out of ideas right now (probably because it's really late too 8-). The few references to this error on the net say that happens when you specify the wrong file system in your /etc/fstab. I tried to change from ext3 to ext2 and I do get errors, much different and of course it won't boot since in this case it cannot mount the root drive.

Some progress? Now I tried to do the ls right after the pivot_root and that fails. It looks very much like the pivot_root fails really bad. I'll have to look a little closer, but it could be that I need a few more instructions to make it work properly... more later!

RAID

Booting RAID 1

Another booting problem... I have another system which I use to develop under Linux. It had a single hard drive and a CD-ROM. Good enough in most cases, but I really wanted a RAID Level 1. So I decided to use /dev/md[5-10] for my different partitions. It seems that you should be able to boot from any partition, but at this time I get an error:

	md: md driver 0.90.0 MAX_MD_DEVS=256, MD_SB_DISK=27
	Journal Block Device driver loaded
	EXT3-fs:unable to read superblock
	EXT2-fs:unable to read superblock
	cramfs: wrong magic
	pivot_root: no such file or directory
	/sbin/init: 432: cannot open dev/console: no such file
	Kernel panic: Attempted to kill init!

I checked out this one page: Installing Debian with SATA based RAID from Transtronics (after checking many others!) And this one gave me the answer to my problem. What I'm still very much wondering about is: how/when is that initrd.img file regenerated and/or modified?!

I'm wondering because I got the opposite problem: I first have 160Gb x 2 in that system and I switch to a single drive because these 2 hard disks went in another system. Okay! So I had just one drive and I could make it boot (after a few tweaks as described in my pivot_root problem page.) And that changed the initrd.img file with the proper ROOT entry. But when trying to get this new 300Gb x 2 work, it would not! It just was saying that it could not mount the drives (with the errors I just presented; that what that meant and not that the hard disk was bad as some people would most certainly tell you.) Okay... so... here is the result of my research:

  1. Checking out what is inside the initrd.img file
	# cd
	# cp /boot/initrd.img initrd.gz
	# gunzip initrd
	# mount -o ro,loop=/dev/loop1 initrd /mnt/initrd

Notice that since the initrd file is compressed with gzip, you first need to gunzip it (may not be necessary on newer systems!) Also, I very strongly suggest that you make a copy so you have your original in a safe place!

You will of course need to change each parameter to fit your system. loop1 may already be in use, just try loop2, loop3, etc. The filename for you initrd image usually includes the version of the image (i.e. initrd-2.4.20-8.img). The name /mnt/initrd is the name of any folder. Note that I put ro in the options because you cannot really write in the files you see in there... So it's just safer to mount the whole thing read-only.

So? What's that you're looking for in there now?! If you need some special file systems or driver support, you can verify that these are present under /mnt/initrd/lib/modules/<version>/driver/.... Another file of interest is the file named script (/mnt/initrd/script). Do a cat on it, it is only a few lines (3 or 4 or so). The first line defines the ROOT directory. If that is wrong, you're not likely to boot properly. The second line defines all the modules to not load (weird...) The 3rd line is a mdadm command to load the multi-disk support in case you are trying to boot on /dev/md0 or some other md device. If you do not see the proper ROOT and mdadm command, then your RAID will not be loaded properly.

  1. Setting up your new initrd.img file

At least under Debian, you have a directory named /etc/mkinitrd inside which you have a configuration file. It is not extremely important to change it since you can specify most of the options on the command line. Yet, if you are not going to change your system all the time, it's easier to keep the info in one place and thus in that one file. Change the ROOT to /dev/md0 or some other multi-disk. Change the MODULES to dep. Change other variables if it seems that it is required.

  1. Creating a new initrd.img file

There is a command (at least under Debian) to re-generate your initrd file. This is called mkinitrd. Use the -o option to specify the output is an excellent idea to not overwrite another initrd.img file.

	# mkinitrd -o /boot/initrd-md.img

For more info about this command, try man mkinitrdor info mkinitrd. In my current version, I get errors saying that some commands cannot be run because some libraries cannot be loaded (libdl.so, libc.so) for different commands. I suppose they do some chroot in there and these commands just don't run. Somehow this did not prevent the boot from working so I'm fine, but it still feels as if something wasn't 100% complete in there!

WARNING: You need to do a chroot, clean up your /etc/mtab file, mount your /usr if needed (and other partitions, avoid /home for now if possible!) and then run the mkinitrd. This will ensure the proper ROOT and if you are using a RAID it will use the RAID device and thus include the mdadm command as required.
Security Considerations

Security Considerations

Although you cannot access the Linux partitions from MS-Windows without some special software, note that when you boot any one of these system, it can access any other. From Linux, you can actually mount all the drives and thus access all the data from MS-Windows & Linux.

Legally, from MS-Windows you will be limited to the MS-Windows partitions from the boot point. In other words, since we put Win98 first, that system has access to all the other paritions (unless made NTFS, but that will cause Win98 to ask you whether you want to format those partitions!) And now from Win2k, you can not access Win98. This is because the very first hard drive needs to be C:.

Note that what is normally protected while running an Operating System (the Kernel under MS-Windows and the root files under Linux) is not when running another Operating System.

Copying

Copying a partition
(see also Copying a Partition)

There are several ways to copy partitions which enable you or not to grow/reduce an existing partition.

Some people will use the cp command. This works under Linux when you use the right flags (i.e. making sure that devices and FIFOs are copied as special files and not fopen()'ed)

Similar to the cp command, you can use the tar command. This one too knows that how to save a device information in the output file.

A little better to my point of view: the dump + restore commands. These can be used to duplicate an entire partition file by file. Thus you can (like with cp and tar) copy a partition to another when both have different sizes and different file formats. Use a level of 0, and if you have /tmp on a separate partition, just don't copy it and tell dump + restore to use /tmp to save their temporary files. You will get only one error in this case: a warning that lost+found already exists.

Now, if both your source and destination partitions have exactly the same size and exactly the same file format, you should use dd since it is a lot faster. It will read each source sector and write it on the destination as is. (actually, it can be a lot slower, not faster; but it sure copies your drive as is; i.e. it generates a perfect clone). dd will create a destination which is 100% the same and thus you need the exact same number of sectors (or more wasted sectors...) on the destination.

Note that all of these can be used over your network if you have ssh/sshd working (which is pretty much the default on Linux these days.) So, what you can do with dd is copy an entire partition from one computer to another:

	dd if=/dev/hda1 | ssh copy.com 'dd of=/dev/hde1'

This command copies partition hda1 from the source computer to hde1 on the destination computer (which name is copy.com.) Of course, for large partitions, this will take about forever, but it's fun since it goes from one computer to another. blah blah blah... maybe I'm too much of a geek 8-).

Now there is no limit to the copying of partition, is there? 8-) This means next time you want to build a new computer, you can just copy entire partitions from computer A to computer B (say, your /boot and / partitions, then just change the /etc/hosts and other network identifiers, and voila!)

I'm using this technique right now to copy a Win 2k partition from one to another computer. This way I will be able to run Windows from either of my systems. This is neat... we'll see if it works okay (since the hardware will be different, windows may just choke!) Okay, it choked... It says "unrecognized boot device". Looks like it's trying to read from a SATA using a totally standard IDE driver. Or something like that. I may try to install the darn thing instead... it's going to destroy my stage 1 boot loader, unless I copy that first. Hmmm... More later!