diff mbox series

[3/4] guestfs: fix trixie bringup

Message ID 20241011010111.3543993-4-mcgrof@kernel.org (mailing list archive)
State New
Headers show
Series kdevops: make trixie default | expand

Commit Message

Luis Chamberlain Oct. 11, 2024, 1:01 a.m. UTC
We have a series of fixups needed to the default generic debian 13
trixie image:

 - kdevops has support for default heuristic when debian is detected
   on the host, and if your host has an /etc/apt/sources.list with
   a hop 1 to the servers, we infer that you are using a local mirror
   for debian. *If* the host and guest match distributions or at
   least we feel confident in the upgrade process (upgrading buster
   to trixie on the guest) then we by default enable leveraging the
   host's sources.list file onto the guest so the guest can also
   save bandwidth. This works nicely. However trixie uses an
   /etc/nsswitch.conf like this:

      files myhostname resolve [!UNAVAIL=return] dns

  This will prevent using dns from finding the 1 hop server on
  /etc/apt/sources.list. To fix this enable dns to be used for
  host son trixie.

 - cloud-init is not used by us and so we should just stop
   it, otherwise we may timeout on some random clout init
   guess work.

 - setup locales for LANG=en_US.UTF-8, we can later add variability
   if folks want it

 - restart ssh as in practice I've seen issues on bringup and timeouts

 - Be sure to remove the distro's /etc/apt/sources.list.d/debian.sources
   if CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST is enabled
   (as explained above).

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 scripts/bringup_guestfs.sh | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/scripts/bringup_guestfs.sh b/scripts/bringup_guestfs.sh
index d09ae64dcaea..16bfa7a6c805 100755
--- a/scripts/bringup_guestfs.sh
+++ b/scripts/bringup_guestfs.sh
@@ -233,6 +233,31 @@  firstboot-command systemctl stop ssh
 firstboot-command DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure -p low --force openssh-server
 firstboot-command systemctl start ssh
 _EOT
+	# CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST will not work
+	# if etc/nsswitch.conf has a line like this:
+	#
+	# hosts:          files myhostname resolve [!UNAVAIL=return] dns
+	#
+	# We need DNS to be used so virb0 will be used for a DNS request
+	if [[ "$CONFIG_GUESTFS_DEBIAN_TRIXIE" == "y" ]]; then
+		cat <<_EOT >>$cmdfile
+edit /etc/nsswitch.conf:'s/^hosts:.*UNAVAIL=return.*dns/hosts: files myhostname resolve dns/'
+uninstall cloud-init
+write /etc/default/locale:LANG=en_US.UTF-8
+append-line /etc/default/locale:LANGUAGE=en_US:en
+write /etc/locale.gen:en_US.UTF-8 UTF-8
+firstboot-command locale-gen en_US.UTF-8
+firstboot-command update-locale LANG=en_US.UTF-8
+firstboot-command DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure -p low --force locales
+firstboot-command systemctl stop ssh
+firstboot-command systemctl start ssh
+_EOT
+		if [[ "$CONFIG_GUESTFS_COPY_SOURCES_FROM_HOST_TO_GUEST" == "y" ]]; then
+		cat <<_EOT >>$cmdfile
+delete /etc/apt/sources.list.d/debian.sources
+_EOT
+		fi
+	fi
 }
 
 USE_SUDO=""