📜 ⬆️ ⬇️

Creating multiboot HDD in linux (GRUB2 + memdisk + grub4dos)

Creating multiboot HDD in linux (GRUB2 + memdisk + grub4dos)


At some certain moment I got tired of carrying about a dozen bootable flash drives. And I created a multiboot usb hdd.
We will need:

This method should work for flash drives, but testing was not conducted.
Addition is described:

Disc preparation

The first step is to split the future boot disk into several partitions. I decided to split into two sections: one boot, the second for different files.
After changing the partition table, all data that is on the disk at the moment will be lost!
Creating 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 

Creating file systems

Create file systems:

 #mkfs.vfat -n boot /dev/sdX1 #mkfs.ntfs -f -L data /dev/sdX2 

Install loaders

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 memdisk / memdisk file from the syslinux archive, the grub.exe file from the grub4dos archive, the plpbt.bin file from the Plop archive, and the firadisk.img file from the firadisk archive.
 $unzip -j -d /mnt/boot/ syslinux-XXzip memdisk/memdisk $unzip -j -d /mnt/ grub4dos-XXXzip grub4dos-XXX/grub.exe $unzip -j -d /mnt/ grub4dos-XXXzip grub4dos-XXX/grldr $unzip -j -d /mnt/boot/ plpbt-XXXzip plpbt-XXX/plpbt.bin $7zx -o/mnt/boot/ firadisk-driver-0.0.1.30-f6.7z 

Preparation of images

Create a directory for iso files. Copy to the iso directory 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" in the root section for multiboot.
 $7zx ./iso/hiren.iso -o/mnt/ -ir\!HBCD 

Dr.Web Live CD

Unpack the “boot” directory from the iso file to a temporary directory and move its contents to the “boot” directory on the section for multiboot.
 $mkdir /mnt/drweb $7zx ./iso/drweb.iso -o/tmp -ir\!boot $mv /tmp/boot/* /mnt/boot/ 
Also find out BOOT_ID.
 $cat /mnt/drweb/config|grep BOOT_ID export BOOT_ID=xxxxxxxxxxxxxxxxxxxx 
Create a configuration file "/mnt/boot/drweb.lst" for grub4dos and add the following content 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 directories for 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 a configuration file "/mnt/boot/ubcd.lst" for grub4dos and add the following content to it:
 title Ultimate Boot CD map (hd0,0)/iso/ubcd.iso (hd32) map --hook root (hd32) chainloader (hd32) 

Windows XP CD

Create a configuration file "/mnt/boot/win.lst" for grub4dos and add the following content 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 = en_US
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 = en 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 = en 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.squashfs findiso = $ isofile
initrd (loop) /live/initrd.img
}
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"
loopback loop $ isofile
linux (loop) / pmagic / bzImage 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 "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_EN
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_EN
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 = en_US.UTF-8 console-setup / layoutcode = ru 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 = en_US.UTF-8 console-setup / layoutcode = ru 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 = en_US.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 = en_US.UTF-8 console-setup / layoutcode = ru 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 partitions before starting the virtual machine.

')

Source: https://habr.com/ru/post/181844/


All Articles