From 13c475babcc34b16ed241a486cec2664ce00271f Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Wed, 13 Mar 2019 06:31:55 +0000 Subject: [PATCH] Get virtual kernel filesystem commands from the book, and really add /run/systemd/resolve/resolv.conf after creating the kernel FS in chapter 6 --- LFS/master.sh | 63 ++++++++++++++++++++---------------- common/kernfs.xsl | 23 +++++++++++++ common/libs/func_book_parser | 43 ++++++++++++++++++++++-- jhalfs | 2 +- 4 files changed, 100 insertions(+), 31 deletions(-) create mode 100644 common/kernfs.xsl diff --git a/LFS/master.sh b/LFS/master.sh index 81cd270..4c9cee4 100644 --- a/LFS/master.sh +++ b/LFS/master.sh @@ -445,12 +445,32 @@ build_Makefile() { # i=`expr $i + 1` done + # Store virtual kernel file systems commands: + devices=`cat ../kernfs-scripts/devices.sh | \ + sed -e 's|^| |' \ + -e 's|mount|sudo &|' \ + -e 's|mkdir|sudo &|' \ + -e 's|\\$|&&|g' \ + -e 's|\$\$LFS|$(MOUNT_PT)|g'` + teardown=`cat ../kernfs-scripts/teardown.sh | \ + sed -e 's|^| |' \ + -e 's|umount|sudo &|' \ + -e 's|\$LFS|$(MOUNT_PT)|'` + teardownat=`cat ../kernfs-scripts/teardown.sh | \ + sed -e 's|^| |' \ + -e 's|umount|@-sudo &|' \ + -e 's|\$LFS|$(MOUNT_PT)|'` +#echo [DEBUG] +#echo devices=$devices +#echo teardown=$teardown +#echo teardownat=$teardownat # Drop in the main target 'all:' and the chapter targets with each sub-target # as a dependency. ( cat << EOF all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS +$teardownat @sudo make do_housekeeping EOF ) >> $MKFILE @@ -533,14 +553,7 @@ mk_CUSTOM_TOOLS: mk_BLFS_TOOL @touch \$@ devices: ck_UID - sudo mount -v --bind /dev \$(MOUNT_PT)/dev - sudo mount -vt devpts devpts \$(MOUNT_PT)/dev/pts - sudo mount -vt proc proc \$(MOUNT_PT)/proc - sudo mount -vt sysfs sysfs \$(MOUNT_PT)/sys - sudo mount -vt tmpfs tmpfs \$(MOUNT_PT)/run - if [ -h \$(MOUNT_PT)/dev/shm ]; then \\ - sudo mkdir -p \$(MOUNT_PT)/\$\$(readlink \$(MOUNT_PT)/dev/shm); \\ - fi +$devices EOF ) >> $MKFILE if [ "$INITSYS" = systemd ]; then @@ -553,12 +566,9 @@ EOF fi ( cat << EOF + teardown: - sudo umount -v \$(MOUNT_PT)/dev/pts - sudo umount -v \$(MOUNT_PT)/dev - sudo umount -v \$(MOUNT_PT)/run - sudo umount -v \$(MOUNT_PT)/proc - sudo umount -v \$(MOUNT_PT)/sys +$teardown chroot1: devices sudo \$(CHROOT1) @@ -571,6 +581,19 @@ chroot: devices SETUP: $chapter4 LUSER: $chapter5 SUDO: $runasroot +EOF +) >> $MKFILE +if [ "$INITSYS" = systemd ]; then +( + cat << EOF + sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve + sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve + +EOF +) >> $MKFILE +fi +( + cat << EOF CHROOT: SHELL=/tools/bin/bash CHROOT: $chapter6 BOOT: $chapter78 @@ -597,26 +620,12 @@ restore-luser-env: @\$(call housekeeping) do_housekeeping: - @-umount \$(MOUNT_PT)/sys - @-umount \$(MOUNT_PT)/proc - @-if mountpoint -q \$(MOUNT_PT)/run; then \\ - umount \$(MOUNT_PT)/run; \\ - elif [ -h \$(MOUNT_PT)/dev/shm ]; then \\ - link=\$\$(readlink \$(MOUNT_PT)/dev/shm); \\ - umount \$(MOUNT_PT)/\$\$link; \\ - unset link; \\ - else \\ - umount \$(MOUNT_PT)/dev/shm; \\ - fi - @-umount \$(MOUNT_PT)/dev/pts - @-umount \$(MOUNT_PT)/dev @-rm /tools @-if [ ! -f luser-exist ]; then \\ userdel \$(LUSER); \\ rm -rf \$(LUSER_HOME); \\ fi; - EOF ) >> $MKFILE diff --git a/common/kernfs.xsl b/common/kernfs.xsl new file mode 100644 index 0000000..e9584ea --- /dev/null +++ b/common/kernfs.xsl @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + diff --git a/common/libs/func_book_parser b/common/libs/func_book_parser index f3a3289..d32acd5 100644 --- a/common/libs/func_book_parser +++ b/common/libs/func_book_parser @@ -211,7 +211,10 @@ extract_commands() { # # Create the packages file. We need it for proper Makefile creation create_package_list - create_chroot_scripts + if [ "${PROGNAME}" = lfs ]; then + create_chroot_scripts + create_kernfs_scripts + fi # Done. Moving on... get_sources @@ -258,10 +261,10 @@ create_package_list() { # } #----------------------------# -create_chroot_scripts() { # +create_chroot_scripts() { # #----------------------------# - rm -rf chroot_scripts + rm -rf chroot-scripts echo -n "Creating chroot commands scripts from $BOOK" if [ ! -z $ARCH ] ; then echo -n " $ARCH" ; fi echo -n "... " @@ -286,3 +289,37 @@ create_chroot_scripts() { # echo "done" } + +#----------------------------# +create_kernfs_scripts() { # +#----------------------------# + + rm -rf kernfs-scripts + mkdir kernfs-scripts + echo -n "Creating virtual kernel FS commands scripts from $BOOK" + if [ ! -z $ARCH ] ; then echo -n " $ARCH" ; fi + echo -n "... " + case ${PROGNAME} in + clfs*) + xsltproc --nonet --xinclude \ + -o kernfs-scripts/ kernfs.xsl \ + $BOOK/BOOK/${ARCH}-index.xml >> $LOGDIR/$LOG 2>&1 + ;; + hlfs) + xsltproc --nonet --xinclude \ + -o kernfs-scripts/ kernfs.xsl \ + $BOOK/index.xml >> $LOGDIR/$LOG 2>&1 + ;; + lfs) + xsltproc --nonet \ + -o kernfs-scripts/devices.sh kernfs.xsl \ + $BOOK/chapter06/kernfs.xml >> $LOGDIR/$LOG 2>&1 + xsltproc --nonet \ + -o kernfs-scripts/teardown.sh kernfs.xsl \ + $BOOK/chapter09/reboot.xml >> $LOGDIR/$LOG 2>&1 + ;; + *) + esac + echo "done" + +} diff --git a/jhalfs b/jhalfs index aa8c5f7..371751c 100755 --- a/jhalfs +++ b/jhalfs @@ -381,7 +381,7 @@ if [[ "$REBUILD_MAKEFILE" = "n" ]] ; then cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/ # Copy needed stylesheets - cp $COMMON_DIR/{packages.xsl,chroot.xsl} $JHALFSDIR/ + cp $COMMON_DIR/{packages.xsl,chroot.xsl,kernfs.xsl} $JHALFSDIR/ # Fix the XSL book parser case $PROGNAME in