Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9816f27ffd | ||
|
|
941f0d6be2 | ||
|
|
6a6b942dbd | ||
|
|
5cc82bf38c |
+61
-12
@@ -68,6 +68,26 @@ function create_partitions() {
|
||||
fi
|
||||
}
|
||||
|
||||
function get_dev_partition_num() {
|
||||
# $1 - device
|
||||
# $2 - partition number
|
||||
|
||||
if [ -b "${1}${2}" ];
|
||||
then
|
||||
echo "${1}${2}"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -b "${1}p${2}" ];
|
||||
then
|
||||
echo "${1}p${2}"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "${bold} == get_dev_partition_num: INTERNAL ERROR ==${normal}"
|
||||
exit 105
|
||||
}
|
||||
|
||||
function write_uefintfs() {
|
||||
cat "$dirpath/uefi-ntfs.img" > "$1"
|
||||
}
|
||||
@@ -79,9 +99,19 @@ function extract_iso() {
|
||||
7z x "$1" -o"$2"
|
||||
}
|
||||
|
||||
function extract_bootmgfw_from_installwim() {
|
||||
# $1 - install.wim path
|
||||
# $2 - destdir
|
||||
|
||||
7z e "$1" -o"$2" 1/Windows/Boot/EFI/bootmgfw.efi
|
||||
}
|
||||
|
||||
function umount_rm_path() {
|
||||
umount "$1" || true
|
||||
rm -r "$1"
|
||||
if [ -d "$1" ];
|
||||
then
|
||||
umount "$1" || true
|
||||
rm -r "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
function sigint_handler() {
|
||||
@@ -91,6 +121,8 @@ function sigint_handler() {
|
||||
if [[ ! "$3" ]];
|
||||
then
|
||||
echo "Windows 7/8/8.1/10 ISO to Flash Drive burning utility"
|
||||
echo "WARNING: this program will delete all existing data on your drive!"
|
||||
echo
|
||||
echo "$(basename "$0")" "<device> <windows iso> <mbr/gpt/gptntfs>"
|
||||
echo
|
||||
echo "Use MBR mode for old computers with BIOS (without UEFI), or for UEFI legacy mode (CSM)."
|
||||
@@ -109,10 +141,13 @@ then
|
||||
dev="$1"
|
||||
isopath="$2"
|
||||
labeltype="$3"
|
||||
partpath="$(mktemp -d /run/winiso-write.XXXXXXXXXX)"
|
||||
uefimode=
|
||||
[[ "$labeltype" == "gpt" ]] && uefimode=1
|
||||
[[ "$labeltype" == "gptntfs" ]] && uefimode=1
|
||||
partpath="$(mktemp -d /run/windows2usb.XXXXXXXXXX)"
|
||||
|
||||
check_requirements
|
||||
trap sigint_handler INT
|
||||
trap sigint_handler INT EXIT
|
||||
|
||||
# MBR
|
||||
if [[ "$labeltype" == "mbr" ]];
|
||||
@@ -122,14 +157,14 @@ then
|
||||
|
||||
echo "${bold} == Creating NTFS partition ==${normal}"
|
||||
create_partitions "dos" "$dev"
|
||||
mkfs.ntfs -f "${dev}1"
|
||||
mkfs.ntfs -f "$(get_dev_partition_num "${dev}" "1")"
|
||||
|
||||
echo "${bold} == Writing bootloader ==${normal}"
|
||||
ms-sys -7 "${dev}"
|
||||
ms-sys -n "${dev}1"
|
||||
ms-sys -n "$(get_dev_partition_num "${dev}" "1")"
|
||||
|
||||
echo "${bold} == Mounting data partition ==${normal}"
|
||||
mount "${dev}1" "$partpath"
|
||||
mount "$(get_dev_partition_num "${dev}" "1")" "$partpath"
|
||||
|
||||
# GPT
|
||||
elif [[ "$labeltype" == "gpt" ]];
|
||||
@@ -138,6 +173,7 @@ then
|
||||
then
|
||||
echo "${bold} == ERROR: install.wim is greater than 4 GiB ==${normal}"
|
||||
echo "${bold} == ERROR: Please use gptntfs mode ==${normal}"
|
||||
echo "NOTE: gptntfs does not support Secure Boot!"
|
||||
umount_rm_path "$partpath"
|
||||
exit 103
|
||||
fi
|
||||
@@ -146,10 +182,10 @@ then
|
||||
|
||||
echo "${bold} == Creating UEFI FAT partition ==${normal}"
|
||||
create_partitions "gpt" "$dev"
|
||||
mkfs.vfat "${dev}1"
|
||||
mkfs.vfat "$(get_dev_partition_num "${dev}" "1")"
|
||||
|
||||
echo "${bold} == Mounting data partition ==${normal}"
|
||||
mount "${dev}1" "$partpath"
|
||||
mount "$(get_dev_partition_num "${dev}" "1")" "$partpath"
|
||||
|
||||
# GPT FAT32 + NTFS
|
||||
elif [[ "$labeltype" == "gptntfs" ]];
|
||||
@@ -159,16 +195,29 @@ then
|
||||
|
||||
echo "${bold} == Creating UEFI FAT and Microsoft NTFS partitions ==${normal}"
|
||||
create_partitions "gptntfs" "$dev"
|
||||
write_uefintfs "${dev}1"
|
||||
mkfs.ntfs -f "${dev}2"
|
||||
write_uefintfs "$(get_dev_partition_num "${dev}" "1")"
|
||||
mkfs.ntfs -f "$(get_dev_partition_num "${dev}" "2")"
|
||||
|
||||
echo "${bold} == Mounting data partition ==${normal}"
|
||||
mount "${dev}2" "$partpath"
|
||||
mount "$(get_dev_partition_num "${dev}" "2")" "$partpath"
|
||||
fi
|
||||
|
||||
echo "${bold} == Extracting files from ISO to the partition ==${normal}"
|
||||
extract_iso "$isopath" "$partpath"
|
||||
|
||||
if [[ "$uefimode" ]];
|
||||
then
|
||||
if [ ! -f "$partpath/efi/boot/bootx64.efi" ] && \
|
||||
[ ! -f "$partpath/efi/boot/bootia32.efi" ];
|
||||
then
|
||||
echo "${bold} == Extracting UEFI bootloader from install.wim ==${normal}"
|
||||
mkdir -p "$partpath/efi/boot/" || true
|
||||
extract_bootmgfw_from_installwim "$partpath/sources/install.wim" "$partpath/efi/boot/"
|
||||
mv "$partpath/efi/boot/bootmgfw.efi" "$partpath/efi/boot/bootx64.efi"
|
||||
cp "$partpath/efi/boot/bootx64.efi" "$partpath/efi/boot/bootia32.efi"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${bold} == Unmounting partition ==${normal}"
|
||||
umount_rm_path "$partpath"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user