From 9cc4379fafc4becd38c061b4a0524eaa894df23f Mon Sep 17 00:00:00 2001 From: Kyle Glaws Date: Wed, 13 Apr 2022 14:24:27 -0400 Subject: [PATCH] uefi and bios builds succeeding --- build.sh | 72 +++++++++++++++++---------- phase4/build_order.txt | 8 --- phase4/linux.sh | 17 +++++++ phase5_bios/build_order.txt | 1 + phase5_bios/grub.sh | 25 ++++++++++ phase5_uefi/build_order.txt | 7 +++ {phase4 => phase5_uefi}/efibootmgr.sh | 0 {phase4 => phase5_uefi}/efivar.sh | 0 {phase4 => phase5_uefi}/grub.sh | 24 +++++++++ {phase4 => phase5_uefi}/mandoc.sh | 0 {phase4 => phase5_uefi}/popt.sh | 0 11 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 phase5_bios/build_order.txt create mode 100644 phase5_bios/grub.sh create mode 100644 phase5_uefi/build_order.txt rename {phase4 => phase5_uefi}/efibootmgr.sh (100%) rename {phase4 => phase5_uefi}/efivar.sh (100%) rename {phase4 => phase5_uefi}/grub.sh (62%) rename {phase4 => phase5_uefi}/mandoc.sh (100%) rename {phase4 => phase5_uefi}/popt.sh (100%) diff --git a/build.sh b/build.sh index 419f8f6..570c669 100755 --- a/build.sh +++ b/build.sh @@ -29,7 +29,7 @@ function usage { " exit.\n" \ "\n" \ " -i|--init Create the .img file, partition it, setup basic directory\n" \ - " structure, then exit." \ + " structure, then exit.\n" \ "\n" \ " -p|--start-phase\n" \ " -a|--start-package Select a phase and optionally a package\n" \ @@ -135,15 +135,15 @@ function check_dependencies { } function install_static { - FILENAME=$1 - FULLPATH="$LFS/$(basename $FILENAME | sed 's/__/\//g')" + local FILENAME=$1 + local FULLPATH="$LFS/$(basename $FILENAME | sed 's/__/\//g')" mkdir -p $(dirname $FULLPATH) cp $FILENAME $FULLPATH } function install_template { - FILENAME=$1 - FULLPATH="$LFS/$(basename $FILENAME | sed 's/__/\//g')" + local FILENAME=$1 + local FULLPATH="$LFS/$(basename $FILENAME | sed 's/__/\//g')" mkdir -p $(dirname $FULLPATH) cp $FILENAME $FULLPATH shift @@ -179,31 +179,41 @@ function init_image { echo -n "Creating image file... " + trap "echo 'init failed.' && exit 1" ERR + + if $VERBOSE + then + set -x + fi + # create image file fallocate -l$LFS_IMG_SIZE $LFS_IMG # hopefully banish any ghost images - dd if=/dev/zero of=$LFS_IMG count=1 conv=notrunc &> /dev/null + dd if=/dev/zero of=$LFS_IMG bs=1M count=1 conv=notrunc &> /dev/null # attach loop device - LOOP=$(losetup -f) + export LOOP=$(losetup -f) losetup $LOOP $LFS_IMG # partition the device - FDISK_INSTR=$FDISK_INSTR_BIOS if $UEFI then FDISK_INSTR=$FDISK_INSTR_UEFI + else + FDISK_INSTR=$FDISK_INSTR_BIOS fi # remove spaces and comments - FDISK_INSTR=$(echo "$FDISK_INSTR" | sed 's/#.*//') + FDISK_INSTR=$(echo "$FDISK_INSTR" | sed 's/ *#.*//') # fdisk fails to get kernel to re-read the partition table # so ignore non-zero exit code, and manually re-read + trap - ERR set +e echo "$FDISK_INSTR" | fdisk $LOOP &> /dev/null set -e + trap "echo 'init failed.' && unmount_image && exit 1" ERR # reattach loop device to re-read partition table losetup -d $LOOP @@ -285,9 +295,7 @@ function init_image { fi # install templates - install_template ./templates/boot__grub__grub.cfg LFSROOTLABEL install_template ./templates/etc__hosts LFSHOSTNAME - if $UEFI then install_template ./templates/etc__fstab LFSROOTLABEL LFSEFILABEL LFSFSTYPE @@ -317,13 +325,16 @@ function init_image { mkdir -p $LFS/$(readlink $LFS/dev/shm) fi + set +x + + trap - ERR + echo "done." } function cleanup_cancelled_download { local PKG=$PACKAGE_DIR/$(basename $1) - [ -f $PKG ] && rm $PKG - exit + [ -f $PKG ] && rm -f $PKG } function download_pkgs { @@ -334,7 +345,7 @@ function download_pkgs { for url in $PACKAGE_URLS do - trap "{ cleanup_cancelled_download $url; }" ERR SIGINT + trap "{ cleanup_cancelled_download $url; exit }" ERR SIGINT $VERBOSE && echo -n "Downloading '$url'... " if ! echo $ALREADY_DOWNLOADED | grep $(basename $url) > /dev/null @@ -366,7 +377,7 @@ function mount_image { unmount_image # attach loop device - LOOP=$(losetup -f) + export LOOP=$(losetup -f) LOOP_P1=${LOOP}p1 LOOP_P2=${LOOP}p2 @@ -443,15 +454,10 @@ function build_package { pushd $LFS > /dev/null if $CHROOT then - if ! chroot "$LFS" /usr/bin/env -i \ + if ! chroot "$LFS" /usr/bin/env \ HOME=/root \ TERM=$TERM \ - PATH=/usr/bin:/usr/sbin &> $LOG_FILE \ - MAKEFLAGS=$MAKEFLAGS \ - ROOT_PASSWD=$ROOT_PASSWD \ - RUN_TESTS=$RUN_TESTS \ - KERNELVERS=$KERNELVERS \ - $(cat $PACKAGE_LIST) \ + PATH=/usr/bin:/usr/sbin \ /usr/bin/bash +h -c "$BUILD_INSTR" &> $LOG_FILE then echo -e "\nERROR: $NAME Phase $PHASE failed:" @@ -512,6 +518,11 @@ function build_phase { CHROOT=true fi + if [ $PHASE -eq 5 ] + then + PHASE=5_$({ $UEFI && echo "uefi"; } || echo "bios") + fi + while read pkg do if $FOUNDSTARTPKG && $ONEOFF @@ -572,7 +583,7 @@ function clean_image { # delete logs if [ -n "$(ls ./logs)" ] then - rm -rf ./logs/*log ./logs/*gz + rm -rf ./logs/* fi } @@ -586,7 +597,9 @@ source ./config.sh ONEOFF=false VERBOSE=false -UEFI=false + +# exported because it's used by linux.sh +export UEFI=false while [ $# -gt 0 ]; do case $1 in @@ -659,7 +672,7 @@ while [ $# -gt 0 ]; do done if [ -n "$STARTPHASE" ] && -[ "$STARTPHASE" != 1 -a "$STARTPHASE" != 2 -a "$STARTPHASE" != 3 -a "$STARTPHASE" != 4 ] +[ "$STARTPHASE" != 1 -a "$STARTPHASE" != 2 -a "$STARTPHASE" != 3 -a "$STARTPHASE" != 4 -a "$STARTPHASE" != 5 ] then echo "ERROR: phase '$STARTPHASE' does not exist" exit 1 @@ -704,7 +717,8 @@ CONFIG_SITE=$LFS/usr/share/config.site LC_ALL=POSIX export LC_ALL PATH CONFIG_SITE -trap "{ unmount_image; exit 1; }" ERR SIGINT +trap "echo 'build failed.' && cd $FULLPATH && unmount_image && exit 1" ERR +trap "echo 'build cancelled.' && cd $FULLPATH && unmount_image && exit" SIGINT # ########### # Start build @@ -729,7 +743,11 @@ $ONEOFF && $FOUNDSTARTPHASE && unmount_image && exit build_phase 4 -# phase 4 cleanup +$ONEOFF && $FOUNDSTARTPHASE && unmount_image && exit + +build_phase 5 + +# final cleanup rm -rf $LFS/tmp/* find $LFS/usr/lib $LFS/usr/libexec -name \*.la -delete find $LFS/usr -depth -name $LFS_TGT\* | xargs rm -rf diff --git a/phase4/build_order.txt b/phase4/build_order.txt index df74cd3..b59cd23 100644 --- a/phase4/build_order.txt +++ b/phase4/build_order.txt @@ -54,7 +54,6 @@ diffutils gawk findutils groff -# Skipping GRUB MBR build since we are using UEFI gzip iproute2 kbd @@ -74,10 +73,3 @@ sysvinit lfsbootscripts linux -# UEFI Boot Dependencies -popt -mandoc -efivar -efibootmgr -grub - diff --git a/phase4/linux.sh b/phase4/linux.sh index a11f9a9..6672700 100644 --- a/phase4/linux.sh +++ b/phase4/linux.sh @@ -1,4 +1,15 @@ # LINUX Phase 4 + +function config_on { + local UNCOMMENTED="^${1}=.*\$" + local COMMENTED="^# ${1} .*\$" + sed -E -i "s/${UCOMMENTED}|${COMMENTED}/${1}=y/" ./.config +} + +function config_off { + sed -i "s/^${1}=.*$//" ./.config +} + CONFIGFILE=config-$KERNELVERS make mrproper @@ -8,6 +19,12 @@ then else # if kernel config not provided, use default architecture config make defconfig + + config_off CONFIG_IKHEADERS + config_on CONFIG_FB + config_off CONFIG_UEVENT_HELPER + config_on CONFIG_DEVTMPFS + config_on CONFIG_MODULES fi make diff --git a/phase5_bios/build_order.txt b/phase5_bios/build_order.txt new file mode 100644 index 0000000..b7e1eb1 --- /dev/null +++ b/phase5_bios/build_order.txt @@ -0,0 +1 @@ +grub diff --git a/phase5_bios/grub.sh b/phase5_bios/grub.sh new file mode 100644 index 0000000..64fbc7c --- /dev/null +++ b/phase5_bios/grub.sh @@ -0,0 +1,25 @@ +./configure --prefix=/usr \ + --sysconfdir=/etc \ + --disable-efiemu \ + --disable-werror + +make + +make install +mv -v /etc/bash_completion.d/grub /usr/share/bash-completion/completions + +grub-install $LOOP --target i386-pc + +cat > /boot/grub/grub.cfg < /boot/grub/grub.cfg <