Skip to content

Instantly share code, notes, and snippets.

@DoctorD90
Last active October 31, 2016 16:28
Show Gist options
  • Save DoctorD90/ae00c9921278768ec13b0a306634bbe0 to your computer and use it in GitHub Desktop.
Save DoctorD90/ae00c9921278768ec13b0a306634bbe0 to your computer and use it in GitHub Desktop.
To create an usb with multiple ISO on it
# Write dev path to your usb
myDEV="/dev/sdc"
# Write Label for your usb
myVOL="MultiBootUSB"
##### DO NOT EDIT BELOW #####
# Write 10MegaByte to clear formats on usb
sudo dd if=/dev/zero of="$myDEV" bs=1M count=10
# Create MBR format and create 1 partition with all available space
echo -en "o\nn\np\n1\n\n\nw\n" | sudo fdisk "$myDEV"
# Format partition with ex4
sudo mkfs.ext4 -j -O extent -L "$myVOL" "$myDEV"1
# Mount partition on /mnt
sudo mount "$myDEV"1 /mnt
# Take ownership of fs
sudo chown "$USER":"$USER" /mnt
# Install grub
sudo grub-install --target=i386-pc --force --removable --boot-directory=/mnt "$myDEV"
# Create grub.cfg
#sudo grub-mkconfig -o /mnt/grub/grub.cfg
sudo touch /mnt/grub/grub.cfg
sudo chmod 666 /mnt/grub/grub.cfg
sudo cat <<EOF > /mnt/grub/grub.cfg
insmod regexp
insmod all_video
for iso_with_device in /isos/*.iso; do
# Remove the grub device name to get just the path to the iso relative to its root.
regexp --set=iso_path '^\(.*\)(.*$)' "$iso_with_device"
menuentry "loop boot $iso_with_device" "$iso_path" {
iso_path="$2"
export iso_path
search --set=root --file "$iso_path"
loopback loop "$iso_path"
root=(loop)
configfile /boot/grub/loopback.cfg
loopback --delete loop
}
done
# Thanks to Jordan Uggla (Jordan_U on irc.freenode.net)
# https://lists.gnu.org/archive/html/help-grub/2016-01/msg00065.html
EOF
sudo chmod 444 /mnt/grub/grub.cfg
# Create isos folder
sudo mkdir /mnt/isos
sudo chown "$USER":"$USER" /mnt/isos
# Umount /mnt
sudo umount /mnt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment