Sunday, December 28, 2008

Multi-booting (automatic way) several Ubuntu based distributions

There is a simple way to boot from different ubuntu .iso images saved on the same media, but a manual intervention is needed in order to rename some files before (re)booting.
It is possible to automate it: it's tricky, but it works.

Briefly:
  1. make an usb stick (or hard disk) FreeDOS bootable;
  2. put the .iso images on it;
  3. put the correct pair of kernel and initrd which boots the .isos;
  4. edit (fd)config.sys and autoexec.bat in order to make a menu and a batch that renames some files and boots (using Grub4DOS).

In detail (with the goal of booting the "alternate" distro of kubuntu hardy in either i386 or amd64 flavour):
  1. make your usb device boot any (in principle) OS capable of file manipulation. The plain old DOS is enaugh (and fast to load) but not free. FreeDOS is a good choice and making an usb stick FreeDOS bootable is simple;
  2. make a folder called "hardy" under the root;
  3. download the alternate iso images and put them into the folder "hardy";
  4. rename them "i386-k.iso" and "amd64-k.iso" for short;
  5. under the folder "hardy" make two sub-folders "i386" and "amd64";
  6. download the proper (check here for details) pair of kernel and initrd of each distro and put them into the corresponding folder;
  7. get Grub4DOS and put the dos executable "grub.exe" in the root folder (it will be used to boot the kernel which in turn will run the installer on the .iso image);
  8. make two configuration files for Grub4DOS to load the proper kernels;
    the first "i386-k.lst" (add kernel options as needed):
    default 0
    timeout 1
    title i386
    root (fd0)
    kernel /hardy/i386/vmlinuz root=/dev/ram0 noapic
    initrd /hardy/i386//initrd.gz
    boot

    the second "amd64-k.lst" (add kernel options as needed):
    default 0
    timeout 1
    title amd64
    root (fd0)
    kernel /hardy/amd64/vmlinuz root=/dev/ram0 noapic
    initrd /hardy/amd64/initrd.gz
    boot
  9. in the root folder, make an "fdconfig.sys" file, which acts as menu:
    switches=/F /N
    menudefault=0,30
    menu Kubuntu USB installer
    menu
    menu 0 - Exit to FreeDOS
    menu 1 - Install from kubuntu-8.04.1-alternate-amd64.iso
    menu 2 - Install from kubuntu-8.04.1-alternate-i386.iso
    0?rem
    1?rem
    2?rem
  10. in the root folder, make an "autoexec.bat" file, which manipulates files and invokes the loader:
    rem common preparation
    cd \hardy
    ren *.iso *.isn

    rem select distro
    if "%config%"=="1" ren amd64-k.isn amd64-k.iso
    if "%config%"=="2" ren i386-k.isn i386-k.iso

    rem run distro
    if "%config%"=="1" \grub --config-file=\hardy\amd64-k.lst
    if "%config%"=="2" \grub --config-file=\hardy\i386-k.lst

    cd \

unmount the usb device to be sure all get saved and reboot.