Last active
June 21, 2024 09:25
-
-
Save yoheiueda/c328ca7eccf313dd03292aeca71fbd02 to your computer and use it in GitHub Desktop.
zipl.wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
tools_dir=/usr/lib/s390-tools | |
if [[ -e /run/bootc/mounts/rootfs/boot ]]; then | |
mount --bind /run/bootc/mounts/rootfs/boot /boot | |
elif [[ -e /run/osbuild/mounts ]]; then | |
mount --bind /run/osbuild/mounts/boot /boot | |
mkdir /run/osbuild/mounts/s390-tools | |
mount --bind /usr/lib/s390-tools /run/osbuild/mounts/s390-tools | |
mount -o remount,rw /run/osbuild/mounts/s390-tools | |
tools_dir=/run/osbuild/mounts/s390-tools | |
fi | |
cat <<'END' > "$tools_dir/zipl_helper.blkext" | |
#!/bin/bash -x | |
case "$1" in | |
*:*) devno=$1 ;; | |
*) devno=$(findmnt -r -n -o MAJ:MIN --target "$1" | tail -n1) ;; | |
esac | |
if [[ -z "$devno" ]]; then | |
echo "$0: devno major:minor is not specified" 1>&2 | |
exit 1 | |
fi | |
sysdev_path="/sys/dev/block/$devno" | |
if [[ ! -e "$sysdev_path" ]]; then | |
echo "$0: device not found: $sysdev_path" 1>&2 | |
exit 1 | |
fi | |
if [[ ! -e "$sysdev_path/partition" ]]; then | |
echo "$0: not a partition: $sysdev_path" 1>&2 | |
exit 1 | |
fi | |
link_path=$(readlink "$sysdev_path") | |
if [[ -z "$link_path" ]]; then | |
echo "$0: failed to read a symlink: $sysdev_path" 1>&2 | |
exit 1 | |
fi | |
parent_path=$(dirname "$link_path") | |
if [[ -z "$parent_path" ]]; then | |
echo "$0: failed to identify whole disk device: $link_path" 1>&2 | |
exit 1 | |
fi | |
parent_name=$(basename "$parent_path") | |
if [[ -z "$parent_name" ]]; then | |
echo "$0: failed to identify whole disk device name: $parent_path" 1>&2 | |
exit 1 | |
fi | |
parent_sysblock_path="/sys/block/$parent_name" | |
if [[ ! -e "$parent_sysblock_path" ]]; then | |
echo "$0: whole disk device not found: $parent_sysblock_path" 1>&2 | |
exit 1 | |
fi | |
if [[ ! -e "$parent_sysblock_path/loop" ]]; then | |
echo "$0: not a loop device: $parent_sysblock_path" 1>&2 | |
exit 1 | |
fi | |
parent_dev_path="/dev/$parent_name" | |
if [[ ! -e "$parent_dev_path" ]]; then | |
echo "$0: not found: $parent_dev_path" 1>&2 | |
exit 1 | |
fi | |
dev_name=$(lsblk -J "$parent_dev_path" | jq -r --arg devno "$devno" '.blockdevices[0].children[] | select(.["maj:min"]==$devno) | .name') | |
offset=$(sfdisk -J "$parent_dev_path"| jq -r --arg part "/dev/$dev_name" '.partitiontable.partitions[] | select(.node==$part) | .start') | |
echo "targetbase=$parent_dev_path" | |
echo "targettype=scsi" | |
echo "targetblocksize=512" | |
echo "targetoffset=$offset" | |
END | |
chmod 755 "$tools_dir/zipl_helper.blkext" | |
/usr/sbin/zipl.bin "$@" | |
rc=$? | |
rm -f "$tools_dir/zipl_helper.blkext" | |
if [[ -e /run/osbuild/mounts/s390-tools ]]; then | |
umount /run/osbuild/mounts/s390-tools | |
rmdir /run/osbuild/mounts/s390-tools | |
fi | |
umount /boot | |
exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment