From 637673085f69f5cabc5514d62b6221af8d70de4a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 19 May 2021 03:36:40 -0600 Subject: [PATCH] Update to support newer Archiso design --- build-iso | 46 ++------ mac-dgpu-disable-tool | 92 +--------------- profile/airootfs/etc/mkinitcpio.conf | 70 ++++++++++++ .../airootfs/etc/mkinitcpio.d/linux.preset | 11 ++ profile/airootfs/etc/shadow | 1 + .../getty@tty1.service.d/autologin.conf | 3 + profile/airootfs/root/.profile | 1 + ...prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 | Bin 0 -> 8 bytes profile/airootfs/root/mac-dgpu-disable-tool | 49 +++++++++ profile/bootstrap_packages.x86_64 | 2 + profile/efiboot/loader/entries/dgpu.conf | 7 ++ profile/efiboot/loader/loader.conf | 5 + profile/packages.x86_64 | 11 ++ profile/pacman.conf | 102 ++++++++++++++++++ profile/profiledef.sh | 19 ++++ profile/syslinux/syslinux-dgpu.cfg | 8 ++ profile/syslinux/syslinux.cfg | 12 +++ 17 files changed, 310 insertions(+), 129 deletions(-) mode change 100755 => 120000 mac-dgpu-disable-tool create mode 100644 profile/airootfs/etc/mkinitcpio.conf create mode 100644 profile/airootfs/etc/mkinitcpio.d/linux.preset create mode 100644 profile/airootfs/etc/shadow create mode 100644 profile/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf create mode 100644 profile/airootfs/root/.profile create mode 100644 profile/airootfs/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 create mode 100755 profile/airootfs/root/mac-dgpu-disable-tool create mode 100644 profile/bootstrap_packages.x86_64 create mode 100644 profile/efiboot/loader/entries/dgpu.conf create mode 100644 profile/efiboot/loader/loader.conf create mode 100644 profile/packages.x86_64 create mode 100644 profile/pacman.conf create mode 100644 profile/profiledef.sh create mode 100644 profile/syslinux/syslinux-dgpu.cfg create mode 100644 profile/syslinux/syslinux.cfg diff --git a/build-iso b/build-iso index 90d3c77..0f5534a 100755 --- a/build-iso +++ b/build-iso @@ -1,43 +1,13 @@ #!/bin/bash # -# Prep build env -rsync -ahvPS /usr/share/archiso/configs/releng/ temp/ -echo 'bc' > temp/packages.both -rm temp/airootfs/etc/systemd/scripts/choose-mirror -rm temp/airootfs/etc/systemd/system/choose-mirror.service -rm temp/airootfs/etc/systemd/system/etc-pacman.d-gnupg.mount -rm temp/airootfs/etc/systemd/system/pacman-init.service -rm temp/airootfs/etc/udev/rules.d/81-dhcpcd.rules -rmdir --ignore-fail-on-non-empty temp/airootfs/etc/udev/rules.d -rmdir --ignore-fail-on-non-empty temp/airootfs/etc/udev -cp mac-dgpu-disable-tool temp/airootfs/root/ -printf "\x07\x00\x00\x00\x01\x00\x00\x00" \ - > temp/airootfs/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 -chown -R root:root temp +# Check if running as root +if [[ "$EUID" -ne 0 ]]; then + echo "This script should be run as root." + echo "Aborted" + exit 1 +fi -# Adjust boot menus -sed -i 's/timeout 3/timeout 1/' temp/efiboot/loader/loader.conf -sed -i 's/Arch Linux archiso x86_64/Mac dGPU Disable Tool/' temp/efiboot/loader/entries/* - -sed -i '/BACKGROUND/d' temp/syslinux/* -echo 'PROMPT 1' >> temp/syslinux/archiso_head.cfg -echo 'TIMEOUT 1' >> temp/syslinux/archiso_head.cfg -echo 'DEFAULT arch64' >> temp/syslinux/archiso_head.cfg -sed -i -r 's/Arch Linux( \(x86_64\)|)( live medium|)/Mac dGPU Disable Tool/' temp/syslinux/* -sed -i '/allows/d' temp/syslinux/* - -# Add nomodeset boot option -sed -i -r 's/^(options.*)$/\1 nomodeset/' temp/efiboot/loader/entries/archiso* -sed -i -r 's/^(APPEND arch.*)$/\1 nomodeset/' temp/syslinux/*cfg - -# Modify live env -echo '' >> temp/airootfs/etc/motd -sed -i '/mirror/d' temp/airootfs/root/customize_airootfs.sh -sed -i '/usermod/d' temp/airootfs/root/customize_airootfs.sh -sed -i '/ssh/d' temp/airootfs/root/customize_airootfs.sh -echo 'echo "~/mac-dgpu-disable-tool" >> /root/.bashrc' \ - >> temp/airootfs/root/customize_airootfs.sh - -temp/build.sh -N dgpu -L DGPU -v +# Build ISO +mkarchiso -w /tmp/archiso-tmp-dgpu -o . -v profile diff --git a/mac-dgpu-disable-tool b/mac-dgpu-disable-tool deleted file mode 100755 index 2eeb0b1..0000000 --- a/mac-dgpu-disable-tool +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash -# - -SOURCE=/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 -DEST=/sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 -needs_nvram_reset="no" - -# Colors -CLEAR='\033[0m' -RED='\033[31m' -GREEN='\033[32m' -YELLOW='\033[33m' -ORANGE='\033[31;1m' -BLUE='\033[34m' - -# Functions -function beep () { - echo -ne '\007' -} -function beeps_bad () { - # SOS-like? - beep - sleep 0.25s - beep - sleep 0.25s - beep - - sleep 0.5s - - beep - sleep 0.5s - beep - sleep 0.5s - beep - - sleep 0.5s - - beep - sleep 0.25s - beep - sleep 0.25s - beep -} -function beeps_good () { - # Two quick beeps - beep - sleep 0.25s - beep -} - -echo '## Mac dGPU Disable Tool ##' -echo '' - -# Check for current variables -for prefix in gfx gpu; do - for var in /sys/firmware/efi/efivars/${prefix}*; do - # The test below is to avoid empty or nonexistent paths - if [[ -e "${var}" ]]; then - echo -e "${YELLOW}Detected:${CLEAR} $var" - needs_nvram_reset="yes" - fi - done -done - -echo "" -if [[ ! -e "/sys/firmware/efi/efivars" ]]; then - # Probably booted legacy - echo -e "${RED}ERROR:${CLEAR} EFIVARS not found" - beeps_bad -elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then - # EFI var matches desired state - echo -e "${GREEN}Discrete GPU already disabled${CLEAR}" - beeps_good -elif [[ "$needs_nvram_reset" == "yes" ]]; then - # One or more gfx/gpu EFI vars detected - echo -e "${RED}ERROR:${CLEAR} Detected the above EFIVARS" - echo -e "Please reboot and reset the NVRAM" - beeps_bad -else - # No gfx/gpu EFI vars detected so we can apply the fix - cp "$SOURCE" "$DEST" - chattr +i "$DEST" - umount /sys/firmware/efi/efivars - sync - echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}" - mount -t efivarfs efivarfs /sys/firmware/efi/efivars - beeps_good -fi -echo "" -read -p "Press Enter to poweroff the system... " -r unusedvar -poweroff diff --git a/mac-dgpu-disable-tool b/mac-dgpu-disable-tool new file mode 120000 index 0000000..7dcae8f --- /dev/null +++ b/mac-dgpu-disable-tool @@ -0,0 +1 @@ +profile/airootfs/root/mac-dgpu-disable-tool \ No newline at end of file diff --git a/profile/airootfs/etc/mkinitcpio.conf b/profile/airootfs/etc/mkinitcpio.conf new file mode 100644 index 0000000..4b7b7fb --- /dev/null +++ b/profile/airootfs/etc/mkinitcpio.conf @@ -0,0 +1,70 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# vim:set ft=sh +# MODULES +# The following modules are loaded before any boot hooks are +# run. Advanced users may wish to specify all system modules +# in this array. For instance: +# MODULES=(piix ide_disk reiserfs) +MODULES=() + +# BINARIES +# This setting includes any additional binaries a given user may +# wish into the CPIO image. This is run last, so it may be used to +# override the actual binaries included by a given hook +# BINARIES are dependency parsed, so you may safely ignore libraries +BINARIES=() + +# FILES +# This setting is similar to BINARIES above, however, files are added +# as-is and are not parsed in any way. This is useful for config files. +FILES=() + +# HOOKS +# This is the most important setting in this file. The HOOKS control the +# modules and scripts added to the image, and what happens at boot time. +# Order is important, and it is recommended that you do not change the +# order in which HOOKS are added. Run 'mkinitcpio -H ' for +# help on a given hook. +# 'base' is _required_ unless you know precisely what you are doing. +# 'udev' is _required_ in order to automatically load modules +# 'filesystems' is _required_ unless you specify your fs modules in MODULES +# Examples: +## This setup specifies all modules in the MODULES setting above. +## No raid, lvm2, or encrypted root is needed. +# HOOKS=(base) +# +## This setup will autodetect all modules for your system and should +## work as a sane default +# HOOKS=(base udev autodetect block filesystems) +# +## This setup will generate a 'full' image which supports most systems. +## No autodetection is done. +# HOOKS=(base udev block filesystems) +# +## This setup assembles a pata mdadm array with an encrypted root FS. +## Note: See 'mkinitcpio -H mdadm' for more information on raid devices. +# HOOKS=(base udev block mdadm encrypt filesystems) +# +## This setup loads an lvm2 volume group on a usb device. +# HOOKS=(base udev block lvm2 filesystems) +# +## NOTE: If you have /usr on a separate partition, you MUST include the +# usr, fsck and shutdown hooks. +HOOKS=(base udev modconf archiso block filesystems) + +# COMPRESSION +# Use this to compress the initramfs image. By default, gzip compression +# is used. Use 'cat' to create an uncompressed image. +#COMPRESSION="gzip" +#COMPRESSION="bzip2" +#COMPRESSION="lzma" +#COMPRESSION="xz" +#COMPRESSION="lzop" +#COMPRESSION="lz4" +#COMPRESSION="zstd" + +# COMPRESSION_OPTIONS +# Additional options for the compressor +#COMPRESSION_OPTIONS=() diff --git a/profile/airootfs/etc/mkinitcpio.d/linux.preset b/profile/airootfs/etc/mkinitcpio.d/linux.preset new file mode 100644 index 0000000..d35f137 --- /dev/null +++ b/profile/airootfs/etc/mkinitcpio.d/linux.preset @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# mkinitcpio preset file for the 'linux' package on archiso + +PRESETS=('archiso') + +ALL_kver='/boot/vmlinuz-linux' +ALL_config='/etc/mkinitcpio.conf' + +archiso_image="/boot/initramfs-linux.img" diff --git a/profile/airootfs/etc/shadow b/profile/airootfs/etc/shadow new file mode 100644 index 0000000..7edfd69 --- /dev/null +++ b/profile/airootfs/etc/shadow @@ -0,0 +1 @@ +root::14871:::::: diff --git a/profile/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf b/profile/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf new file mode 100644 index 0000000..d1d8474 --- /dev/null +++ b/profile/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=-/sbin/agetty --autologin root --noclear %I 38400 linux diff --git a/profile/airootfs/root/.profile b/profile/airootfs/root/.profile new file mode 100644 index 0000000..3917a68 --- /dev/null +++ b/profile/airootfs/root/.profile @@ -0,0 +1 @@ +/root/mac-dgpu-disable-tool diff --git a/profile/airootfs/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 b/profile/airootfs/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 new file mode 100644 index 0000000000000000000000000000000000000000..78bf659219acfd68d8e91f7a6a578b5478c26834 GIT binary patch literal 8 NcmZQ)U|?VbVgLX{00{s9 literal 0 HcmV?d00001 diff --git a/profile/airootfs/root/mac-dgpu-disable-tool b/profile/airootfs/root/mac-dgpu-disable-tool new file mode 100755 index 0000000..ed07f26 --- /dev/null +++ b/profile/airootfs/root/mac-dgpu-disable-tool @@ -0,0 +1,49 @@ +#!/bin/bash +# + +SOURCE=/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 +DEST=/sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 +needs_nvram_reset="no" + +# Colors +CLEAR='\033[0m' +RED='\033[31m' +GREEN='\033[32m' +YELLOW='\033[33m' +ORANGE='\033[31;1m' +BLUE='\033[34m' + +# Check for current variables +for prefix in gfx gpu; do + for var in /sys/firmware/efi/efivars/${prefix}*; do + # The test below is to avoid empty or nonexistent paths + if [[ -e "${var}" ]]; then + echo -e "${YELLOW}Detected:${CLEAR} $var" + needs_nvram_reset="yes" + fi + done +done + +echo "" +if [[ ! -e "/sys/firmware/efi/efivars" ]]; then + # Probably booted legacy + echo -e "${RED}ERROR:${CLEAR} EFIVARS not found" +elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then + # EFI var matches desired state + echo -e "${GREEN}Discrete GPU already disabled${CLEAR}" +elif [[ "$needs_nvram_reset" == "yes" ]]; then + # One or more gfx/gpu EFI vars detected + echo -e "${RED}ERROR:${CLEAR} Detected the above EFIVARS" + echo -e "Please reboot and reset the NVRAM" +else + # No gfx/gpu EFI vars detected so we can apply the fix + cp "$SOURCE" "$DEST" + chattr +i "$DEST" + sync + umount /sys/firmware/efi/efivars + echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}" + mount -t efivarfs efivarfs /sys/firmware/efi/efivars +fi +echo "" +read -p "Press Enter to poweroff the system... " -r unusedvar +poweroff diff --git a/profile/bootstrap_packages.x86_64 b/profile/bootstrap_packages.x86_64 new file mode 100644 index 0000000..64966d0 --- /dev/null +++ b/profile/bootstrap_packages.x86_64 @@ -0,0 +1,2 @@ +arch-install-scripts +base diff --git a/profile/efiboot/loader/entries/dgpu.conf b/profile/efiboot/loader/entries/dgpu.conf new file mode 100644 index 0000000..ba3b4b3 --- /dev/null +++ b/profile/efiboot/loader/entries/dgpu.conf @@ -0,0 +1,7 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +title Mac dGPU Disable Tool +linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux +initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux.img +options archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% nomodeset diff --git a/profile/efiboot/loader/loader.conf b/profile/efiboot/loader/loader.conf new file mode 100644 index 0000000..5604ee1 --- /dev/null +++ b/profile/efiboot/loader/loader.conf @@ -0,0 +1,5 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +timeout 0 +default dgpu.conf diff --git a/profile/packages.x86_64 b/profile/packages.x86_64 new file mode 100644 index 0000000..4d09f47 --- /dev/null +++ b/profile/packages.x86_64 @@ -0,0 +1,11 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later +base +#cloud-init +linux +mkinitcpio +mkinitcpio-archiso +#openssh +#qemu-guest-agent +syslinux +#virtualbox-guest-utils-nox diff --git a/profile/pacman.conf b/profile/pacman.conf new file mode 100644 index 0000000..9d895e9 --- /dev/null +++ b/profile/pacman.conf @@ -0,0 +1,102 @@ +# +# /etc/pacman.conf +# +# See the pacman.conf(5) manpage for option and repository directives +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# +# GENERAL OPTIONS +# +[options] +# The following paths are commented out with their default values listed. +# If you wish to use different paths, uncomment and update the paths. +#RootDir = / +#DBPath = /var/lib/pacman/ +#CacheDir = /var/cache/pacman/pkg/ +#LogFile = /var/log/pacman.log +#GPGDir = /etc/pacman.d/gnupg/ +#HookDir = /etc/pacman.d/hooks/ +HoldPkg = pacman glibc +#XferCommand = /usr/bin/curl -L -C - -f -o %o %u +#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u +#CleanMethod = KeepInstalled +Architecture = auto + +# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +#IgnorePkg = +#IgnoreGroup = + +#NoUpgrade = +#NoExtract = + +# Misc options +#UseSyslog +#Color +#TotalDownload +# We cannot check disk space from within a chroot environment +#CheckSpace +#VerbosePkgLists + +# By default, pacman accepts packages signed by keys that its local keyring +# trusts (see pacman-key and its man page), as well as unsigned packages. +SigLevel = Required DatabaseOptional +LocalFileSigLevel = Optional +#RemoteFileSigLevel = Required + +# NOTE: You must run `pacman-key --init` before first using pacman; the local +# keyring can then be populated with the keys of all official Arch Linux +# packagers with `pacman-key --populate archlinux`. + +# +# REPOSITORIES +# - can be defined here or included from another file +# - pacman will search repositories in the order defined here +# - local/custom mirrors can be added here or in separate files +# - repositories listed first will take precedence when packages +# have identical names, regardless of version number +# - URLs will have $repo replaced by the name of the current repo +# - URLs will have $arch replaced by the name of the architecture +# +# Repository entries are of the format: +# [repo-name] +# Server = ServerName +# Include = IncludePath +# +# The header [repo-name] is crucial - it must be present and +# uncommented to enable the repo. +# + +# The testing repositories are disabled by default. To enable, uncomment the +# repo name header and Include lines. You can add preferred servers immediately +# after the header, and they will be used before the default mirrors. + +#[testing] +#Include = /etc/pacman.d/mirrorlist + +[core] +Include = /etc/pacman.d/mirrorlist + +[extra] +Include = /etc/pacman.d/mirrorlist + +#[community-testing] +#Include = /etc/pacman.d/mirrorlist + +[community] +Include = /etc/pacman.d/mirrorlist + +# If you want to run 32 bit applications on your x86_64 system, +# enable the multilib repositories as required here. + +#[multilib-testing] +#Include = /etc/pacman.d/mirrorlist + +#[multilib] +#Include = /etc/pacman.d/mirrorlist + +# An example of a custom package repository. See the pacman manpage for +# tips on creating your own repositories. +#[custom] +#SigLevel = Optional TrustAll +#Server = file:///home/custompkgs diff --git a/profile/profiledef.sh b/profile/profiledef.sh new file mode 100644 index 0000000..9af9a0a --- /dev/null +++ b/profile/profiledef.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2034 + +iso_name="dgpu" +iso_label="DGPU_$(date +%Y-%m-%d)" +iso_publisher="https://github.com/2Shirt/Mac-dGPU-Disable-Tool" +iso_application="Mac dGPU Disable Tool" +iso_version="$(date +%Y-%m-%d)" +install_dir="dgpu" +buildmodes=('iso') +bootmodes=('bios.syslinux.mbr' 'bios.syslinux.eltorito' 'uefi-x64.systemd-boot.esp' 'uefi-x64.systemd-boot.eltorito') +arch="x86_64" +pacman_conf="pacman.conf" +airootfs_image_type="squashfs" +airootfs_image_tool_options=('-comp' 'xz' '-Xbcj' 'x86' '-b' '1M' '-Xdict-size' '1M') +file_permissions=( + ["/etc/shadow"]="0:0:400" + ["/root/mac-dgpu-disable-tool"]="0:0:700" +) diff --git a/profile/syslinux/syslinux-dgpu.cfg b/profile/syslinux/syslinux-dgpu.cfg new file mode 100644 index 0000000..c042eb3 --- /dev/null +++ b/profile/syslinux/syslinux-dgpu.cfg @@ -0,0 +1,8 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +LABEL dgpu +MENU LABEL Mac dGPU Disable Tool +LINUX /%INSTALL_DIR%/boot/%ARCH%/vmlinuz-linux +INITRD /%INSTALL_DIR%/boot/%ARCH%/initramfs-linux.img +APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% nomodeset diff --git a/profile/syslinux/syslinux.cfg b/profile/syslinux/syslinux.cfg new file mode 100644 index 0000000..e3f30a6 --- /dev/null +++ b/profile/syslinux/syslinux.cfg @@ -0,0 +1,12 @@ +# +# SPDX-License-Identifier: GPL-3.0-or-later + +SERIAL 0 115200 +UI menu.c32 +MENU TITLE dGPU Tool +MENU CLEAR + +DEFAULT dgpu +TIMEOUT 0 + +INCLUDE syslinux-dgpu.cfg