Updated wwinit for clarity #1156

Also:

- Renamed /warewulf/wwinit to /warewulf/prescripts

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-02-12 11:45:55 -07:00
parent fb9f269fc5
commit 4fa8601b75
12 changed files with 159 additions and 68 deletions

View File

@@ -33,8 +33,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
and to include `PS1` from the environment if present. #1245 and to include `PS1` from the environment if present. #1245
- DHCP template generates as much of the subnet and range definition as possible. #1469 - DHCP template generates as much of the subnet and range definition as possible. #1469
- Updated overlay flags to `wwctl <node|profile> <add|set> [--runtime-overlays|--system-overlays]`. #1495 - Updated overlay flags to `wwctl <node|profile> <add|set> [--runtime-overlays|--system-overlays]`. #1495
- Update ipxe and grub configuration for clarity and logging. #1156 - Added logging and updated output during iPXE and GRUB. #1156
- Defined a menu for iPXE. #1156 - Defined a menu for iPXE. #1156
- Added logging to wwinit scripts. #1156
- Renamed /warewulf/wwinit to /warewulf/prescripts. #1156
### Fixed ### Fixed

View File

@@ -216,7 +216,7 @@ install: build docs ## Install Warewulf from source
(cd overlays && find * -path '*/internal' -prune -o -type d -exec mkdir -pv $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;) (cd overlays && find * -path '*/internal' -prune -o -type d -exec mkdir -pv $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;)
(cd overlays && find * -path '*/internal' -prune -o -type l -exec cp -av {} $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;) (cd overlays && find * -path '*/internal' -prune -o -type l -exec cp -av {} $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;)
chmod 0755 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/init chmod 0755 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/init
chmod 0755 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/$(WWCLIENTDIR)/wwinit chmod 0755 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/$(WWCLIENTDIR)/wwprescripts
chmod 0600 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/$(WWCLIENTDIR)/config.ww chmod 0600 $(DESTDIR)$(DATADIR)/warewulf/overlays/wwinit/rootfs/$(WWCLIENTDIR)/config.ww
chmod 0600 $(DESTDIR)$(DATADIR)/warewulf/overlays/ssh.host_keys/rootfs/etc/ssh/ssh* chmod 0600 $(DESTDIR)$(DATADIR)/warewulf/overlays/ssh.host_keys/rootfs/etc/ssh/ssh*
chmod 0644 $(DESTDIR)$(DATADIR)/warewulf/overlays/ssh.host_keys/rootfs/etc/ssh/ssh*.pub.ww chmod 0644 $(DESTDIR)$(DATADIR)/warewulf/overlays/ssh.host_keys/rootfs/etc/ssh/ssh*.pub.ww

48
init.bak Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/sh
echo "Warewulf pre-init (/init)"
echo
echo "Mounting kernel file systems..."
mountpoint -q /proc || (mkdir -p /proc && mount -t proc proc /proc && echo "Mounted /proc")
mountpoint -q /dev || (mkdir -p /dev && mount -t devtmpfs devtmpfs /dev && echo "Mounted /dev")
mountpoint -q /sys || (mkdir -p /sys && mount -t sysfs sysfs /sys && echo "Mounted /sys")
echo
echo "Loading /warewulf/config..."
if [ -f "/warewulf/config" ]; then
. /warewulf/config
else
echo "ERROR: Warewulf configuration file not found."
echo "Rebooting in 1 minute..."
sleep 60
echo b > /proc/sysrq-trigger || /sbin/reboot -f
fi
echo
echo "Configuring root file system..."
WWPRESCRIPTS=/warewulf/wwprescripts
chmod +rx "${WWPRESCRIPTS}"
WWROOT="${WWROOT:-initramfs}"
if [ "${WWROOT}" = "initramfs" ]; then
echo "WWROOT=${WWROOT}: using initial rootfs and invoking ${WWPRESCRIPTS}..."
exec "${WWPRESCRIPTS}"
elif [ "${WWROOT}" = "ramfs" -o "${WWROOT}" = "tmpfs" ]; then
echo "WWROOT=${WWROOT}: setting up new ${WWROOT} rootfs (/newroot)..."
mkdir /newroot
mount wwroot /newroot -t ${WWROOT} -o mpol=interleave # mpol ignored for ramfs
tar -cf - --exclude ./proc --exclude ./sys --exclude ./dev --exclude --exclude ./newroot . | tar -xf - -C /newroot
mkdir /newroot/proc /newroot/dev /newroot/sys 2>/dev/null
echo "Switching to new rootfs (/newroot) and invoking ${WWPRESCRIPTS}..."
exec /sbin/switch_root /newroot "${WWPRESCRIPTS}"
else
echo "ERROR: Unrecognized rootfs type requested: ${WWROOT}"
echo "Rebooting in 1 minute..."
sleep 60
echo b > /proc/sysrq-trigger || /sbin/reboot -f
fi
echo
echo "ERROR: wwinit encountered a problem."
echo "Rebooting in 1 minute..."
sleep 60
echo b > /proc/sysrq-trigger || /sbin/reboot -f

View File

@@ -165,6 +165,7 @@ type Node struct {
func (legacy *Node) Upgrade(addDefaults bool, replaceOverlays bool) (upgraded *node.Node) { func (legacy *Node) Upgrade(addDefaults bool, replaceOverlays bool) (upgraded *node.Node) {
upgraded = new(node.Node) upgraded = new(node.Node)
upgraded.Tags = make(map[string]string) upgraded.Tags = make(map[string]string)
upgraded.Resources = make(map[string]node.Resource)
upgraded.Disks = make(map[string]*node.Disk) upgraded.Disks = make(map[string]*node.Disk)
upgraded.FileSystems = make(map[string]*node.FileSystem) upgraded.FileSystems = make(map[string]*node.FileSystem)
upgraded.Ipmi = new(node.IpmiConf) upgraded.Ipmi = new(node.IpmiConf)
@@ -332,6 +333,11 @@ func (legacy *Node) Upgrade(addDefaults bool, replaceOverlays bool) (upgraded *n
genericSplitOverlays) genericSplitOverlays)
} }
} }
if legacy.Resources != nil {
for key, value := range legacy.Resources {
upgraded.Resources[key] = value
}
}
return return
} }

View File

@@ -254,7 +254,7 @@ nodes:
`, `,
}, },
{ {
name: "keys and tags", name: "keys, tags, and resources",
addDefaults: false, addDefaults: false,
replaceOverlays: false, replaceOverlays: false,
legacyYaml: ` legacyYaml: `
@@ -269,6 +269,13 @@ nodeprofiles:
key4: valD key4: valD
tagsdel: tagsdel:
- key4 - key4
resources:
res1:
- val1a
- val1b
res2:
- val2a
- val2b
network devices: network devices:
default: default:
tags: tags:
@@ -295,6 +302,13 @@ nodes:
key4: valD key4: valD
tagsdel: tagsdel:
- key4 - key4
resources:
resn1:
- valn1a
- valn1b
resn2:
- valn2a
- valn2b
network devices: network devices:
default: default:
tags: tags:
@@ -327,6 +341,13 @@ nodeprofiles:
key1: val1 key1: val1
key2: valB key2: valB
key3: valC key3: valC
resources:
res1:
- val1a
- val1b
res2:
- val2a
- val2b
nodes: nodes:
n1: n1:
ipmi: ipmi:
@@ -342,6 +363,13 @@ nodes:
key1: val1 key1: val1
key2: valB key2: valB
key3: valC key3: valC
resources:
resn1:
- valn1a
- valn1b
resn2:
- valn2a
- valn2b
`, `,
}, },
{ {

View File

@@ -1,14 +1,13 @@
#!/bin/sh #!/bin/sh
#
# This is one of those types of files that you shouldn't edit unless you really
# know what you are doing and even then you should make a backup.
#
# Edit at your own risk! DANGER DANGER.
echo "Warewulf pre-init (/init)"
echo
echo "Mounting kernel file systems..."
mountpoint -q /proc || (mkdir -p /proc && mount -t proc proc /proc && echo "Mounted /proc") mountpoint -q /proc || (mkdir -p /proc && mount -t proc proc /proc && echo "Mounted /proc")
mountpoint -q /dev || (mkdir -p /dev && mount -t devtmpfs devtmpfs /dev && echo "Mounted /dev") mountpoint -q /dev || (mkdir -p /dev && mount -t devtmpfs devtmpfs /dev && echo "Mounted /dev")
mountpoint -q /sys || (mkdir -p /sys && mount -t sysfs sysfs /sys && echo "Mounted /sys") mountpoint -q /sys || (mkdir -p /sys && mount -t sysfs sysfs /sys && echo "Mounted /sys")
echo
echo "Loading /warewulf/config..."
if [ -f "/warewulf/config" ]; then if [ -f "/warewulf/config" ]; then
. /warewulf/config . /warewulf/config
else else
@@ -17,24 +16,24 @@ else
sleep 60 sleep 60
echo b > /proc/sysrq-trigger || /sbin/reboot -f echo b > /proc/sysrq-trigger || /sbin/reboot -f
fi fi
echo
echo "Warewulf v4 is now booting: ${WWHOSTNAME}"
echo echo
echo "Configuring root file system..."
chmod 755 /warewulf/wwinit WWPRESCRIPTS=/warewulf/wwprescripts
chmod +rx "${WWPRESCRIPTS}"
if [ -z "${WWROOT}" -o "${WWROOT}" = "initramfs" ]; then WWROOT="${WWROOT:-initramfs}"
echo "Retaining initramfs and invoking /warewulf/wwinit..." if [ "${WWROOT}" = "initramfs" ]; then
exec /warewulf/wwinit echo "WWROOT=${WWROOT}: using initial rootfs and invoking ${WWPRESCRIPTS}..."
exec "${WWPRESCRIPTS}"
elif [ "${WWROOT}" = "ramfs" -o "${WWROOT}" = "tmpfs" ]; then elif [ "${WWROOT}" = "ramfs" -o "${WWROOT}" = "tmpfs" ]; then
echo "Setting up new ${WWROOT} rootfs..." echo "WWROOT=${WWROOT}: setting up new ${WWROOT} rootfs (/newroot)..."
mkdir /newroot mkdir /newroot
mount wwroot /newroot -t ${WWROOT} -o mpol=interleave # mpol ignored for ramfs mount wwroot /newroot -t ${WWROOT} -o mpol=interleave # mpol ignored for ramfs
tar -cf - --exclude ./proc --exclude ./sys --exclude ./dev --exclude --exclude ./newroot . | tar -xf - -C /newroot tar -cf - --exclude ./proc --exclude ./sys --exclude ./dev --exclude --exclude ./newroot . | tar -xf - -C /newroot
mkdir /newroot/proc /newroot/dev /newroot/sys 2>/dev/null mkdir /newroot/proc /newroot/dev /newroot/sys 2>/dev/null
echo "Switching to new rootfs and invoking /warewulf/wwinit..." echo "Switching to new rootfs (/newroot) and invoking ${WWPRESCRIPTS}..."
exec /sbin/switch_root /newroot /warewulf/wwinit exec /sbin/switch_root /newroot "${WWPRESCRIPTS}"
else else
echo "ERROR: Unrecognized rootfs type requested: ${WWROOT}" echo "ERROR: Unrecognized rootfs type requested: ${WWROOT}"
echo "Rebooting in 1 minute..." echo "Rebooting in 1 minute..."
@@ -43,7 +42,7 @@ else
fi fi
echo echo
echo "ERROR: There was a problem with the initial provisioning process." echo "ERROR: wwinit encountered a problem."
echo "Rebooting in 1 minute..." echo "Rebooting in 1 minute..."
sleep 60 sleep 60
echo b > /proc/sysrq-trigger || /sbin/reboot -f echo b > /proc/sysrq-trigger || /sbin/reboot -f

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
. /warewulf/config echo "Warewulf prescript: localhost"
echo
echo "Bringing up lo:127.0.0.1" echo "Bringing up lo..."
/sbin/ip link set dev lo up /sbin/ip link set dev lo up

View File

@@ -4,17 +4,22 @@
export PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH=/usr/bin:/bin:/usr/sbin:/sbin
echo "Warewulf prescript: IPMI"
echo
if [ "$WWIPMI_WRITE" != "true" ]; then if [ "$WWIPMI_WRITE" != "true" ]; then
echo "IPMI write not configured: skipping" echo "IPMI write not configured: skipping"
exit exit
fi fi
echo "Loading IPMI kernel modules..."
modprobe ipmi_si ipmi_ssif ipmi_devintf ipmi_msghandler || ( modprobe ipmi_si ipmi_ssif ipmi_devintf ipmi_msghandler || (
echo "unable to load IPMI kernel modules: skipping IPMI configuration" echo "Unable to load IPMI kernel modules: skipping IPMI configuration"
exit exit
) )
if [ ! -e /dev/ipmi0 ]; then if [ ! -e /dev/ipmi0 ]; then
echo "/dev/ipmi0 does not exist; creating..."
sleep 1 sleep 1
ipmi_dev=$(grep ipmidev /proc/devices | awk '{ print $1 }') ipmi_dev=$(grep ipmidev /proc/devices | awk '{ print $1 }')
mknod -m 0666 /dev/ipmi0 c "$ipmi_dev" 0 mknod -m 0666 /dev/ipmi0 c "$ipmi_dev" 0
@@ -83,7 +88,7 @@ if [ -n "$WWIPMI_PASSWORD" ]; then
fi fi
fi fi
# Serial Over LAN echo "Configuring Serial over LAN..."
ipmitool channel setaccess 1 2 link=on ipmi=on callin=on privilege=4 ipmitool channel setaccess 1 2 link=on ipmi=on callin=on privilege=4
ipmitool sol set force-encryption true 1 ipmitool sol set force-encryption true 1
ipmitool sol set force-authentication true 1 ipmitool sol set force-authentication true 1

View File

@@ -2,23 +2,19 @@
. /warewulf/config . /warewulf/config
# This will eventually be optional echo "Warewulf prescript: VNFS fixes"
if true; then echo
if [ -f "/etc/pam.d/system-auth" ]; then
echo "FIXING: system-auth"
sed -i -e '/^account.*pam_unix\.so\s*$/s/\s*$/\ broken_shadow/' /etc/pam.d/system-auth
fi
if [ -f "/etc/pam.d/password-auth" ]; then add_broken_shadow() {
echo "FIXING: password-auth" if [ -f "${1}" ]; then
sed -i -e '/^account.*pam_unix\.so\s*$/s/\s*$/\ broken_shadow/' /etc/pam.d/password-auth echo "Adding broken_shadow to ${1}..."
fi sed -i -e '/^account.*pam_unix\.so\s*$/s/\s*$/\ broken_shadow/' "${1}"
if [ -f "/etc/pam.d/common-account" ]; then
echo "FIXING: common-account"
sed -i -e '/^account.*pam_unix\.so\s*$/s/\s*$/\ broken_shadow/' /etc/pam.d/common-account
fi
fi fi
}
add_broken_shadow /etc/pam.d/system-auth
add_broken_shadow /etc/pam.d/password-auth
add_broken_shadow /etc/pam.d/common-account
echo "Adjusting root directory permissions..."
chmod 755 / chmod 755 /

View File

@@ -2,32 +2,42 @@
. /warewulf/config . /warewulf/config
echo "Warewulf prescript: SELinux"
if test -f "/etc/sysconfig/selinux"; then if test -f "/etc/sysconfig/selinux"; then
. /etc/sysconfig/selinux . /etc/sysconfig/selinux
else else
echo "Skipping SELinux configuration: Host config not found: /etc/sysconfig/selinux" echo "File not found: /etc/sysconfig/selinux"
echo "Skipping SELinux configuration."
exit exit
fi fi
if test "$SELINUX" == "disabled"; then if [ "$SELINUX" = "disabled" ]; then
echo "Skipping SELinux setup per /etc/sysconfig/selinux" echo "/etc/sysconfig/selinux:SELINUX=${SELINUX}: skipping SELinux configuration."
exit exit
fi fi
if grep -q "selinux=0" /proc/cmdline; then if grep -q "selinux=0" /proc/cmdline; then
echo "Skipping SELinux setup per kernel command line" echo "/proc/cmdline:selinux=0: skipping SELinux configuration."
exit exit
fi fi
if [ $(findmnt / --noheadings --output SOURCE) == 'rootfs' ]; then if [ $(findmnt / --noheadings --output SOURCE) = 'rootfs' ]; then
echo "Skipping SELinux configuration: rootfs does not support SELinux contexts" echo "/ is a 'rootfs' file system, which does not support SELinux contexts."
echo "Skipping SELinux configuration."
echo echo
echo "WARNING: SELinux prep is being skipped, but SELinux is enabled on host! This may" echo "WARNING: SELinux configuration is being skipped, but SELinux is"
echo "WARNING: cause the system to not work properly. Try setting 'Root=tmpfs'" echo "WARNING: enabled in the image! The node will probably not boot"
sleep 5 echo "WARNING: properly."
echo "WARNING:"
echo "WARNING: Try setting 'Root=tmpfs'"
echo
echo "Continuing in 60s..."
sleep 60
exit exit
fi fi
echo "Setting up SELinux" echo "Loading SELinux policy..."
/sbin/load_policy -i /sbin/load_policy -i
echo "Restoring filesystem labels..."
/sbin/restorecon -e /sys -r / /sbin/restorecon -e /sys -r /

View File

@@ -1,17 +0,0 @@
#!/bin/sh
echo "Hello from WWINIT"
. /warewulf/config
myPATH=/warewulf/init.d
ls -1 $myPATH/ | while read -r NAME; do
echo "Launching: $NAME"
sh "$myPATH/$NAME"
done
echo "Calling $WWINIT..."
echo
sleep 2
exec $WWINIT

View File

@@ -0,0 +1,14 @@
#!/usr/bin/sh
. /warewulf/config
echo "Warewulf prescript runner (/warewulf/wwprescripts)"
scriptdir=/warewulf/init.d
echo "Looking for prescripts in /warewulf/init.d/..."
ls -1 "${scriptdir}/" | while read -r name; do
echo "Running prescript: ${name}..."
sh "${scriptdir}/${name}"
done
echo
echo "Running ${WWINIT}..."
exec $WWINIT