Last active
August 29, 2015 14:17
-
-
Save Shudouken/111c37a88aecbdd3b1f1 to your computer and use it in GitHub Desktop.
Creates a bootstick from archlinux based iso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creates a bootstick from archlinux based iso | |
function usage() { | |
echo "usage $0 /path/to/your_arch.iso /dev/sdX1" | |
echo "example: $0 archlinux-2015.02.01-dual.iso /dev/sdb1" | |
echo "" | |
echo "/dev/sdX needs to have an ms-dos partition table" | |
exit 1 | |
} | |
function error() { | |
echo "Error: $1" | |
exit 1 | |
} | |
#check for root | |
if [[ $EUID -ne 0 ]]; then | |
error "This script must be run as root" | |
fi | |
#check for correct usage | |
if ! [[ $# -eq 2 ]] || [[ $1 != *linux-*.*.*.iso ]] || [[ $2 != /*/*1 ]]; then | |
usage | |
fi | |
#check if required commands are present | |
commands="rsync mkdosfs mkdir sync grep lsblk extlinux fdisk dd umount mount" | |
for program in $commands; do | |
if ! type $program &> /dev/null; then | |
error "please install $program or the script cannot continue" | |
fi | |
done | |
iso="$1" | |
if ! [ -f $iso ]; then | |
error "$iso - file does not exist" | |
fi | |
label=$(echo "$iso" | grep -o -P '(?<=linux-).*(?=-)') | |
label="ARCH_${label:0:4}${label:5:2}" | |
usb="$2" | |
mnt=$(lsblk | grep -i ${usb:5:4}) | |
if ! [[ $mnt ]]; then | |
error "$usb - device not present" | |
fi | |
echo -n "Warning: all data on $usb will be lost, continue? [Y/n]: " | |
read cont | |
if [[ $cont ]] && [[ $cont != [Yy]* ]]; then | |
echo "Exiting ..." | |
exit 1 | |
fi | |
mnt=$(echo "${mnt:6}" | grep -o -P '(?<=/).*') | |
if [[ $mnt ]]; then | |
echo "Unmounting $usb at /$mnt ..." | |
umount /$mnt | |
fi | |
echo "Formatting $usb to FAT32 with label $label ..." | |
mkdosfs -F 32 -n $label -I $usb | |
#uuid=$(blkid $usb -o value -s UUID) | |
echo "Copying data from $iso to $usb ..." | |
mkdir -p /mnt/{iso,usb} | |
mount -o loop $iso /mnt/iso | |
mount $usb /mnt/usb | |
rsync --progress -av /mnt/iso/* /mnt/usb | |
echo "Running sync (this may take a while) ..." | |
sync | |
umount /mnt/iso | |
echo "Copying syslinux files ..." | |
rsync --progress -rv /usr/lib/syslinux/bios/*.c32 /mnt/usb/arch/boot/syslinux | |
extlinux --install /mnt/usb/arch/boot/syslinux | |
umount /mnt/usb | |
boot=$(fdisk -l ${usb:0:-1} | grep -i "*" | grep -i "$usb") | |
if ! [[ $boot ]]; then | |
echo "Setting bootable flag on ${usb:0:-1} ..." | |
fdisk ${usb:0:-1}<<EOF | |
a | |
w | |
EOF | |
fi | |
echo "Installing MBR to ${usb:0:-1} ..." | |
dd bs=440 count=1 if=/usr/lib/syslinux/bios/mbr.bin of=${usb:0:-1} | |
echo "Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment