Skip to content

Commit

Permalink
Merge branch 'acidanthera:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisHotpatch authored Jan 6, 2023
2 parents 205e718 + 573c2d5 commit 050e852
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 37 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ OpenCore Changelog
#### v0.8.9
- Improved debug logging when applying ACPI patches
- Fixed loading macOS with legacy boot without Apple Secure Boot
- Added Linux support to legacy boot BootInstall script

#### v0.8.8
- Updated underlying EDK II package to edk2-stable202211
Expand Down
145 changes: 108 additions & 37 deletions Utilities/LegacyBoot/BootInstallBase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,122 @@ if [ ! -f "boot${ARCHS}" ] || [ ! -f boot0 ] || [ ! -f boot1f32 ]; then
exit 1
fi

diskutil list
echo "Disable SIP in the case of any problems with installation!!!"
echo "Enter disk number to install to:"
read -r N

if ! diskutil info disk"${N}" | grep -q "/dev/disk"
then
echo Disk "$N" not found
exit 1
fi
if [ "$(uname)" = "Linux" ]; then
if [ "$EUID" -ne 0 ]
then echo "Please run this script as root"
exit
fi
if [ "$(which lsblk)" = "" ]; then
echo "lsblk tool is missing! Try installing util-linux package"
exit 1
fi
if [ "$(which fdisk)" = "" ]; then
echo "fdisk tool is missing!"
exit 1
fi

if ! diskutil info disk"${N}"s1 | grep -q -e FAT_32 -e EFI
then
echo "No FAT32 partition to install"
exit 1
fi
rm -f newbs origbs

echo "Select the disk where you want to install boot files:"
lsblk -d | tail -n+2 | cut -d" " -f1
echo "Example: sda"
read -r DRIVE

DRIVE="/dev/${DRIVE}"

if ! lsblk "$DRIVE"; then
echo Disk "${DRIVE}" not found
exit 1
fi

echo "Choose EFI partition on selected disk:"
lsblk -f "${DRIVE}"
echo "Example: sda1"
read -r EFI_PART

EFI_PART="/dev/${EFI_PART}"

if ! lsblk -f "$EFI_PART" | grep -q -e FAT32 -e vfat; then
echo "No FAT32 partition to install"
exit 1
fi

# Write MBR
dd if=boot0 of="$DRIVE" bs=1 count=446 conv=notrunc || exit 1

umount "${EFI_PART}"

dd if="${EFI_PART}" count=1 of=origbs
cp -v boot1f32 newbs
dd if=origbs of=newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
dd if=/dev/random of=newbs skip=496 seek=496 bs=1 count=14 conv=notrunc
dd if=newbs of="${EFI_PART}"

# Write MBR
sudo fdisk -uy -f boot0 /dev/rdisk"${N}" || exit 1

diskutil umount disk"${N}"s1
sudo dd if=/dev/rdisk"${N}"s1 count=1 of=origbs
cp -v boot1f32 newbs
sudo dd if=origbs of=newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
dd if=/dev/random of=newbs skip=496 seek=496 bs=1 count=14 conv=notrunc
sudo dd if=newbs of=/dev/rdisk"${N}"s1
#if [[ "$(sudo diskutil mount disk"${N}"s1)" == *"mounted" ]]
if sudo diskutil mount disk"${N}"s1 | grep -q mounted
then
cp -v "boot${ARCHS}" "$(diskutil info disk"${N}"s1 | sed -n 's/.*Mount Point: *//p')/boot"
p=/tmp/$(uuidgen)/EFI
mkdir -p "${p}" || exit 1
mount -t vfat "${EFI_PART}" "${p}" -o rw,noatime,uid="$(id -u)",gid="$(id -g)" || exit 1

cp -v "boot${ARCHS}" "${p}/boot" || exit 1

echo Check "${p}" boot drive EFI folder to install OpenCorePkg

DISK_SCHEME=$(fdisk -l "${DRIVE}" | sed -n 's/.*Disklabel type: *//p')
if [ "$DISK_SCHEME" != "gpt" ]; then
BOOT_FLAG=$(dd if="$DRIVE" bs=1 count=1 status=none skip=$((0x1BE)) | od -t x1 -A n | tr -d ' ')
if [ "$BOOT_FLAG" != "80" ]; then
fdisk "$DRIVE" <<END
p
a
1
w
END
fi
fi
else
p=/tmp/$(uuidgen)/EFI
mkdir -p "${p}" || exit 1
sudo mount_msdos /dev/disk"${N}"s1 "${p}" || exit 1
cp -v "boot${ARCHS}" "${p}/boot" || exit 1
open "${p}"
fi
rm -f newbs origbs

diskutil list
echo "Disable SIP in the case of any problems with installation!!!"
echo "Enter disk number to install to:"
read -r N

if ! diskutil info disk"${N}" | grep -q "/dev/disk"; then
echo Disk "$N" not found
exit 1
fi

if ! diskutil info disk"${N}"s1 | grep -q -e FAT_32 -e EFI; then
echo "No FAT32 partition to install"
exit 1
fi

# Write MBR
sudo fdisk -uy -f boot0 /dev/rdisk"${N}" || exit 1

diskutil umount disk"${N}"s1
sudo dd if=/dev/rdisk"${N}"s1 count=1 of=origbs
cp -v boot1f32 newbs
sudo dd if=origbs of=newbs skip=3 seek=3 bs=1 count=87 conv=notrunc
dd if=/dev/random of=newbs skip=496 seek=496 bs=1 count=14 conv=notrunc
sudo dd if=newbs of=/dev/rdisk"${N}"s1
#if [[ "$(sudo diskutil mount disk"${N}"s1)" == *"mounted" ]]
if sudo diskutil mount disk"${N}"s1 | grep -q mounted; then
cp -v "boot${ARCHS}" "$(diskutil info disk"${N}"s1 | sed -n 's/.*Mount Point: *//p')/boot"
else
p=/tmp/$(uuidgen)/EFI
mkdir -p "${p}" || exit 1
sudo mount_msdos /dev/disk"${N}"s1 "${p}" || exit 1
cp -v "boot${ARCHS}" "${p}/boot" || exit 1
open "${p}"
fi

if diskutil info disk"${N}" | grep -q FDisk_partition_scheme
then
sudo fdisk -e /dev/rdisk"$N" <<-MAKEACTIVE
if diskutil info disk"${N}" | grep -q FDisk_partition_scheme; then
sudo fdisk -e /dev/rdisk"$N" <<-MAKEACTIVE
p
f 1
w
y
q
MAKEACTIVE
fi
fi

0 comments on commit 050e852

Please sign in to comment.