Skip to content

Instantly share code, notes, and snippets.

@nobodyzxc
Last active March 31, 2022 08:08
Show Gist options
  • Save nobodyzxc/12d16b9bf6110ef2f720d298cf4e7bf5 to your computer and use it in GitHub Desktop.
Save nobodyzxc/12d16b9bf6110ef2f720d298cf4e7bf5 to your computer and use it in GitHub Desktop.
USB= # /dev/sdc
BOOTSIZE= # 1G
FAT32= # b # hex code in fdisk
exFAT= # 7 # hex code in fdisk
ISO= # archlinux-version-x86_64.iso # iso path
# VAR declar must be connected. ex: USB=/dev/sdc
if [ ! -n "$USB" ];then echo "please set USB" && exit; fi
if [ ! -n "$BOOTSIZE" ];then echo "please set BOOTSIZE" && exit; fi
if [ ! -n "$FAT32" ];then echo "please set FAT32" && exit; fi
if [ ! -n "$exFAT" ];then echo "please set exFAT" && exit; fi
if [ ! -n "$ISO" ];then echo "please set ISO" && exit; fi
set -e
# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
if [ ! -f $ISO ];then
echo $ISO not in the current path
exit 1
fi
(echo "o"; sleep 1; \
echo "n"; \
echo "p"; \
echo "1"; \
echo ""; \
echo "+$BOOTSIZE"; sleep 1; \
echo "n"; \
echo "p"; \
echo "2"; \
echo ""; \
echo ""; sleep 1; \
echo "t"; \
echo "1"; \
echo "$FAT32"; sleep 1; \
echo "t"; \
echo "2"; \
echo "$exFAT"; sleep 1; \
echo "a"; \
echo "1"; sleep 1; \
echo "w"; sleep 1;) | sudo fdisk $USB
sudo mkfs.vfat ${USB}1
sudo mkfs.exfat ${USB}2
sudo mkdir -p /mnt/{iso,usb}
sudo mount -o loop $ISO /mnt/iso
sudo mount ${USB}1 /mnt/usb
sudo cp -a /mnt/iso/* /mnt/usb
sudo sync
sudo umount /mnt/iso
LABEL=`grep -ohP "label=ARCH_\\d*" /mnt/usb/syslinux/*.cfg | cut -c7- | head -n 1`
sudo umount /mnt/usb
sudo fatlabel ${USB}1 $LABEL
echo "set LABEL = $LABEL"
sudo syslinux --directory syslinux --install ${USB}1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment