####[ How-Do-I Documents ]################################### Sub : Loadlin Boots HDI #001 How-Do-I enable a multi-boot system where my M$-Win is on the first partition and I have Linux on the other, below the 1024 cylinder limit of LILO ? ############################################################# Contents: 1. What is Loadlin 2. Where to get Loadlin 3. Why use Loadlin 4. Various options for booting Linux 5. How Loadlin works 6. How do you go about using loadlin o Down-loading loadlin o Copying kernel to M$ partition 7. Subsequent M$ TO-DOs 8. Loadlin and MS-DOS 9. How to make a Loadlin boot disk 10. Some other handy utilities 11. Appendices a) Sample msdos.sys b) Sample config.sys c) Sample autoexec.bat 12. Kudos and brickbats ############################################################### 1. What is Loadlin 1.1 This is a boot loader for Linux that runs under MSDOS. It can boot Linux from a DOS prompt or CONFIG.SYS, and fully supports the command line feature of the Linux kernel. This also supports bzImage+initrd, i.e it can load directly 'high' and can load the ramdisk. The DOS program was originally written by Hans Lerman. Later versions were jointly developed along with Werner Almesberger (author of LILO). 1.2 Loadlin is a boot loader for Linux. It operates from a DOS partition (or a DOS formatted diskette).LOADLIN is an utility which starts a "logical reload" of your machine, causing DOS to be completely overlaid with Linux. When you wish to return to DOS you must use the Linux "reboot" command, since DOS is no longer active. 1.2 Loadlin is written completely in TASM (3.0) and there- fore a x86 DOS binary. LOADLIN is highly adaptable to different DOS configurations, and now has very few loading restrictions. It makes use of extended memory and can load big kernels and ramdisk images directly. It is also capable of booting a UMSDOS-based system from a DOS drive. 2 Where to get Loadlin 2.1 Normally Loadlin comes with the distribution diskettes of nearly all distros ... If not, down-load it from : ftp://elserv.ffm.fgan.de/pub/linux/loadlin-1.6/ 3 Why use loadlin 3.1 There are several reasons. The default boot loader for Linux is LILO (Linux Loader). The older versions had a few limitations: a) Inability to load from UMSDOS systems b) The "1024-voodoo" ... explained below c) Inability to load multiple operating systems on the same box e.g. Win+Linux+QNX+BeOS 3.2 All these limitations are overcome by Loadlin. There is also an added advantage, in that, since the Master Boot Record (MBR) is MSDOS/ Windows, there are no problems with some virus scanners which frown at the altered MBR (boot sector). 3.3 The 1024-voodoo 3.3.1 The Master Boot Record (MBR) contains a tiny program which has just enough information and code to load ano- ther program placed somewhere else on your hard disk to continue the booting process. The MBR does not have the space to store much code (< 512 bytes). LILO depends on the BIOS API to read from hard disk. With older BIOSes the hard disk geometry is defined in C/H/S (Cylinder/ Head/Sector) format which can go upto a maximum of 1024 cylinders. LILO therefore failed if the root partition was located beyond 1024 cylinders ... 1024-voodoo ! 3.3.2 This limitation has been circumvented in newer LILOs (ver 21.4 and beyond), provided you have a newer BIOS providing disk geometry in Linear Block Addressing form (LBA). 3.4 The M$ problem 3.4.1 All M$ OSs always occupy the MBR by default. There is absolutely no compromise on this issue. If you put LILO on the MBR, control actually passes over to Linux which if located above the first 1024 cylinders, fails to do a successful boot. 4. Various options for booting Linux 4.1 Since there are problems with the default Linux loader (LILO) in certain situations alternatives available are a) Repartition hard disk in such a way to keep the root partition within the 1024 cylinder limit, use LILO.. This may not be a viable option if there is a lot of data already installed on the Win/ DOS partition. b) Boot into MSDOS/ Win and use a DOS program to boot into Linux (e.g. Loadlin) c) Use independent boot managers like partition magic. All these boot loaders normally run from a primary partition where the executables and data are kept. Since an IDE hard drive can have a max of 4 primary partitions, you effectively lose one Primary parti- tion (and one less OS can be installed). 5 How Loadlin works. 5.1 The normal boot process of booting on an x86 platform is as follows: 5.1.1 On initial power up, control is passed on to the BIOS which checks configuration as saved in the CMOS, does a probe of all hardware interfaces, and then reads the MBR of the selected device (be it Hard disk, floppy or the CDROM). 5.1.2 The code on the MBR directs control to another booting program, which in M$ systems are 2 hidden/ system files (io.sys and msdos.sys), followed by loading of command interpreter command.com. After this configuration pref- erences are loaded from config.sys, and programs to be run at boot through autoexec.bat. 5.1.3 In this sequence the first level from where control can be transferred is [config.sys], and subsequently, from [autoexec.bat]. If Linux kernel is booted from autoexec some amount of memory would be taken up by the programs initiated from config.sys. Requirement to remove these programs from memory therefore arise. 5.1.4 For Loadlin boots, the Linux kernel must be kept within the M$ partition (not Linux /boot). The kernel itself should be correctly pointed to the "/" partition where Linux is installed. All that Loadlin does is to load the kernel, which once loaded, can access all the ext2 partitions of your installation. The Linux init process then commences normally as in LILO. 6 How do you go about using loadlin 6.1 Loadlin can successfully operate from any DOS or Win-9x boot. The development of Loadlin ceased in 97-98, and Win32 was the last thing added. There is no intrinsic support for Win-NT or other M$ OSs like Win-2k, ME etc. released subsequently. 6.2 Conceptually, being a pure Win-32 executable, it should be operable on any system where config.sys or autoexec. bat can be trapped. However I have not personally tried it, and therefore, the rest of the methods described pertain to MSDOS and Win-9x. 6.3 Down-loading Loadlin. 6.3.1 Loadlin comes as a zipped file. It can be downloaded or copied to the M$ partition, and unzipped with any of the unzipping tools (e.g. pkzip, winzip etc). There is only one program of importance loadlin.exe, the others are documentation, program source etc. 6.3.2 Make an independent directory in your M$ partition: C:>mkdir C:\loadlin Copy loadlin.exe to it ( optionally documentation can also be copied there). Read all the doc files ... 6.4 Transferring kernel (vmlinuz) to M$ partition 6.4.1 As stated in Para 5.1.4, the kernel also needs to be kept in the same directory ... only that at this stage there is no kernel image available, unless you have already installed Linux, and have made a boot disk. 6.4.2 If you have made a boot disk already, and have Linux already installed, to run from (say /dev/hda2), the kernel image should already be pointed correctly. It is, however, safer to check. 6.4.3 If you have not installed Linux, nor have a boot disk, there is no go ... you have to install Linux first. On a pre-existing M$/ Win-9x box, first step is to ensure you have a M$/ Win boot floppy at hand so that you can do a fdisk /mbr to get back into M$/Win. At this stage go and install Linux using the installation method for your distro. At the end of it all LILO needs to be put in place ... DO NOT put LILO on the MBR. Just place it on the boot sector of your "/" (root) partition .. AND ensure you make a boot disk. Once this is done, exit. At this stage, you will be able to boot into M$/ Win9x through hard disk, and into Linux with boot disk only. The situation is good enough. 6.4.4 To copy your kernel (vmlinuz) to M$ partition you have to go through Linux. M$/ Win cannot access ext2 parti- tions. After booting, step [#1] is to identify kernel image. In most distros this is kept in /boot. ( Note : the kernel image may have a name of vmlinuz, zimage or bzImage ) #cd /boot #ls -al vmlinuz* 6.4.4.1 For each of these do: #file vmlinuz.. (whatever) 6.4.4.2 One of these will show "Linux kernel x86 boot execut- able". This is the file to be copied. 6.4.4.3 Next step is to see that this is correctly pointed to your "/" (root) device. #rdev vmlinuz 6.4.4.4 You will get a response like /dev/hda2. If this is okay leave it alone, otherwise change it for your "/": #rdev vmlinuz /dev/hda3 (or wherever your "/" lies) 6.4.4.5 Now you are assured that the kernel has been identified and that it is correctly pointed. Next step is to mount the M$ partition. You need a mount point for that. For many distros a default /mnt is created at installation. Otherwise you need to create a mount point: #mkdir /mnt 6.4.4.6 Next mount the partition #mount -t msdos /dev/hda1 /mnt (assuming that /dev/hda1 is your M$ partition. Note:the partition is being loaded as msdos and NOT vfat. This is because, in most stock kernels of nearly all distros msdos support in statically compiled, whereas vfat is not. vfat support needs to be compiled or loaded as a module for long filenames to work). 6.4.4.7 If you do a "ls /mnt" you should be able to see the directory structure of M$ partition with all file names truncated to 8.3 since you mounted it a M$. No harm ... Now copy the kernel. Kernels may have name which is not in the 8.3 format. Ensure that the filename written to the M$ directory follows the 8.3 convention. E.g.: #cp /boot/kernel-2.2.16 /mnt/loadlin/vmlinuz 6.4.4.8 That is about all there is to it. Your kernel image has been copied to C:\loadlin\vmlinuz. 6.4.5 Once this is done .. exit from Linux. The rest of it is to be done from M$/ Win. 7 Subsequent M$ TO-DOs 7.1 The test floppy 7.1.1 There is no magic here. The secret is in Win-9x rescue disks. You notice that in Win-9x rescue disks you get a menu on boot? That is because in Win9x, the hidden file msdos.sys is an ASCII file! Make a spare Win-9x rescue/ boot disk and play around on that first. C:\> attrib -h -s -r a:\msdos.sys C:\> copy msdos.sys msdos1.sys C:\> attrib +h +s +r a:\msdos.sys [Read msdos1.sys well ... there are no changes needed. You will see that MultiBoot has been enabled] 7.1.2 What a valid Win-98 looks like is pasted at Appendix "A" 7.1.3 Make a Win-9x boot disk first, and play around with that If things work ... venture to hard disk. o format a: /s /v .... bootable floppy o copy /path/of/vmlinuz a: o copy /path/of/loadlin.exe a: o make a one line config.sys shell=a:\loadlin.exe a:\vmlinuz root=/dev/hda2 ro (change "root=" to the path your Linux is installed) 7.1.4 Can you boot Linux ? If yes, then proceed to make this disk multi-boot. 7.2 Making new boot floppy to multi-boot 7.2.1 Copy msdos1.sys (from the one which you changed attrib) to this disk. o ren msdos1.sys msdos.sys o attrib +h +r +s msdos.sys 7.2.2 Make a config.sys with only two options ... plain Win98 and Linux. ------------<Sample config.sys for boot disk>----------- [menu] menuitem=Menu1, Win-98 menuitem=Menu2, Linux menudefault=Menu1,15 menucolor=15,1 [Menu1] REM Default into Win-98 DOS mode DEVICE=C:\windows\HIMEM.SYS /testmem:off DEVICEHIGH=C:\windows\EMM386.EXE NOEMS dos=HIGH,UMB stacks=9,256 buffers=32,0 files=32 FCBS=4,0 [Menu2] REM Load Linux through Config.sys shell=a:\loadlin.exe a:\vmlinuz root=/dev/hda2 ro ---------------</End of Config.sys>--------------------- 7.2.3 There may not be enough space on this disk for all the files needed by Win ... so no need for putting autoexec or putting additional drivers except for HIMEM.SYS and EMM386.EXE on the floppy ... after all, this is for test only. 7.2.4 Boot from this floppy. You will notice a menu of Win-98 and Linux on a blue screen. Select with arrow keys and press [Return] to confirm. 7.2.5 This will give the confidence to play around more. When you are cock sure ... take the plunge, and make changes to your hard disk set up. 7.3 Setting it on your hard disk 7.3.1 DO NOT DELETE old Win9x Configuration files. Just rename them to msdos.000, config.000 and autoexec.000. In case of trouble, boot through Win rescue disk and rename the .000 files. You would have to change attributes of msdos.sys of-course before renaming! 7.3.1 Copy the msdos.sys file from the working a: boot disk to c: ... the procedure is the same as above. o C:\> attrib -r -h -s a:\msdos.sys o C:\> copy a:\msdos.sys C:\ o attrib +r +h +s C:\msdos.sys 7.3.2 Write a config.sys for C: with all the parameters you normally use for your Win-9x system. I am placing below a config.sys with 2 Linuxes, Win-98 and DOS. The "pygmy" linux is just to show how an UMSDOS installation is done for a full installation on a M$ partition at /dev/hda1. 7.3.3 I am also placing an autoexec.bat below (Appendix "C"). Note how each segment calls a separate batch file. It is easier to maintain and errors in one do not cascade over to other batch processes. 7.3.4 I am also placing a linux.bat file (Appendix-"D") which has been commented enough for your discomfort ;-) I am assuming that you need no assistance in writing batch files for Win and DOS ... 8 Loadlin and MS-DOS 8.1 Unlike in Win-9x, msdos.sys is NOT an ASCII file. There is no scope of menu through config.sys, so loading has to be through autoexec.bat only. This applies for all versions of MS-DOS (ver 6.22 and below), DR DOS and all other types of DOS. 8.2 There is a need to flush all unwritten buffers before loadlin is called: smartdrv /C 8.2.1 Reduce the number of devices installed through config. sys. When loadlin loads the kernel it automatically clears them all, but more time is taken. 8.3 For MS-DOS loadlin boots the changes from Win-9x are: o no tinkering with msdos.sys (you cannot, binary file) o no tinkering with config.sys o only loading through autoexec.bat 9 How to make a Loadlin boot disk 9.1 The simplest method of making a boot disk is through loadlin. Totally a MS-DOS (or DOS prompt) job: o format a: /s /v o copy c:\loadlin\loadlin.exe a: o copy c:\loadlin\vmlinuz a: o write a one line config.sys: --- shell=a:\loadlin.exe a:\vmlinuz root=/dev/hda2 ro REM (change "root=" to the path your Linux is installed) --- 9.2 Note, if you have loadlin installed, and you use it for booting purposes, there is absolutely no need for LILO or having anything in /boot. However, it is not a bad idea keeping /boot and LILO, in case you want to switch at a later date, or want to make a LILO based boot disk Note: Programs like mkbootdisk need LILO ... 9.3 FYI, there is also a shell script written by me for the making of LILO boot floppies available for download at: http://oocities.com/usmbish/mbf-0.3.tar.gz 9.3.1 I don't want to write a batch file about making loadlin boot disks ... the process is too simple ... 10 Some other handy utilities 10.1 Winux is a graphical configuration interface for Loadlin bootloader. Once installed, it can also be used to fire Linux from within Windows. This is a program written in Delphi by Herve Utard, and is available under GPL from: http://www.linux-france.org/prj/winux/English/Downloads.html 10.1.1 For this program to operate the kernel images would have to be copied from the ext2 partition to the Windows par- tition, by the method described earlier. 10.1.2 This program essentially creates a winux.conf file of the Linux installations on your system, and can be fired from your Windows desktop. The program clears all memory before handing control to Linux. 10.1.3 In the method described by me earlier, we are going over into Linux at the config.sys stage itself, so there is no need to go into Windows at all. However, if you are new to the game, and more comfortable from the Windows screen, this is another option. 10.2 explore2fs : This is a must-have if you want to read (or write to) ext2 partitions from Windows. The write option as on date of this HDI was still experimental. This is a program written in Delphi, by John Newbegin and is GPLed It is available for download from: http://uranus.it.swin.edu.au/~jn/linux/explore2fs.htm 10.2.1 WARNING: The write support is still experimental. There are chances of damaging your file system... It is better avoiding write to ext2 partitions at this stage. Default "read only" support is safe for unrestricted use ... and can be used for jobs like copying the kernel image from your ext2 partition to M$ partition. ############################################################## 11 Appendices ############################################################## Appendix - "A" ---------------[ MSDOS.SYS ]---------------------------- [Paths] WinDir=C:\WINDOWS WinBootDir=C:\WINDOWS HostWinBootDrv=C [Options] BootMulti=1 BootGUI=1 DoubleBuffer=1 AutoScan=1 WinVer=4.10.2222 ; ;The following lines are required for compatibility with other programs. ;Do not remove them (MSDOS.SYS needs to be >1024 bytes). ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxc ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxd ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxg ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxh ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxj ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxk ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxl ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxm ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxn ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxo ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxp ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxq ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxs ####################################################################### Appendix - "B" ----------------[ CONFIG.SYS ]---------------------- [menu] menuitem=Menu1, DOS Prompt (Win-98) menuitem=Menu2, Slakware (Ver 7.1) menuitem=Menu3, Pygmy Linux menuitem=Menu4, Windows 98 Normal menudefault=Menu1,15 menucolor=15,1 [Menu1] REM Default into Win-98 DOS mode REM Enable xms thru himem.sys (640-1024k) DEVICE=C:\windows\HIMEM.SYS /testmem:off REM Enable memory beyond 1 mb DEVICEHIGH=C:\windows\EMM386.EXE NOEMS REM Load DOS High in memory dos=HIGH,UMB REM CD-ROM Driver primer DEVICEHIGH /L:1,40800 =C:\WINDOWS\OAKCDROM.SYS /D:MSCD001 REM Enable Compressed drive r & w DEVICEHIGH=C:\WINDOWS\COMMAND\DRVSPACE.SYS /MOVE REM Requirements of Win/ DOS software stacks=9,256 buffers=32,0 files=32 FCBS=4,0 [Menu2] REM Load Linux through Config.sys rem It is possible to boot Linux from here as shown below rem shell=c:\loadlin\loadlin.exe @C:\loadlin\linuxpar.1 rem ---------------------------------------------------- REM If the line below is commented, then we can load Linux REM through AUTOEXEC.BAT but that option at times fails to REM operate successfully shell=c:\loadlin\loadlin.exe c:\loadlin\vmlinuz.slk root=/dev/hda2 ro [Menu3] REM Load Pygmy Linux through Config.sys rem ---------------------------------------------------- REM Note attribute has to be ro for ext2 and rw for umsdos REM ------------------------------------------------------ shell=c:\loadlin\loadlin.exe c:\loadlin\vmlinuz.pyg root=/dev/hda1 rw [Menu4] REM Load Windows-98 Normal, Same as DOS except that REM CDROM driver NOT needed DEVICE=C:\DOS\HIMEM.SYS DEVICE=C:\DOS\EMM386.EXE NOEMS DOS=HIGH, UMB DEVICEHIGH=C:\WINDOWS\COMMAND\DRVSPACE.SYS /MOVE DEVICEHIGH=C:\WINDOWS\setver.exe buffers=32,0 files=32 dos=UMB FCBS=4,0 ################################################################ Appendix -"C" -------------[ Autoexec.BAT ] ---------------------- @IF ERRORLEVEL 1 PAUSE @ECHO OFF IF "%config%"=="Menu1" GOTO Menu1-BAT IF "%config%"=="Menu2" GOTO Menu2-BAT IF "%config%"=="Menu3" GOTO Menu3-BAT IF "%config%"=="Menu4" GOTO Menu4-BAT :Menu4-BAT REM This is in reverse order, with default last REM This is for Windows-98 (item 4 on menu) REM Control being passed to external program command c:\command.com /k c:\util\Win98.bat :Menu3-BAT REM Load Linux (Pygmy) from UMSDOS partition command c:\command.com /k c:\util\pygmy.bat :Menu2-BAT REM Load Linux (Slackware) from /dev/hda2 command c:\command.com /k c:\util\linux.bat :Menu1-BAT REM This is exactly same as Windows except for necessity for REM loading mouse and CDROM device drivers command c:\command.com /k c:\util\dos7.bat ############################################################### Appendix - "D" ---------------[ c:\util\linux.bat ]---------------- @ECHO OFF rem This loads Slackware Linux 7.1 from /dev/hda2 rem Loadlin <kernel_image> root=<root device> ro|rw rem If on UMSDOS then "ro" should be changed to "rw" rem Other information may need to be passed to the rem kernel through Loadlin docs rem C:\loadlin\LOADLIN.EXE C:\loadlin\vmlinuz.slk root=/dev/hda2 ro ------------------------</end>--------------------- ################################################################ 12 Kudos and Brickbats 12.1 This document is released under GNU/ GPL license. You are free to use and distribute this without any encumbrances. 12.2 Any kudos and brickbats should be directed at: USM Bish <bish@nde.vsnl.net.in> 20 Sep 2001