Skip to content

Instantly share code, notes, and snippets.

@jakelee8
Created July 12, 2016 04:54
Show Gist options
  • Save jakelee8/0149a03e66ad9da144209cb9b323a326 to your computer and use it in GitHub Desktop.
Save jakelee8/0149a03e66ad9da144209cb9b323a326 to your computer and use it in GitHub Desktop.
Attempt at multiboot Linux installer
DEVICE=/dev/sdb
MOUNT=/media/usb
# apt-get install -y udftools
# apt-get install -y casper grub-efi
# apt-get install -y grub-pc
# partition the disk
# fdisk ${DEVICE}
# sfdisk ${DEVICE} <<EOF
# label: dos
# device: /dev/sdb
# unit: sectors
# type=ef, size=4G, bootable
# type=07, size=8G, bootable
# type=07
# EOF
sfdisk ${DEVICE} <<EOF
label: gpt
device: /dev/sdb
unit: sectors
start=2048, size=128M, type=1
type=20
EOF
# create filesystem on usb pen
mkfs.fat -n BOOT ${DEVICE}1
mkfs.ext2 ${DEVICE}2
# mkfs.ext2 -L ISO_FILES ${DEVICE}3
BOOT_UUID=$(blkid -o value -s UUID ${DEVICE}1)
DATA_UUID=$(blkid -o value -s UUID ${DEVICE}2)
# mount usb
MOUNT_BOOT="${MOUNT}/boot"
MOUNT_DATA="${MOUNT}/data"
mkdir -p "${MOUNT_BOOT}" && mount ${DEVICE}1 "${MOUNT_BOOT}"
mkdir -p "${MOUNT_DATA}" && mount ${DEVICE}2 "${MOUNT_DATA}"
# install grub2 on usb pen
grub-install --force --target=x86_64-efi --removable \
--root-directory="${MOUNT_BOOT}" ${DEVICE}1
# grub-mkconfig -o ${MOUNT}/boot/grub/grub.cfg
# mkdir -p "${MOUNT_BOOT}/syslinux/"
# rsync -chtP /usr/lib/syslinux/ "${MOUNT_BOOT}/syslinux/"
# create grub config
cat <<EOF> ${MOUNT_BOOT}/boot/grub/grub.cfg
insmod all_video
if loadfont \${prefix}/fonts/unicode.pf2
then
insmod gfxterm
set gfxmode=auto
set gfxpayload=keep
terminal_output gfxterm
fi
# search --set=root --fs-uuid ${BOOT_UUID}
function boot_debian {
insmod part_gpt
insmod ext2
search --set=root --fs-uuid ${DATA_UUID}
loopback loop \$1
linux \$3 fromiso=/dev/disk/by-uuid/${DATA_UUID}/\$1 ro
initrd \$2
}
menuentry 'Install Debian Jessie (stable)' {
set isofile=/debian-8.5.0-amd64-netinst.iso
set initrdfile=/debian-jessie/hd-media/initrd.gz
# set vmlinuzfile=/debian-jessie/hd-media/vmlinuz
set vmlinuzfile=(loop)/install.amd/vmlinuz
boot_debian \${isofile} \${initrdfile} \${vmlinuzfile}
}
menuentry 'Install Debian Stretch (testing)' {
set isofile=/debian-stretch-DI-alpha7-amd64-netinst.iso
set initrdfile=/debian-stretch/hd-media/initrd.gz
# set vmlinuzfile=/debian-stretch/hd-media/vmlinuz
set vmlinuzfile=(loop)/install.amd/vmlinuz
boot_debian \${isofile} \${initrdfile} \${vmlinuzfile}
}
menuentry 'Install Ubuntu Server 16.04 LTS' {
set isofile=/ubuntu-16.04-server-amd64.iso
set initrdfile=/ubuntu-xenial/hd-media/initrd.gz
# set vmlinuzfile=/ubuntu-xenial/hd-media/vmlinuz
set vmlinuzfile=(loop)/install/vmlinuz
boot_debian \${isofile} \${initrdfile} \${vmlinuzfile}
}
# menuentry "Install Microsoft Windows 10" {
# search --set=root --fs-uuid ${WINI_UUID}
# chainloader /efi/boot/bootx64.efi
# }
menuentry "System Shutdown" {
halt
}
menuentry "System Reboot" {
reboot
}
EOF
grub-script-check "${MOUNT_BOOT}/boot/grub/grub.cfg"
if [ $? -ne 0 ]; then
echo 'GRUB config error!'
umount ${DEVICE}2
umount ${DEVICE}1
exit 1
fi
mount.vboxsf debian /mnt
rsync -chtP /mnt/debian-8.5.0-amd64-netinst.iso "${MOUNT_DATA}/"
rsync -chtP /mnt/debian-stretch-DI-alpha7-amd64-netinst.iso "${MOUNT_DATA}/"
rsync -chtP /mnt/ubuntu-16.04-server-amd64.iso "${MOUNT_DATA}/"
# rsync -chtP /mnt/Win10_1511_2_English_x64.iso "${MOUNT_DATA}/"
function download() {
wget -P "${MOUNT_DATA}/$1" -e robots=off -cr \
--cut-dirs=7 -nH -np -R index.html* -R robots.txt "$2"
}
download debian-jessie https://mirrors.kernel.org/debian/dists/jessie/main/installer-amd64/current/images/hd-media/
download debian-stretch https://mirrors.kernel.org/debian/dists/stretch/main/installer-amd64/current/images/hd-media/
download ubuntu-xenial http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/hd-media/
# wget -O "${MOUNT_DATA}/debian-jessie-initrd.gz" https://mirrors.kernel.org/debian/dists/jessie/main/installer-amd64/current/images/hd-media/initrd.gz
# wget -O "${MOUNT_DATA}/debian-stretch-initrd.gz" https://mirrors.kernel.org/debian/dists/stretch/main/installer-amd64/current/images/hd-media/initrd.gz
# wget -O "${MOUNT_DATA}/ubuntu-xenial-initrd.gz" http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/hd-media/initrd.gz
# for f in /mnt/ASRockSupport/*.zip; do
# unzip -d "${MOUNT_BOOT}/ASRockSupport" $f
# done
# mount /mnt/Win10_1511_2_English_x64.iso /media/cdrom
# # dd if=/mnt/Win10_1511_2_English_x64.iso of=${DEVICE}2 bs=1M
# rsync -acP --delete /media/cdrom/ "${MOUNT_WINI}/"
# umount /media/cdrom
umount /mnt
umount ${DEVICE}2
umount ${DEVICE}1
# mkdir -p mnt/{,boot,data,windows}
# sudo mount_msdos /dev/disk2s1 mnt/boot
# sudo mount_ntfs /dev/disk2s2 mnt/windows
# sudo mount_ntfs /dev/disk2s3 mnt/data
# sudo umount /dev/disk2s1
# sudo umount /dev/disk2s2
# sudo umount /dev/disk2s3
# http://askubuntu.com/questions/141940/how-to-boot-from-non-ubuntu-live-iso-images-like-fedora-or-centos
# http://reboot.pro/topic/19970-grub2-wimboot-windows-setup/
# http://superuser.com/questions/154133/grub-boot-from-iso
# http://unix.stackexchange.com/questions/199339/grub-boot-debian-iso-file-from-ntfs-partition-and-install-it
# http://www.panticz.de/MultiBootUSB
# http://www.tuxera.com/community/open-source-ntfs-3g/
# https://help.ubuntu.com/community/Grub2
# https://help.ubuntu.com/community/Grub2/Installing
# https://help.ubuntu.com/community/Grub2/ISOBoot
# https://wiki.archlinux.org/index.php/GRUB#.22No_suitable_mode_found.22_error
# https://wiki.archlinux.org/index.php/GRUB#Install_to_external_USB_stick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment