Skip to content

Instantly share code, notes, and snippets.

@penguin2716
Created January 30, 2014 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penguin2716/8709802 to your computer and use it in GitHub Desktop.
Save penguin2716/8709802 to your computer and use it in GitHub Desktop.
An easy script to create Gentoo/Linux installation usb stick.
#!/bin/sh
set -e
echo "This is an easy script to create Gentoo/Linux installation usb stick."
echo
if [ $# -ne 2 ]
then
echo "usage: $0 /dev/sdx /path/to/gentoo_install_disk.iso"
exit 1
fi
if [ `whoami` != "root" ]
then
echo "error: root access required"
exit 1
fi
DEVICE=$1
TARGET=${DEVICE}1
ISO=$2
LOGFILE=/dev/null
MBRBIN=/usr/share/syslinux/mbr.bin
echo "* removing all data in $DEVICE..."
echo " - deleting MBR..."
dd if=/dev/zero of=$DEVICE bs=512 count=1 >$LOGFILE 2>&1
fdisk $DEVICE >$LOGFILE 2>&1 <<_EOF
n
p
t
b
a
1
w
_EOF
echo " - formatting $TARGET with FAT32..."
mkdosfs -F 32 $TARGET >$LOGFILE 2>&1
echo " - installing MBR..."
dd if=$MBRBIN of=$DEVICE >$LOGFILE 2>&1
echo "* copying boot data..."
echo " - mounting devices..."
mkdir -p /mnt/usb
mkdir -p /mnt/iso
mount -t iso9660 -o loop,ro $ISO /mnt/iso
mount -t vfat $TARGET /mnt/usb
echo " - preparing data..."
cp -r /mnt/iso/* /mnt/usb
mv /mnt/usb/isolinux/* /mnt/usb
mv /mnt/usb/isolinux.cfg /mnt/usb/syslinux.cfg
rm -rf /mnt/usb/isolinux*
mv /mnt/usb/memtest86 /mnt/usb/memtest
sed -i \
-e "s:cdroot:cdroot slowusb:" \
-e "s:kernel memtest86:kernel memtest:" \
/mnt/usb/syslinux.cfg
echo " - writing (This may take a while)..."
sync
echo "* unmounting devices..."
umount /mnt/usb
umount /mnt/iso
rmdir /mnt/usb
rmdir /mnt/iso
echo "* finalizing..."
syslinux $TARGET
echo "DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment