0953c4c06e2667a135e75f000f747820948028fa
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / etc / init.d / rc.sysinit
1 #!/bin/sh
2 # vi: ts=4 noexpandtab
3
4 . /lib/cirros/shlib
5
6 write_lxc_is_container() {
7         cat <<"EOF"
8 #!/bin/sh
9 # This program is written by /etc/rc.d/rc.sysinit.
10 # It simply reports whether or not this system is in an lxc container
11
12 EOF
13         if is_lxc; then
14                 echo "# This is an LXC container"
15                 echo '[ "$1" = "-v" ] && echo '"$_LXC_CONTAINER"
16                 echo "exit 0"
17         else
18                 echo "# This is NOT an LXC container"
19                 echo '[ "$1" = "-v" ] && echo none'
20                 echo "exit 1"
21         fi
22 }
23
24 fail() { echo "FAIL:" "$@"; }
25 warn() { echo "WARN:" "$@"; }
26
27 ### begin init ###
28
29 if [ ! -d /proc/1 ]; then
30         mount -n -t proc /proc /proc || fail "failed mount /proc"
31 fi
32
33 read uptime cputime < /proc/uptime
34 iinfo "$0: up at $uptime"
35
36 if (: >/.testrw; ) >/dev/null 2>&1; then
37         rm -f /.testrw
38 else
39         mount -o remount,rw / || fail "failed mount / rw"
40 fi
41
42 is_mounted sysfs "" /sys ||
43         mount -t sysfs sysfs /sys || fail "failed mount /sys!"
44
45 if ! is_lxc; then
46         mount_once devtmpfs /dev /dev || fail "failed mount /dev"
47 fi
48 iinfo "container: $_LXC_CONTAINER"
49
50 mkdir -p /dev/pts /dev/shm /run
51
52 mount -a
53
54 mkdir /run/var.tmp
55
56 hostname -F /etc/hostname
57
58 f="/bin/lxc-is-container" && write_lxc_is_container > "$f" && chmod 755 "$f"
59
60 if ! is_lxc; then
61         for d in $(awk '$2 == "/" { print $1 }' /proc/mounts); do
62                 [ -e "/dev/${d#/dev}" ] && ln -sf "${d#/dev/}" /dev/root && break
63         done
64 fi
65
66 ## pretend you're runlevel 3
67 set +f
68 for s in /etc/rc3.d/S*; do
69         [ -x "$s" ] || continue
70         "$s" "start" </dev/null || warn "$s failed"
71 done
72 set -f
73
74 if is_lxc; then
75         grep -q "^pts/0$" /etc/securetty || echo "pts/0" >> /etc/securetty
76         if ! [ /dev/tty1 -ef /dev/console ]; then
77                 # on libvirt lxc, /dev/console is a symlink to /dev/pts0
78                 # and /dev/tty1 is also a symlink to /dev/pts/0. So using
79                 # the tty1 gets us a getty on "console"
80                 #
81                 # on upstream lxc, /dev/console is a character device
82                 # so we run a getty there if so.
83                 lxc_console="console"
84         fi
85 fi
86
87 s_args=""
88 for tty in $lxc_console tty1 ttyS0 hvc0; do
89         if [ -e /dev/$tty ] && { echo "" >> "/dev/$tty" ; } 2>/dev/null ; then
90                 s_args="${s_args:+${s_args} }s/^#$tty:\(.*\)/$tty:\1/;"
91         else
92                 s_args="${s_args:+${s_args} }s/^$tty:\(.*\)/#$tty:\1/;"
93         fi
94 done
95 [ -z "$s_args" ] ||
96         { sed -i "$s_args" /etc/inittab && kill -HUP 1; }
97
98 if [ -f /etc/rc.local -a -x /etc/rc.local ]; then
99         /etc/rc.local
100 fi