| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
| 4 |
|
| 5 |
if ! getargbool 0 rd.kiwi.ramdisk; then |
| 6 |
# we create a sysroot generator only for the special |
| 7 |
# ramdisk deployment case |
| 8 |
exit 0 |
| 9 |
fi |
| 10 |
|
| 11 |
root_cmdline=$(getarg root=) |
| 12 |
if [ -z "${root_cmdline}" ];then |
| 13 |
# if the root= parameter is missing there is no guarantee |
| 14 |
# that the /config.bootoptions file is present on local |
| 15 |
# storage at the time this generator code is called. This |
| 16 |
# case applies on PXE deployments which serves config.bootoptions |
| 17 |
# from the network. The mount process including config.bootoptions |
| 18 |
# paramters is then handled by the dracut |
| 19 |
# mount hook: kiwi-mount-ramdisk.sh |
| 20 |
exit 0 |
| 21 |
fi |
| 22 |
|
| 23 |
GENERATOR_DIR="$1" |
| 24 |
[ -z "${GENERATOR_DIR}" ] && exit 1 |
| 25 |
[ -d "${GENERATOR_DIR}" ] || mkdir -p "${GENERATOR_DIR}" |
| 26 |
|
| 27 |
[ -e /config.bootoptions ] || exit 1 |
| 28 |
|
| 29 |
root_uuid=$( |
| 30 |
awk '{ for(i=1; i <= NF; i++) {print $i } }' /config.bootoptions |\ |
| 31 |
grep root= | cut -f2- -d= |
| 32 |
) |
| 33 |
|
| 34 |
[ -z "${root_uuid}" ] && exit 2 |
| 35 |
|
| 36 |
{ |
| 37 |
echo "[Unit]" |
| 38 |
echo "Before=initrd-root-fs.target" |
| 39 |
echo "DefaultDependencies=no" |
| 40 |
echo "[Mount]" |
| 41 |
echo "Where=/sysroot" |
| 42 |
echo "What=${root_uuid}" |
| 43 |
_dev=$(systemd-escape -p /dev/disk/by-uuid/"${root_uuid#UUID=}") |
| 44 |
} > "$GENERATOR_DIR"/sysroot.mount |
| 45 |
|
| 46 |
if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.requires/sysroot.mount" ]; then |
| 47 |
mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires |
| 48 |
ln -s "$GENERATOR_DIR"/sysroot.mount \ |
| 49 |
"$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount |
| 50 |
fi |
| 51 |
|
| 52 |
mkdir -p "$GENERATOR_DIR/$_dev.device.d" |
| 53 |
{ |
| 54 |
echo "[Unit]" |
| 55 |
echo "JobTimeoutSec=infinity" |
| 56 |
} > "$GENERATOR_DIR/$_dev.device.d/timeout.conf" |