Creating multiboot HDD in linux (GRUB2 + memdisk + grub4dos)
Creating multiboot HDD in linux (GRUB2 + memdisk + grub4dos)
At some certain moment I was tired of carrying around a dozen bootable flash drives with me. And I created myself a multiboot usb hdd.
We will need:
- Installed linux with grub2
- memdisk from syslinux
- grub.exe from grub4dos
- Plop boot manager
- firadisk
This method should work for flash drives, but testing has not been conducted.
Addition described:
- Hiren's boot cd
- Dr.Web Live CD
- Debian Netinstall
- Ultimate boot cd
- SystemRescue CD
- Clonezilla cd
- Memtest cd
- Ubuntu Live CD
- Lubuntu Live CD
- Windows XP CD
Disk preparation
First of all, it is worth breaking the future bootable hard disk into several partitions. I decided to divide into two sections: one boot, the second for various files.
After changing the partition table, all data that is on the disk will be lost at the moment!
Create Partitions
#fdisk /dev/sdX
Create an empty partition table.Command (m for help): o
Create a section for multiboot.Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-XXXXXXXXX, default 2048):
Last sector, +sectors or +size{K,M,G} (2048-XXXXXXXXX, default XXXXXXXXX): +32G
Create a section for the data.Command (m for help): n
Select (default p): p
Partition number (1-4, default 2): 2
First sector (67110912-XXXXXXXXX, default 67110912):
Last sector, +sectors or +size{K,M,G} (67110912-XXXXXXXXX, default XXXXXXXXX):
Mark the first partition as bootable and write the changes to disk:Command (m for help): a
Partition number (1-4): 1
Command (m for help): w
File system creation
Create file systems:
- on the section for multiboot: FAT32
- on the data section: NTFS
#mkfs.vfat -n boot /dev/sdX1
#mkfs.ntfs -f -L data /dev/sdX2
Install bootloaders
We will mount the partition for multiboot and install grub2 on it.
#mount /dev/sdX1 /mnt
#grub-install --no-floppy --root-directory=/mnt /dev/sdX
We will extract the file “memdisk / memdisk” from the archive with syslinux, from the archive with grub4dos the file “grub.exe”, from the archive with Plop the file “plpbt.bin”, from the archive with firadisk the file “firadisk.img”.$unzip -j -d /mnt/boot/ syslinux-X.X.zip memdisk/memdisk
$unzip -j -d /mnt/ grub4dos-X.X.X.zip grub4dos-X.X.X/grub.exe
$unzip -j -d /mnt/ grub4dos-X.X.X.zip grub4dos-X.X.X/grldr
$unzip -j -d /mnt/boot/ plpbt-X.X.X.zip plpbt-X.X.X/plpbt.bin
$7z x -o/mnt/boot/ firadisk-driver-0.0.1.30-f6.7z
Image preparation
Create a directory for iso files. Copy the files for Ultimate Boot CD, SystemRescue CD, Clonezilla CD (clz16.iso - version i486, clz32.iso - version i686pae, clz64.iso - version amd64), Memtest CD, Debian Netinstall, Ubuntu, Lubuntu, Windows XP .
$mkdir /mnt/iso
$cp ./iso/{clz16.iso,clz32.iso,clz64.iso,ubcd.iso,sysr.iso,memtest.iso,debian32.iso,debian64.iso,ubuntu32.iso,ubuntu64.iso,lbuntu32.iso,lbuntu64.iso,xp.iso} /mnt/iso/
Hiren's boot cd
Unpack the "HBCD" directory from the iso file. After that, extract the file “grub.exe” to the root of the partition for multiboot.
$7z x ./iso/hiren.iso -o/mnt/ -ir\!HBCD
Dr.Web Live CD
Unpack the “boot” directory from the iso file into a temporary directory and move its contents to the “boot” directory on the multiboot partition.
$mkdir /mnt/drweb
$7z x ./iso/drweb.iso -o/tmp -ir\!boot
$mv /tmp/boot/* /mnt/boot/
We also recognize BOOT_ID.$cat /mnt/drweb/config|grep BOOT_ID
export BOOT_ID=xxxxxxxxxxxxxxxxxxxx
Create the configuration file "/mnt/boot/drweb.lst" for grub4dos and add the following contents to it:title 1. Dr.Web Russian
kernel /boot/vmlinuz ID=<Тут вставить BOOT_ID> root=/dev/ram0 init=/linuxrc init_opts=4 vga=791 splash=silent,theme:drweb CONSOLE=/dev/tty1 BOOT_LANG=ru_RU.UTF-8 quiet
initrd /boot/initrd
title 2. Dr.Web Advanced options
kernel /boot/vmlinuz ID=<Тут вставить BOOT_ID> root=/dev/ram0 init=/linuxrc init_opts=3 CONSOLE=/dev/tty1
Debian Netinstall
Create the directories for the debian installers and download the “initrd.gz” and “vmlinuz” files for downloading from hd-media for the respective architectures.
$mkdir /mnt/debian
$mkdir /mnt/debian/{amd64,i386}
$wget -cO /mnt/debian/i386/initrd.gz http://ftp.nl.debian.org/debian/dists/wheezy/main/installer-i386/current/images/hd-media/initrd.gz
$wget -cO /mnt/debian/i386/initrd.gz http://ftp.nl.debian.org/debian/dists/wheezy/main/installer-i386/current/images/hd-media/vmlinuz
$wget -cO /mnt/debian/amd64/initrd.gz http://ftp.nl.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/hd-media/initrd.gz
$wget -cO /mnt/debian/amd64/initrd.gz http://ftp.nl.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/hd-media/vmlinuz
Ultimate boot cd
Create the configuration file "/mnt/boot/ubcd.lst" for grub4dos and add the following contents to it:
title Ultimate Boot CD
map (hd0,0)/iso/ubcd.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)
Windows XP CD
Create the configuration file "/mnt/boot/win.lst" for grub4dos and add the following contents to it:
title 1. Windows XP (1st)
map --mem /boot/firadisk.img (fd0)
map --mem /iso/xp.iso (hd32)
map --hook
chainloader (hd32)
title 2. Windows XP (2nd)
map --mem /boot/firadisk.img (fd0)
map --mem /iso/xp.iso (hd32)
map --hook
find --set-root --ignore-floppies --ignore-cd /ntldr
map () (hd0)
map (hd0) ()
map --rehook
find --set-root --ignore-floppies --ignore-cd /ntldr
chainloader /ntldr
Configuration file for GRUB2
/mnt/boot/grub/grub.cfg
have_grubenv = true
load_env
insmod part_msdos
insmod fat
set gfxmode = 640x480
set locale_dir = / boot / grub / locale
set lang = ru_RU
set menu_color_highlight = yellow / dark-gray
set menu_color_normal = black / light-gray
set color_normal = yellow / black
submenu "1 . AVP "{
menuentry" 1. Dr.Web "{
linux /grub.exe --config-file = / boot / drweb.lst
}
}
submenu" 2. Boot cd "{
menuentry" 1. Hiren's boot cd "{
linux /grub.exe --config-file = / HBCD / menu.lst
}
menuentry" 2. Ultimate Boot CD "{
linux /grub.exe --config-file = / boot / ubcd.lst
}
menuentry" 3. SystemRescue CD (i586) »{
set isofile = "/ iso / sysr.iso"
loopback loop $ isofile
linux (loop) / isolinux / rescue32 setkmap = ru isoloop = $ isofile
initrd (loop) /isolinux/initram.igz
}
menuentry "4. SystemRescue CD (amd64) »{
set isofile =" / iso / sysr.iso "
loopback loop $ isofile
linux (loop) / isolinux / rescue64 setkmap = ru isoloop = $ isofile
initrd (loop) /isolinux/initram.igz
}
menuentry" 5. Clonezilla (i468) »{
set isofile =" / iso / clz16.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \ "ocs-live-general \" ocs_live_extra_param = \ "\" ocs_live_keymap = \ "\" ocs_live_batch = \ "no \" ocs_lang = \ "\" vga = 788 ip = frommedia nosplash noeject toram = filesystem.squashfs findiso = $ isofile
initrd (loop) /live/initrd.img
}
menuentry "6. Clonezilla (i686pae) »{
set isofile =" / iso / clz32.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \" ocs-live-general \ "Ocs_live_extra_param = \" \ "ocs_live_keymap = \" \ "ocs_live_batch = \" no \ "ocs_lang = \" \ "vga = 788 ip = frommedia nosplash noeject toram = filesystem.
menuentry "7. Clonezilla (amd64) »{
set isofile =" / iso / clz64.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \" ocs-live-general \ "Ocs_live_extra_param = \" \ "ocs_live_keymap = \" \ "ocs_live_batch = \" no \ "ocs_lang = \" \ "vga = 788 ip = frommedia nosplash noeject toram = filesystem.squashfs findiso = $ isofile
initrd (loop) / live /initrd.img
}
}
submenu "3. Parted Magic "{
menuentry" 1. Parted Magic RAM (i586) »{
set isofile =" / iso / pmagic.iso "
initrd (loop) /pmagic/initrd.img
}
menuentry "2. Parted Magic RAM (amd64) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage64 iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
menuentry "3. Parted Magic Live (i586) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 livemedia noeject max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
menuentry "4. Parted Magic Live (amd64) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage64 iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 livemedia noeject max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
}
submenu "4. Debian "{
menuentry" 1. Debian netinstall (i368) "{
linux / debian / i386 / vmlinuz priority = low vga = 788 - initrd /debian/i386/initrd.gz
}
menuentry" 2. Debian netinstall (amd64) "{
linux / debian / amd64 / vmlinuz priority = low vga = 788 - initrd /debian/amd64/initrd.gz
}
}
submenu" 5. Ubuntu »{
menuentry "1. Ubuntu live (i386) »{
set isofile =" / iso / ubuntu32.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
menuentry "2. Ubuntu live (amd64) »{
set isofile =" / iso / ubuntu64.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
}
submenu "6. Lubuntu "{
menuentry" 1. Lubuntu live (i386) »{
set isofile =" / iso / lbuntu32.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console-setup / layoutcode = ru noeject noprompt - initrd (loop) /casper/initrd.lz
}
menuentry "2 . Lubuntu live (amd64) »{
set isofile =" / iso / lbuntu64.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
}
menuentry "7. Windows "{
linux /grub.exe --config-file = / boot / win.lst
}
submenu" 8. Tools "{
menuentry" 1. Memtest »{
set isofile =" / iso / memtest.iso "
linux16 / boot / memdisk iso
initrd16 $ isofile
}
menuentry "2. Plop Boot Manager »{
linux16 /boot/plpbt.bin
}
}
menuentry" 9. First hdd "{
insmod ext2
insmod ntfs
set root = (hd1)
chainload + 1
}
load_env
insmod part_msdos
insmod fat
set gfxmode = 640x480
set locale_dir = / boot / grub / locale
set lang = ru_RU
set menu_color_highlight = yellow / dark-gray
set menu_color_normal = black / light-gray
set color_normal = yellow / black
submenu "1 . AVP "{
menuentry" 1. Dr.Web "{
linux /grub.exe --config-file = / boot / drweb.lst
}
}
submenu" 2. Boot cd "{
menuentry" 1. Hiren's boot cd "{
linux /grub.exe --config-file = / HBCD / menu.lst
}
menuentry" 2. Ultimate Boot CD "{
linux /grub.exe --config-file = / boot / ubcd.lst
}
menuentry" 3. SystemRescue CD (i586) »{
set isofile = "/ iso / sysr.iso"
loopback loop $ isofile
linux (loop) / isolinux / rescue32 setkmap = ru isoloop = $ isofile
initrd (loop) /isolinux/initram.igz
}
menuentry "4. SystemRescue CD (amd64) »{
set isofile =" / iso / sysr.iso "
loopback loop $ isofile
linux (loop) / isolinux / rescue64 setkmap = ru isoloop = $ isofile
initrd (loop) /isolinux/initram.igz
}
menuentry" 5. Clonezilla (i468) »{
set isofile =" / iso / clz16.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \ "ocs-live-general \" ocs_live_extra_param = \ "\" ocs_live_keymap = \ "\" ocs_live_batch = \ "no \" ocs_lang = \ "\" vga = 788 ip = frommedia nosplash noeject toram = filesystem.squashfs findiso = $ isofile
initrd (loop) /live/initrd.img
}
menuentry "6. Clonezilla (i686pae) »{
set isofile =" / iso / clz32.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \" ocs-live-general \ "Ocs_live_extra_param = \" \ "ocs_live_keymap = \" \ "ocs_live_batch = \" no \ "ocs_lang = \" \ "vga = 788 ip = frommedia nosplash noeject toram = filesystem.
menuentry "7. Clonezilla (amd64) »{
set isofile =" / iso / clz64.iso "
loopback loop $ isofile
linux (loop) / live / vmlinuz boot = live live-config noswap nolocales edd = on nomodeset ocs_live_run = \" ocs-live-general \ "Ocs_live_extra_param = \" \ "ocs_live_keymap = \" \ "ocs_live_batch = \" no \ "ocs_lang = \" \ "vga = 788 ip = frommedia nosplash noeject toram = filesystem.squashfs findiso = $ isofile
initrd (loop) / live /initrd.img
}
}
submenu "3. Parted Magic "{
menuentry" 1. Parted Magic RAM (i586) »{
set isofile =" / iso / pmagic.iso "
initrd (loop) /pmagic/initrd.img
}
menuentry "2. Parted Magic RAM (amd64) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage64 iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
menuentry "3. Parted Magic Live (i586) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 livemedia noeject max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
menuentry "4. Parted Magic Live (amd64) »{
set isofile =" / iso / pmagic.iso "
loopback loop $ isofile
linux (loop) / pmagic / bzImage64 iso_filename = $ isofile edd = off load_ramdisk = 1 prompt_ramdisk = 0 rw vga = normal loglevel = 9 livemedia noeject max_loop = 256 vmalloc = 384MiB keymap = en ru_RU
initrd (loop) /pmagic/initrd.img
}
}
submenu "4. Debian "{
menuentry" 1. Debian netinstall (i368) "{
linux / debian / i386 / vmlinuz priority = low vga = 788 - initrd /debian/i386/initrd.gz
}
menuentry" 2. Debian netinstall (amd64) "{
linux / debian / amd64 / vmlinuz priority = low vga = 788 - initrd /debian/amd64/initrd.gz
}
}
submenu" 5. Ubuntu »{
menuentry "1. Ubuntu live (i386) »{
set isofile =" / iso / ubuntu32.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
menuentry "2. Ubuntu live (amd64) »{
set isofile =" / iso / ubuntu64.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
}
submenu "6. Lubuntu "{
menuentry" 1. Lubuntu live (i386) »{
set isofile =" / iso / lbuntu32.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console-setup / layoutcode = ru noeject noprompt - initrd (loop) /casper/initrd.lz
}
menuentry "2 . Lubuntu live (amd64) »{
set isofile =" / iso / lbuntu64.iso "
loopback loop $ isofile
linux (loop) / casper / vmlinuz boot = casper iso-scan / filename = $ isofile locale = ru_RU.UTF-8 console- setup / layoutcode = en noeject noprompt - initrd (loop) /casper/initrd.lz
}
}
menuentry "7. Windows "{
linux /grub.exe --config-file = / boot / win.lst
}
submenu" 8. Tools "{
menuentry" 1. Memtest »{
set isofile =" / iso / memtest.iso "
linux16 / boot / memdisk iso
initrd16 $ isofile
}
menuentry "2. Plop Boot Manager »{
linux16 /boot/plpbt.bin
}
}
menuentry" 9. First hdd "{
insmod ext2
insmod ntfs
set root = (hd1)
chainload + 1
}
Testing
For testing, I used VirtualBox .
You can attach a physical disk to a virtual machine in the following way:
VBoxManage internalcommands createrawvmdk -filename ./sdX.vmdk -rawdisk /dev/sdX
After that, simply attach the sdX.vmdk file to the virtual machine. Remember to unmount the partitions before starting the virtual machine.