about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJuan RP <xtraeme@gmail.com>2014-08-07 17:22:57 +0200
committerJuan RP <xtraeme@gmail.com>2014-08-07 17:22:57 +0200
commit53a09fa9d57bad1b074d0f72a302ffc4517d4b0f (patch)
tree0fbaaa59a8e1eb3669bb4ad6bd7925aa493f5253
parent18ae61d8157af26fb58041bdfcf8cc405f1a2157 (diff)
downloadrunit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.tar.gz
runit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.tar.xz
runit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.zip
Added "core" services that are run from scripts on stage 1.
- /etc/runit/functions: contains common functions to be used in core-services.
- /etc/runit/core-services: directory containing one-time tasks run in stage 1.
- Added LXC container detection to disable some core services.

This accidentally also fixes the issue of unicode not working in the active
TTY from stage 1.
-rwxr-xr-x1167
-rwxr-xr-x23
-rwxr-xr-x330
-rw-r--r--Makefile17
-rwxr-xr-xcore-services/00-pseudofs.sh17
-rwxr-xr-xcore-services/02-udev.sh23
-rwxr-xr-xcore-services/03-filesystems.sh49
-rwxr-xr-xcore-services/04-swap.sh10
-rwxr-xr-xcore-services/05-misc.sh25
-rwxr-xr-xcore-services/06-console-setup.sh22
-rwxr-xr-xcore-services/07-kmods.sh11
-rwxr-xr-xcore-services/08-sysctl.sh10
-rwxr-xr-xcore-services/99-cleanup.sh9
-rwxr-xr-xfunctions35
14 files changed, 245 insertions, 183 deletions
diff --git a/1 b/1
index 34b68c5..2f437ed 100755
--- a/1
+++ b/1
@@ -1,176 +1,19 @@
 #!/bin/sh
 # vim: set ts=4 sw=4 et:
 
-msg() {
-    # bold
-    printf "\033[1m=> $@\033[m"
-}
-
-msg_ok() {
-    # bold/green
-    printf "\033[1m\033[32m OK\033[m\n"
-}
-
-msg_error() {
-    # bold/red
-    printf "\033[1m\033[31mERROR: $@\033[m\n"
-}
-
-msg_warn() {
-    # bold/yellow
-    printf "\033[1m\033[33mWARNING: $@\033[m"
-}
-
-emergency_shell() {
-    echo
-    echo "Cannot continue due to errors above, starting emergency shell."
-    echo "When ready type exit to continue booting."
-    /bin/sh -l
-}
-
 PATH=/usr/bin:/usr/sbin
 
-# re-exec this script with a controlling tty
-if [ $(tty) = /dev/console ]; then
-    mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
-    tty=$(cat /sys/class/tty/console/active)
-    exec setsid sh -c "exec sh /etc/runit/1 < /dev/$tty > /dev/$tty 2>&1"
-fi
+. /etc/runit/functions
 
 msg "Welcome to Void!\n"
 
 [ -r /etc/rc.conf ] && . /etc/rc.conf
 
