X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fsrc%2Finit;fp=cirros-testvm%2Fsrc-cirros%2Fsrc%2Finit;h=884b0f00ec39024a9ea200ae0b4612852f456f3e;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/src/init b/cirros-testvm/src-cirros/src/init new file mode 100755 index 0000000..884b0f0 --- /dev/null +++ b/cirros-testvm/src-cirros/src/init @@ -0,0 +1,93 @@ +#!/bin/sh +# vi: ts=4 noexpandtab +# +# This is the initramfs init script +ROOTFS_LABEL="cirros-rootfs" + +. /lib/cirros/shlib + +mkdir -p /proc /newroot /dev /tmp + +mount -t devtmpfs /dev /dev +mount -t proc /proc /proc + +echo "6 4 1 7" >/proc/sys/kernel/printk + +parse_cmdline + +for x in $KC_CONSOLES; do + [ "$x" = "$KC_CONSOLE" ] || + echo "further output written to $KC_CONSOLE" > "$x"; +done +if [ -n "$KC_PREF_CONSOLE" ]; then + exec >"$KC_PREF_CONSOLE" 2>&1 <"$KC_PREF_CONSOLE" +fi + +read uptime cputime < /proc/uptime +iinfo "initramfs: up at $uptime" + +idebug "loading modules" +/etc/init.d/load-modules start + +ROOT="" +MOUNTED="" + +if [ "$KC_RAMDISK_ROOT" != "1" ]; then + while read maj min blk name other; do + [ -n "${maj}" -a "${maj}" != "major" ] || continue + umount=0 + mount -o ro "/dev/${name}" "/newroot" >/dev/null 2>&1 && + MOUNTED="$MOUNTED ${name}" && umount=1 && + [ -x /newroot/sbin/init ] && ROOT="/dev/$name" && break + [ ${umount} -eq 0 ] || umount /newroot + done < /proc/partitions +fi + +if [ "$KC_DEBUG" = "1" ]; then + echo "dropping into initramfs debug shell" + /bin/sh +fi + +if [ -z "$ROOT" -a "$KC_RAMDISK_ROOT" != "1" ] && + blank=$(blkid -l -o device -t LABEL=$ROOTFS_LABEL) && + [ -e "$blank" ]; then + iinfo "copying initramfs to $blank" + items="" + set +f + for x in /*; do + case "$x" in + /dev|/proc|/newroot) : ;; + *) items="$items $x";; + esac + done + set -f + mount "$blank" /newroot + mkdir -p /newroot/dev /newroot/proc + cp -a $items /newroot/ + cp -a /dev/console /newroot/dev + mount -o remount,ro /newroot + ROOT="$blank" +fi + +if [ -n "$ROOT" ]; then + cd /newroot + mount -o move /dev ./dev + umount /proc + iinfo "initramfs loading root from $ROOT" + exec switch_root /newroot "$KC_INIT" "$@" +else + while read maj min blk name other; do + [ -n "${maj}" -a "${maj}" != "major" ] || continue + umount=0 + mount -o ro "/dev/${name}" "/newroot" >/dev/null 2>&1 && + umount=1 && + [ -x /newroot/sbin/init ] && ROOT="/dev/$name" && break + [ ${umount} -eq 0 ] || umount /newroot + done < /proc/partitions + umount /proc + [ "$KC_RAMDISK_ROOT" = "0" ] && + iinfo "initramfs did not find root, running as ramdisk" || + iinfo "running in ramdisk mode as requested" + exec "$KC_INIT" "$@" +fi +failure "badness occurred in ramdisk"