systemd: copy /etc/resolv.conf from the host

when entering chroot. This allows using the network in chroot.
This commit is contained in:
Pierre Labastie 2022-10-06 10:39:09 +02:00
parent 3722d3164c
commit 262e174aa1

View file

@ -293,6 +293,21 @@ build_Makefile() { #
all: ck_UID ck_terminal mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS all: ck_UID ck_terminal mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS
@sudo env LFS=\$(MOUNT_PT) kernfs-scripts/teardown.sh @sudo env LFS=\$(MOUNT_PT) kernfs-scripts/teardown.sh
EOF
) >> $MKFILE
# With systemd, the commands in chapter 9 do not create a
# valid /etc/resolv.conf, so that if blfs_tools are installed, and
# make-ca is run, it cannot connect. In this case, resolv.conf
# from the host has been copied, and we need to remove it now.
if [ "$INITSYS" = systemd ]; then
(
cat << EOF
@sudo rm -v \$(MOUNT_PT)/etc/resolv.conf
EOF
) >> $MKFILE
fi
(
cat << EOF
@sudo make do_housekeeping @sudo make do_housekeeping
@echo $VERSION > lfs-release && \\ @echo $VERSION > lfs-release && \\
sudo mv lfs-release \$(MOUNT_PT)/etc && \\ sudo mv lfs-release \$(MOUNT_PT)/etc && \\
@ -380,11 +395,17 @@ devices: ck_UID
sudo env LFS=\$(MOUNT_PT) kernfs-scripts/devices.sh sudo env LFS=\$(MOUNT_PT) kernfs-scripts/devices.sh
EOF EOF
) >> $MKFILE ) >> $MKFILE
# With systemd, the commands in chapter 9 do not create a
# valid /etc/resolv.conf, so that if we want to enter chroot,
# and systemd has not yet been run (otherwise /etc/resolv.conf
# exists), we just copy resolv.conf from the host.
if [ "$INITSYS" = systemd ]; then if [ "$INITSYS" = systemd ]; then
( (
cat << EOF cat << EOF
sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve if ! [ -e \$(MOUNT_PT)/etc/resolv.conf ]; then \\
sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/etc; \\
sudo touch \$(MOUNT_PT)/etc/.host-resolvconf; \\
fi
EOF EOF
) >> $MKFILE ) >> $MKFILE
fi fi
@ -393,6 +414,25 @@ fi
teardown: teardown:
sudo env LFS=\$(MOUNT_PT) kernfs-scripts/teardown.sh sudo env LFS=\$(MOUNT_PT) kernfs-scripts/teardown.sh
EOF
) >> $MKFILE
# With systemd, the commands in chapter 9 do not create a
# valid /etc/resolv.conf, so that if we want to enter chroot,
# and systemd has not yet been run (otherwise /etc/resolv.conf
# exists), we just copy resolv.conf from the host.
# We need to remove it now, if it has been created.
if [ "$INITSYS" = systemd ]; then
(
cat << EOF
if [ -e \$(MOUNT_PT)/etc/.host-resolvconf ]; then \\
sudo rm -v \$(MOUNT_PT)/etc/resolv.conf; \\
sudo rm -v \$(MOUNT_PT)/etc/.host-resolvconf; \\
fi
EOF
) >> $MKFILE
fi
(
cat << EOF
chroot1: devices chroot1: devices
sudo \$(CHROOT1) sudo \$(CHROOT1)
@ -407,11 +447,14 @@ LUSER: $LUSER_TGT
SUDO: $SUDO_TGT SUDO: $SUDO_TGT
EOF EOF
) >> $MKFILE ) >> $MKFILE
# With systemd, the commands in chapter 9 do not create a
# valid /etc/resolv.conf, so that if blfs_tools are installed, and
# make-ca is run, it cannot connect. We just copy resolv.conf
# from the host. We'll remove it at the end.
if [ "$INITSYS" = systemd ]; then if [ "$INITSYS" = systemd ]; then
( (
cat << EOF cat << EOF
mkdir -pv \$(MOUNT_PT)/run/systemd/resolve @cp -v /etc/resolv.conf \$(MOUNT_PT)/etc
cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
EOF EOF
) >> $MKFILE ) >> $MKFILE