Skip to content

Instantly share code, notes, and snippets.

@brownman
Created September 2, 2015 15:48
Show Gist options
  • Save brownman/31431f75529f88db9288 to your computer and use it in GitHub Desktop.
Save brownman/31431f75529f88db9288 to your computer and use it in GitHub Desktop.
format usb drive , install grub , add file.iso, run with qemu
source /tmp/library.cfg
set -x
set -u
set -e
#trap exiting EXIT
drive=${1:-sdX}
partition=${drive}1
file_iso=$HOME/Downloads/XenServer-6.5.0-xenserver.org-install-cd2.iso
mode_cp=cp
filename_iso='xenserver.iso'
#file_iso=/boot/grub/$filename_iso
#If you use the wrong syntax, you will receive an error stating "Installation is impossible. Aborting"
if [ "$(id -u)" != "0" ]; then
echo "Sorry, you are not root."
exit 1
fi
exiting(){
$? || { lsof /mnt; }
}
fdisk1(){
echo "
d
n
p
1
a
1
t
c
w
" | fdisk /dev/$drive
}
format1(){
mkfs.vfat -F 32 -n MULTIBOOT /dev/$partition # (to format the partition as fat32)
}
umount1(){
cd /tmp
( ls -l /mnt/USB ) && { sleep 1; umount /mnt/USB; } || true
#umount /dev/$partition
}
grub1(){
#III. Install Grub2 on the USB Flash Drive:
#Old versions of grub used
local args1='--root-directory=/mnt/USB'
local args="--boot-directory=/mnt/USB/boot"
grub-install --force --no-floppy $args /dev/$drive
}
mnt1(){
( ls -l /mnt/USB || { mkdir -p /mnt/USB; } )
mount /dev/$partition /mnt/USB
}
cfg1(){
cd /mnt/USB/boot/grub
wget pendrivelinux.com/downloads/multibootlinux/grub.cfg #(to get the grub.cfg file)
cat > grub2.cfg <<START
set timeout=10
set default=0
menuentry "$filename_iso" {
loopback loop /boot/grub/$filename_iso
linux (loop)/boot/bzImage --
initrd (loop)/boot/tinycore.gz
}
START
}
wget1(){
cd /mnt/USB/boot/grub
( test -f $filename_iso ) || { wget "distro.ibiblio.org/pub/linux/distributions/tinycorelinux/2.x/release/tinycore-current.iso" -O $filename_iso; }
}
cp1(){
cd /mnt/USB/boot/grub
cp $file_iso $filename_iso
}
steps(){
( fdisk -l | grep /dev/$drive ) || { echo drive not found; exit; }
( fdisk -l | grep /dev/$partition ) && { umount1; } || true
fdisk1
format1
mnt1
grub1
if [ $mode_cp = "wget" ];then
wget1
else
cp1
fi
cfg1
umount1 && { qemu-system-x86_64 -hda /dev/$drive; }
}
steps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment