This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
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
96 changes: 96 additions & 0 deletions
96
mkosi.extra-iscsi/usr/lib/systemd/system-generators/iscsi-generator.sh
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Format: | ||
# root=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname> | ||
# [root=*] netroot=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname> | ||
# | ||
# root= takes precedence over netroot= if root=iscsi[...] | ||
|
||
# Example: | ||
# netroot=iscsi:10.10.10.1::::iqn.2022-01.com.example:iscsi.initrd.test | ||
# /dev/disk/by-path/ip-10.10.10.1:3260-iscsi-iqn.2022-01.com.example:iscsi.initrd.test-lun-1 | ||
# /dev/disk/by-path/ip-10.10.10.1:3260-iscsi-iqn.2022-01.com.example:iscsi.initrd.test-lun-1-part1 | ||
# /dev/disk/by-path/ip-<servername>:<port>-iscsi-<lun>-<targetname>-lun-<lun> | ||
|
||
root= | ||
specs=() | ||
|
||
cmdline="${SYSTEMD_PROC_CMDLINE:-$(cat /proc/cmdline)}" | ||
|
||
for arg in $cmdline; do | ||
if [[ $arg == "root="* ]]; then | ||
# The last root= assignment wins. | ||
root="${arg#*=}" | ||
elif [[ $arg == "netroot=iscsi:"* ]]; then | ||
value="${arg#*=}" | ||
# All netroot= invocations matter. | ||
specs+=( "$value" ) | ||
|
||
if [ -z "$root" ]; then | ||
root="$value" | ||
fi | ||
fi | ||
done | ||
|
||
if [[ $root == "iscsi:"* ]]; then | ||
specs+=( "$root" ) | ||
fi | ||
|
||
if [ ${#specs[@]} -eq 0 ]; then | ||
# nothing for us to do | ||
exit 0 | ||
fi | ||
|
||
make_unit() { | ||
# Handle the root= argument | ||
if [[ $root == "iscsi:" ]]; then | ||
: # TODO | ||
fi | ||
|
||
service="${dest_normal}/initrd-iscsi-auto.service" | ||
this="$(realpath "$0")" | ||
cat >"${service}" <<EOF | ||
# generated by $this | ||
[Unit] | ||
Description=Poke iscsid to bring up iscsi devices | ||
DefaultDependencies=no | ||
Wants=iscsid.socket | ||
Wants=iscsiuio.socket | ||
Before=initrd-root-device.target | ||
Conflicts=shutdown.target | ||
Before=shutdown.target | ||
[Service] | ||
Type=oneshot | ||
ExecStart=$this --go | ||
EOF | ||
|
||
mkdir -p "${dest_normal}/initrd-root-device.target.requires" | ||
ln -s "../initrd-iscsi-auto.service" "${dest_normal}/initrd-root-device.target.requires/" | ||
} | ||
|
||
do_things() { | ||
for spec in "${specs[@]}"; do | ||
server=$(echo "$spec" | cut -d: -f1) | ||
# protocol? | ||
port=$(echo "$spec" | cut -d: -f3) | ||
lun=$(echo "$spec" | cut -d: -f4) | ||
target=$(echo "$spec" | cut -d: -f5-) | ||
|
||
echo "$spec: will start server=$server port=$port lun=$lun target=$target" | ||
|
||
iscsiadm -m discovery -t st -p "${server}${port:+:$port}" | ||
iscsiadm -m node -T "$target" -l | ||
done | ||
} | ||
|
||
if [ "${1:?}" == '--go' ]; then | ||
do_things | ||
else | ||
# invoked as generator | ||
dest_normal=${1:?} | ||
|
||
make_unit | ||
fi |