mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-26 04:12:17 +00:00
f1d8641672
A Subiquity layout written with "layout:" and no "match" goes to the largest disk. With a d: or s:d: entry in linuximage.partitionfile, that disk need not be the one the entry selected, so the install could wipe a disk the entry was meant to keep it off. When a disk entry is configured, give such a layout a match on the selected disk. Refuse a use_gap layout in that case, because some Subiquity releases ignore match in use_gap mode and would install into free space on another disk. A layout with its own match, a "config:" layout and a layout without a disk entry are kept as written.
397 lines
11 KiB
Plaintext
397 lines
11 KiB
Plaintext
export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#"
|
|
if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then
|
|
set -x
|
|
fi
|
|
|
|
#!/bin/sh
|
|
|
|
# syslog is probably running from the syslog.socket service
|
|
systemctl stop syslog.socket
|
|
systemctl stop rsyslog
|
|
# however, lets make sure . . .
|
|
[ -e /var/run/rsyslogd.pid ] && kill -TERM $(cat /var/run/rsyslogd.pid)
|
|
# bare minimum rsyslog.conf to support UDP forwarding. Newer Ubuntu releases
|
|
# run rsyslog under AppArmor and do not allow a config file from /tmp.
|
|
cat <<EOF > /etc/rsyslog.conf
|
|
module(load="imuxsock")
|
|
module(load="imklog" permitnonkernelfacility="on")
|
|
*.* @#XCATVAR:XCATMASTER#
|
|
EOF
|
|
rsyslogd -f /etc/rsyslog.conf
|
|
log_label="xcat.deployment"
|
|
logger -t $log_label -p "info" "============deployment starting============"
|
|
logger -t $log_label -p "info" "Running preseeding early_command Installation script..."
|
|
if [ ! -c /dev/vcs ]; then
|
|
mknod /dev/vcs c 7 0
|
|
fi
|
|
|
|
cat >/tmp/foo.sh <<EOF
|
|
#!/bin/sh
|
|
|
|
#
|
|
# If no arguments:
|
|
#
|
|
# 1) Start child process to connect as client to master, and re-execute this script to send
|
|
# "installmonitor" to master. Do not wait for child process.
|
|
#
|
|
# 2) Loop forever. For each iteration, start child process as server waiting for a client
|
|
# connection. Once a connection is established, child process re-executes this script to
|
|
# handle request from that particular client.
|
|
#
|
|
|
|
if [ \$# -eq 0 ]; then
|
|
xcatdhost="#XCATVAR:XCATMASTER#"
|
|
xcatdport="#TABLE:site:key=xcatiport:value#"
|
|
NODESTATUS="#TABLEBLANKOKAY:site:key=nodestatus:value#"
|
|
|
|
|
|
/usr/bin/nc "\$xcatdhost" "\$xcatdport" -e /tmp/foo.sh install_monitor &
|
|
|
|
if [ -z "\$NODESTATUS" ] || [ "\$NODESTATUS" != "0" -a "\$NODESTATUS" != "N" -a "\$NODESTATUS" != "n" ];
|
|
then
|
|
|
|
/usr/bin/nc "\$xcatdhost" "\$xcatdport" -e /tmp/foo.sh installstatus installing &
|
|
|
|
fi
|
|
|
|
while true; do
|
|
/usr/bin/nc -l -p 3054 -e /tmp/foo.sh serve_client
|
|
done
|
|
|
|
exit 1 # never reached; reboot ends this
|
|
fi
|
|
|
|
#
|
|
# If the script was called with the "install_monitor" argument, stdin and stdout are
|
|
# connected to an xCAT daemon on the master. Write the "installmonitor" request to the
|
|
# daemon.
|
|
#
|
|
|
|
if [ "\$1" = "install_monitor" ]; then
|
|
cmd=""
|
|
while [ "\$cmd" != "done" ]; do
|
|
read cmd remainder
|
|
|
|
if [ "\$cmd" == "ready" ]; then
|
|
echo "installmonitor"
|
|
fi
|
|
done
|
|
|
|
exit 0
|
|
fi
|
|
|
|
#
|
|
# If the script was called with the "installstatus" argument, stdin and stdout are
|
|
# connected to an xCAT daemon on the master.
|
|
# Write the "installstatus xx" request to the daemon to update thenode installation status.
|
|
if [ "\$1" = "installstatus" ]; then
|
|
cmd=""
|
|
while [ "\$cmd" != "done" ]; do
|
|
read cmd remainder
|
|
|
|
if [ "\$cmd" == "ready" ]; then
|
|
echo "installstatus \$2"
|
|
fi
|
|
done
|
|
|
|
exit 0
|
|
fi
|
|
|
|
|
|
|
|
|
|
#
|
|
# When execution reaches here, script called with "serve_client" argument, which means
|
|
# stdin and stdout are connected to a client. Read the request from the client, provide
|
|
# the answer to the client, and terminate.
|
|
#
|
|
|
|
read cmd arg remainder
|
|
|
|
case "\$cmd" in
|
|
#UNCOMMENTOENABLEDEBUGPORT# "sh") #TODO: ENABLE IF DEBUG
|
|
#UNCOMMENTOENABLEDEBUGPORT# output=\$(eval \$arg \$remainder)
|
|
#UNCOMMENTOENABLEDEBUGPORT# echo "\$output"
|
|
#UNCOMMENTOENABLEDEBUGPORT# echo "EOO"
|
|
#UNCOMMENTOENABLEDEBUGPORT# ;;
|
|
|
|
"screendump")
|
|
output=\$(eval chvt \$arg; cat /dev/vcs)
|
|
echo "\$output"
|
|
;;
|
|
|
|
"stat")
|
|
sedcmds='/^[^ ]+ +[^ ]+ +install /h; \${ g; s,^[^ ]+ +[^ ]+ +install +([^ ]+) +[^ ]+ ([^ ]+).*,installing \1 \2,; p }'
|
|
output=\$(sed -nre "\$sedcmds" /target/var/log/dpkg.log 2>/dev/null)
|
|
|
|
if [ -z "\$output" ]; then
|
|
output="installing prep"
|
|
fi
|
|
|
|
echo "\$output"
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
|
|
chmod 755 /tmp/foo.sh
|
|
|
|
/tmp/foo.sh >/tmp/foo.log 2>&1 &
|
|
|
|
# Subiquity runs this script under dash, which has no read -n, and its live system ships coreutils.
|
|
base64decode()
|
|
{
|
|
base64 -d
|
|
}
|
|
|
|
# A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose.
|
|
rm -f /tmp/diskscript.enc
|
|
[ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected
|
|
#XCA_PARTMAN_DISK_SCRIPT#
|
|
override_rc=$?
|
|
disk_entry=""
|
|
if [ -e /tmp/diskscript.enc ]; then
|
|
disk_entry=1
|
|
# Falling back to the detected disk could wipe the disk the entry protects.
|
|
if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then
|
|
logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install"
|
|
exit 1
|
|
fi
|
|
elif [ -e /tmp/xcat.install_disk.detected ]; then
|
|
mv /tmp/xcat.install_disk.detected /tmp/xcat.install_disk
|
|
fi
|
|
|
|
# Note that the subiquity/curtin installation config is fairly picky about
|
|
# the order in which things are specified - you have to specify all the
|
|
# partitions before you can specify any filesystems, which means this is
|
|
# hard to stitch together piecemeal. Instead we just do everything in
|
|
# separate blocks . . .
|
|
#
|
|
# Also note that only /one/ partition can be given a variable size, and it
|
|
# must be the last partition on the disk - this forces us to put swap before
|
|
# the main root partition, and forces us to have a fixed size swap partition
|
|
#
|
|
# Subiquity re-serializes /autoinstall.yaml after the first load,
|
|
# stripping the autoinstall: wrapper. The storage block is appended
|
|
# to this unwrapped file and must start at column 0.
|
|
logger -t $log_label -p "info" "Generate partition file..."
|
|
if [ -e /tmp/xcat.install_disk ]; then
|
|
# The layout uses one disk, the first one the disk file names.
|
|
INSTALL_DISK=$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk)
|
|
# Subiquity matches the disk path literally, so resolve a link such as /dev/disk/by-id/.
|
|
INSTALL_DISK=$(readlink -f "$INSTALL_DISK" || echo "$INSTALL_DISK")
|
|
else
|
|
logger -t $log_label -p "err" "Failed to find partition file - getinstdisk must be run first"
|
|
logger -t $log_label -p "err" "Using fallback default disk /dev/sda"
|
|
INSTALL_DISK="/dev/sda"
|
|
fi
|
|
|
|
if [ -d /sys/firmware/efi ]; then
|
|
cat <<EOF >/tmp/partitionfile
|
|
storage:
|
|
version: 1
|
|
config:
|
|
- id: disk-detected
|
|
type: disk
|
|
ptable: gpt
|
|
path: $INSTALL_DISK
|
|
wipe: superblock-recursive
|
|
preserve: false
|
|
- id: efi-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: 512M
|
|
flag: boot
|
|
number: 1
|
|
preserve: false
|
|
grub_device: true
|
|
- id: swap-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: 2G
|
|
number: 2
|
|
preserve: false
|
|
- id: root-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: -1
|
|
wipe: superblock
|
|
number: 3
|
|
preserve: false
|
|
- id: efi-part-fs
|
|
type: format
|
|
fstype: fat32
|
|
volume: efi-part
|
|
preserve: false
|
|
- id: swap-part-fs
|
|
type: format
|
|
fstype: swap
|
|
volume: swap-part
|
|
preserve: false
|
|
- id: root-part-fs
|
|
type: format
|
|
fstype: ext4
|
|
volume: root-part
|
|
preserve: false
|
|
- id: efi-part-mount
|
|
type: mount
|
|
path: /boot/efi
|
|
device: efi-part-fs
|
|
- id: swap-part-mount
|
|
type: mount
|
|
path: none
|
|
device: swap-part-fs
|
|
- id: root-part-mount
|
|
type: mount
|
|
path: /
|
|
device: root-part-fs
|
|
EOF
|
|
elif [ "$(uname -m)" = "ppc64le" ] || [ "$(uname -m)" = "ppc64" ]; then
|
|
# POWER firmware reads neither an ESP nor a bios_grub partition. It loads the
|
|
# boot loader from a PReP partition, and curtin writes grub to the partition
|
|
# flagged prep, not to the disk.
|
|
cat <<EOF >/tmp/partitionfile
|
|
storage:
|
|
version: 1
|
|
config:
|
|
- id: disk-detected
|
|
type: disk
|
|
ptable: gpt
|
|
path: $INSTALL_DISK
|
|
wipe: superblock-recursive
|
|
preserve: false
|
|
- id: prep-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: 8M
|
|
flag: prep
|
|
number: 1
|
|
preserve: false
|
|
grub_device: true
|
|
- id: swap-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: 2G
|
|
number: 2
|
|
preserve: false
|
|
- id: root-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: -1
|
|
wipe: superblock
|
|
number: 3
|
|
preserve: false
|
|
- id: swap-part-fs
|
|
type: format
|
|
fstype: swap
|
|
volume: swap-part
|
|
preserve: false
|
|
- id: root-part-fs
|
|
type: format
|
|
fstype: ext4
|
|
volume: root-part
|
|
preserve: false
|
|
- id: swap-part-mount
|
|
type: mount
|
|
path: none
|
|
device: swap-part-fs
|
|
- id: root-part-mount
|
|
type: mount
|
|
path: /
|
|
device: root-part-fs
|
|
EOF
|
|
else
|
|
cat <<EOF >/tmp/partitionfile
|
|
storage:
|
|
version: 1
|
|
config:
|
|
- id: disk-detected
|
|
type: disk
|
|
ptable: gpt
|
|
path: $INSTALL_DISK
|
|
wipe: superblock-recursive
|
|
preserve: false
|
|
grub_device: true
|
|
- id: bios-grub
|
|
type: partition
|
|
device: disk-detected
|
|
size: 1M
|
|
flag: bios_grub
|
|
number: 1
|
|
preserve: false
|
|
- id: swap-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: 2G
|
|
number: 2
|
|
preserve: false
|
|
- id: root-part
|
|
type: partition
|
|
device: disk-detected
|
|
size: -1
|
|
wipe: superblock
|
|
number: 3
|
|
preserve: false
|
|
- id: swap-part-fs
|
|
type: format
|
|
fstype: swap
|
|
volume: swap-part
|
|
preserve: false
|
|
- id: root-part-fs
|
|
type: format
|
|
fstype: ext4
|
|
volume: root-part
|
|
preserve: false
|
|
- id: swap-part-mount
|
|
type: mount
|
|
path: none
|
|
device: swap-part-fs
|
|
- id: root-part-mount
|
|
type: mount
|
|
path: /
|
|
device: root-part-fs
|
|
EOF
|
|
fi
|
|
|
|
# Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment
|
|
# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing,
|
|
# and a layout without a match goes to the largest disk too, so it gets the disk in $2, if any.
|
|
# Some Subiquity releases ignore match in use_gap mode, so such a layout is refused with $2.
|
|
normalize_storage_layout()
|
|
{
|
|
python3 -c 'import sys, yaml
|
|
s = yaml.safe_load(open(sys.argv[1]))
|
|
t = s.get("storage") if isinstance(s, dict) else None
|
|
if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))):
|
|
sys.exit(1)
|
|
l = t.get("layout")
|
|
if sys.argv[2] and isinstance(l, dict):
|
|
if l.get("mode") == "use_gap":
|
|
sys.exit(1)
|
|
l.setdefault("match", {"path": sys.argv[2]})
|
|
open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" "$2" 2>/dev/null
|
|
}
|
|
|
|
# A partitionfile layout or s: script must come after the default layout, which it replaces.
|
|
rm -f /tmp/partscript.enc
|
|
mv /tmp/partitionfile /tmp/partitionfile.default
|
|
#XCA_PARTMAN_RECIPE_SCRIPT#
|
|
override_rc=$?
|
|
if [ -e /tmp/partscript.enc ]; then
|
|
# Keeping the default layout could wipe a disk the administrator layout protects.
|
|
if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile "${disk_entry:+$INSTALL_DISK}"; then
|
|
logger -t $log_label -p "err" "The partitionfile layout entry wrote no usable layout, stopping the install"
|
|
rm -f /tmp/partitionfile
|
|
exit 1
|
|
fi
|
|
else
|
|
mv /tmp/partitionfile.default /tmp/partitionfile
|
|
fi
|
|
#XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT#
|
|
exit 0
|
|
|
|
if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then
|
|
set +x
|
|
fi
|