-msg "Mounting pseudo-filesystems...\n"
-mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
-mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
-mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
-mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
-mkdir -p -m0755 /run/runit /run/lvm /run/user /dev/pts /dev/shm
-mountpoint -q /dev/pts || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
-mountpoint -q /dev/shm || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
-
-msg "Remounting rootfs read-only...\n"
-mount -o remount,ro / || emergency_shell
-
-msg "Setting up TTYs to unicode mode...\n"
-for i in /dev/tty[0-6]; do
-    unicode_start < $i || emergency_shell
+# Start core services: one-time system tasks.
+detect_virt
+for f in /etc/runit/core-services/*.sh; do
+    [ -x $f ] && $f
 done
-if [ -n "$FONT" ]; then
-    msg "Setting up TTYs font to '${FONT}'...\n"
-    for i in /dev/tty[0-6]; do
-        setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} $FONT -C $i || emergency_shell
-    done
-fi
-
-msg "Setting up keymap to '${KEYMAP:-us}'...\n"
-loadkeys -q -u ${KEYMAP:-us} || emergency_shell
-
-if [ -n "$HARDWARECLOCK" ]; then
-    msg "Setting up RTC to '${HARDWARECLOCK}'...\n"
-    TZ=$TIMEZONE hwclock --systz \
-        ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z) --noadjfile} || emergency_shell
-fi
-
-if [ -x /usr/lib/systemd/systemd-udevd ]; then
-    _udevd=/usr/lib/systemd/systemd-udevd
-elif [ -x /usr/sbin/udevd ]; then
-    _udevd=/usr/sbin/udevd
-else
-    msg_warn "cannot find udevd!\n"
-fi
-
-if [ -n "${_udevd}" ]; then
-    msg "Starting udev and waiting for devices to settle...\n"
-    { ${_udevd} --daemon;
-        udevadm trigger --action=add --type=subsystems;
-        udevadm trigger --action=add --type=devices;
-        udevadm settle; } || emergency_shell
-fi
-
-msg "Setting up loopback interface...\n"
-ip link set up dev lo || emergency_shell
-
-if [ -n "$HOSTNAME" ]; then
-    echo "$HOSTNAME" > /proc/sys/kernel/hostname
-elif [ -r /etc/hostname ]; then
-    HOSTNAME=$(cat /etc/hostname)
-    echo "$HOSTNAME" > /proc/sys/kernel/hostname
-fi
-msg "Setting up hostname to '${HOSTNAME}'...\n"
-
-if [ -x /usr/sbin/dmraid ]; then
-    msg "Activating dmraid devices...\n"
-    dmraid -i -ay || emergency_shell
-fi
-
-if [ -x /usr/bin/btrfs ]; then
-    msg "Activating btrfs devices...\n"
-    btrfs device scan || emergency_shell
-fi
-
-if [ -x /usr/sbin/vgchange ]; then
-    msg "Activating LVM devices...\n"
-    vgchange --sysinit -a y || emergency_shell
-fi
-
-if [ -e /etc/crypttab ]; then
-    msg "Activating encrypted devices...\n"
-    awk '/^#/ || /^$/ { next }
-         NF>2 { print "unsupported crypttab: " $0 >"/dev/stderr"; next }
-         { system("cryptsetup luksOpen " $2 " " $1) }' /etc/crypttab
-
-    if [ -x /usr/sbin/vgchange ]; then
-      msg "Activating LVM devices...\n"
-      vgchange --sysinit -a y || emergency_shell
-    fi
-fi
-
-msg "Checking filesystems:\n"
-fsck -A -T -a -t noopts=_netdev
-if [ $? -gt 1 ]; then
-    emergency_shell
-fi
-
-msg "Mounting rootfs read-write...\n"
-mount -o remount,rw / || emergency_shell
-
-msg "Mounting all non-network filesystems...\n"
-mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
-
-mountpoint -q /sys/fs/cgroup || mount -t tmpfs cgroup /sys/fs/cgroup -o mode=0755
-awk '$4==1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || mount -t cgroup -o " $1 ",x-mount.mkdir cgroup /sys/fs/cgroup/" $1) }' /proc/cgroups
-
-msg "Initializing swap...\n"
-swapon -a || emergency_shell
-
-if [ -x /usr/sbin/vgchange ]; then
-    vgchange --monitor y || emergency_shell
-fi
-
-if [ -n "$TIMEZONE" ]; then
-    msg "Setting up timezone to '${TIMEZONE}'...\n"
-    ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
-fi
-
-msg "Initializing random seed...\n"
-cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
-( umask 077; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 >/dev/null 2>&1 )
-
-install -m0664 -o root -g utmp /dev/null /run/utmp
-install -d -m1777 /tmp/.X11-unix /tmp/.ICE-unix
-
-rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot
-
-msg "Loading kernel modules...\n"
-modules-load -v ${MODULES} | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
-echo
-
-if [ -x /sbin/sysctl ]; then
-    msg "Loading sysctl(8) settings...\n"
-    sysctl --system
-fi
 
 dmesg >/var/log/dmesg.log
 
diff --git a/2 b/2
index e7357cc..8440f19 100755
--- a/2
+++ b/2
@@ -10,9 +10,6 @@ for arg in $(cat /proc/cmdline); do
     esac
 done
 
-# Setup first tty as unicode again, stage1 does not work correctly for tty1.
-unicode_start
-
 [ -x /etc/rc.local ] && /etc/rc.local
 
 # Create runlevel and then make it the default.
diff --git a/3 b/3
index 577568d..05fae3c 100755
--- a/3
+++ b/3
@@ -3,43 +3,51 @@
 
 PATH=/usr/bin:/usr/sbin
 
-. /etc/rc.conf
+. /etc/runit/functions
+detect_virt
+[ -r /etc/rc.conf ] && . /etc/rc.conf
 
 if [ -e /run/runit/reboot ]; then
     touch /etc/runit/reboot
     chmod 100 /etc/runit/reboot
 fi
 
-echo "Waiting for services to stop..."
+echo
+msg "Waiting for services to stop...\n"
 sv -w196 force-stop /var/service/*
 sv exit /var/service/*
 
 stty onlcr
 
-echo "Saving random seed..."
+msg "Saving random seed...\n"
 dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 >/dev/null 2>&1
 
-if [ -n "$HARDWARECLOCK" ]; then
+if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
     hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
 fi
 
 halt -w  # for utmp
 
-echo "Stopping udev..."
-udevadm control --exit
+if [ -z "$VIRTUALIZATION" ]; then
+    msg "Stopping udev...\n"
+    udevadm control --exit
+fi
 
-echo "Sending TERM signal to processes..."
+msg "Sending TERM signal to processes...\n"
 pkill --inverse -s0,1 -TERM
 sleep 5
-echo "Sending KILL signal to processes..."
+msg "Sending KILL signal to processes...\n"
 pkill --inverse -s0,1 -KILL
 
-echo "Unmounting filesystems, disabling swap..."
+msg "Unmounting filesystems, disabling swap...\n"
 umount /tmp
 swapoff -a
 umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
 
-echo "Remounting rootfs read-only..."
-mount -o remount,ro /
+if [ -z "$VIRTUALIZATION" ]; then
+    msg "Remounting rootfs read-only...\n"
+    mount -o remount,ro /
+fi
+
 sleep 1
 sync
diff --git a/Makefile b/Makefile
index 315b4b4..bbe6430 100644
--- a/Makefile
+++ b/Makefile
@@ -12,22 +12,25 @@ install:
 	install -m755 shutdown.sh ${DESTDIR}/${PREFIX}/bin/shutdown
 	install -m755 modules-load ${DESTDIR}/${PREFIX}/bin/modules-load
 	install -m755 zzz ${DESTDIR}/${PREFIX}/bin
-	ln -s zzz ${DESTDIR}/${PREFIX}/bin/ZZZ
-	ln -s halt ${DESTDIR}/${PREFIX}/bin/poweroff
-	ln -s halt ${DESTDIR}/${PREFIX}/bin/reboot
+	ln -sf zzz ${DESTDIR}/${PREFIX}/bin/ZZZ
+	ln -sf halt ${DESTDIR}/${PREFIX}/bin/poweroff
+	ln -sf halt ${DESTDIR}/${PREFIX}/bin/reboot
 	install -d ${DESTDIR}/${PREFIX}/share/man/man1
 	install -m644 pause.1 ${DESTDIR}/${PREFIX}/share/man/man1
 	install -d ${DESTDIR}/${PREFIX}/share/man/man8
 	install -m644 zzz.8 ${DESTDIR}/${PREFIX}/share/man/man8
 	install -m644 shutdown.8 ${DESTDIR}/${PREFIX}/share/man/man8
 	install -m644 halt.8 ${DESTDIR}/${PREFIX}/share/man/man8
-	ln -s halt.8 ${DESTDIR}/${PREFIX}/share/man/man8/poweroff.8
-	ln -s halt.8 ${DESTDIR}/${PREFIX}/share/man/man8/reboot.8
+	ln -sf halt.8 ${DESTDIR}/${PREFIX}/share/man/man8/poweroff.8
+	ln -sf halt.8 ${DESTDIR}/${PREFIX}/share/man/man8/reboot.8
 	install -d ${DESTDIR}/etc/sv
 	install -d ${DESTDIR}/etc/runit/runsvdir
+	install -d ${DESTDIR}/etc/runit/core-services
+	install -m755 core-services/*.sh ${DESTDIR}/etc/runit/core-services
 	install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
-	install -m644 rc.conf ${DESTDIR}/etc
-	install -m755 rc.local ${DESTDIR}/etc
+	install -m644 functions $(DESTDIR)/etc/runit
+	#[ ! -f $(DESTDIR)/etc/rc.conf ] && install -m644 rc.conf ${DESTDIR}/etc
+	#[ ! -f $(DESTDIR)/etc/rc.local ] && install -m755 rc.local ${DESTDIR}/etc
 	install -d ${DESTDIR}/${PREFIX}/lib/dracut/dracut.conf.d
 	install -m644 dracut/*.conf ${DESTDIR}/${PREFIX}/lib/dracut/dracut.conf.d
 	cp -aP runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
diff --git a/core-services/00-pseudofs.sh b/core-services/00-pseudofs.sh
new file mode 100755
index 0000000..f0da22f
--- /dev/null
+++ b/core-services/00-pseudofs.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+PATH=/usr/bin:/usr/sbin
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+msg "Mounting pseudo-filesystems...\n"
+mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
+mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
+mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
+mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
+mkdir -p -m0755 /run/runit /run/lvm /run/user /dev/pts /dev/shm
+mountpoint -q /dev/pts || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
+mountpoint -q /dev/shm || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
+mountpoint -q /sys/fs/cgroup || mount -t tmpfs cgroup /sys/fs/cgroup -o mode=0755
+awk '$4==1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || mount -t cgroup -o " $1 ",x-mount.mkdir cgroup /sys/fs/cgroup/" $1) }' /proc/cgroups
diff --git a/core-services/02-udev.sh b/core-services/02-udev.sh
new file mode 100755
index 0000000..1375209
--- /dev/null
+++ b/core-services/02-udev.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+if [ -x /usr/lib/systemd/systemd-udevd ]; then
+    _udevd=/usr/lib/systemd/systemd-udevd
+elif [ -x /usr/sbin/udevd ]; then
+    _udevd=/usr/sbin/udevd
+else
+    msg_warn "cannot find udevd!\n"
+fi
+
+if [ -n "${_udevd}" ]; then
+    msg "Starting udev and waiting for devices to settle...\n"
+    ${_udevd} --daemon
+    udevadm trigger --action=add --type=subsystems
+    udevadm trigger --action=add --type=devices
+    udevadm settle
+fi
diff --git a/core-services/03-filesystems.sh b/core-services/03-filesystems.sh
new file mode 100755
index 0000000..02df01a
--- /dev/null
+++ b/core-services/03-filesystems.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Remounting rootfs read-only...\n"
+mount -o remount,ro / || emergency_shell
+
+if [ -x /sbin/dmraid ]; then
+    msg "Activating dmraid devices...\n"
+    dmraid -i -ay || emergency_shell
+fi
+
+if [ -x /bin/btrfs ]; then
+    msg "Activating btrfs devices...\n"
+    btrfs device scan || emergency_shell
+fi
+
+if [ -x /sbin/vgchange ]; then
+    msg "Activating LVM devices...\n"
+    vgchange --sysinit -a y || emergency_shell
+fi
+
+if [ -e /etc/crypttab ]; then
+    msg "Activating encrypted devices...\n"
+    awk '/^#/ || /^$/ { next }
+         NF>2 { print "unsupported crypttab: " $0 >"/dev/stderr"; next }
+         { system("cryptsetup luksOpen " $2 " " $1) }' /etc/crypttab
+
+    if [ -x /sbin/vgchange ]; then
+        msg "Activating LVM devices for dm-crypt...\n"
+        vgchange --sysinit -a y || emergency_shell
+    fi
+fi
+
+msg "Checking filesystems:\n"
+fsck -A -T -a -t noopts=_netdev
+if [ $? -gt 1 ]; then
+    emergency_shell
+fi
+
+msg "Mounting rootfs read-write...\n"
+mount -o remount,rw / || emergency_shell
+
+msg "Mounting all non-network filesystems...\n"
+mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
diff --git a/core-services/04-swap.sh b/core-services/04-swap.sh
new file mode 100755
index 0000000..f1db240
--- /dev/null
+++ b/core-services/04-swap.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Initializing swap...\n"
+swapon -a || emergency_shell
diff --git a/core-services/05-misc.sh b/core-services/05-misc.sh
new file mode 100755
index 0000000..fba6d2a
--- /dev/null
+++ b/core-services/05-misc.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+msg "Setting up loopback interface...\n"
+ip link set up dev lo
+
+if [ -n "$HOSTNAME" ]; then
+    echo "$HOSTNAME" > /proc/sys/kernel/hostname
+elif [ -r /etc/hostname ]; then
+    HOSTNAME=$(cat /etc/hostname)
+    echo "$HOSTNAME" > /proc/sys/kernel/hostname
+fi
+msg "Setting up hostname to '${HOSTNAME}'...\n"
+
+if [ -n "$TIMEZONE" ]; then
+    msg "Setting up timezone to '${TIMEZONE}'...\n"
+    ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
+fi
+
+msg "Initializing random seed...\n"
+cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
+( umask 077; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 >/dev/null 2>&1 )
diff --git a/core-services/06-console-setup.sh b/core-services/06-console-setup.sh
new file mode 100755
index 0000000..63fea25
--- /dev/null
+++ b/core-services/06-console-setup.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Setting up TTYs to unicode mode...\n"
+for i in /dev/tty[0-6]; do
+    unicode_start < $i
+done
+
+if [ -n "$FONT" ]; then
+    msg "Setting up TTYs font to '${FONT}'...\n"
+    for i in /dev/tty[0-6]; do
+        setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} $FONT -C $i
+    done
+fi
+
+msg "Setting up keymap to '${KEYMAP:-us}'...\n"
+loadkeys -q -u ${KEYMAP:-us}
diff --git a/core-services/07-kmods.sh b/core-services/07-kmods.sh
new file mode 100755
index 0000000..07a5310
--- /dev/null
+++ b/core-services/07-kmods.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Loading kernel modules...\n"
+modules-load -v ${MODULES} | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
+echo
diff --git a/core-services/08-sysctl.sh b/core-services/08-sysctl.sh
new file mode 100755
index 0000000..febe7bb
--- /dev/null
+++ b/core-services/08-sysctl.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+if [ -x /sbin/sysctl ]; then
+    msg "Loading sysctl(8) settings...\n"
+    sysctl --system
+fi
diff --git a/core-services/99-cleanup.sh b/core-services/99-cleanup.sh
new file mode 100755
index 0000000..8030b4f
--- /dev/null
+++ b/core-services/99-cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+install -m0664 -o root -g utmp /dev/null /run/utmp
+install -dm1777 /tmp/.X11-unix /tmp/.ICE-unix
+rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot
diff --git a/functions b/functions
new file mode 100755
index 0000000..65d0b78
--- /dev/null
+++ b/functions
@@ -0,0 +1,35 @@
+# *-*-shell-*-*
+
+msg() {
+    # bold
+    printf "\033[1m=> $@\033[m"
+}
+
+msg_ok() {
+    # bold/green
+    printf "\033[1m\033[32m OK\033[m\n"
+}
+
+msg_error() {
+    # bold/red
+    printf "\033[1m\033[31mERROR: $@\033[m\n"
+}
+
+msg_warn() {
+    # bold/yellow
+    printf "\033[1m\033[33mWARNING: $@\033[m"
+}
+
+emergency_shell() {
+    echo
+    echo "Cannot continue due to errors above, starting emergency shell."
+    echo "When ready type exit to continue booting."
+    /bin/sh -l
+}
+
+detect_virt() {
+    # Detect LXC containers
+   if grep -q lxc /proc/self/environ >/dev/null; then
+       export VIRTUALIZATION=1
+   fi
+}