daemon: Remove -f (don't fork) option.
[libguestfs.git] / appliance / init
1 #!/bin/sh
2
3 echo Starting /init script ...
4
5 PATH=/sbin:/usr/sbin:/bin:/usr/bin
6 export PATH
7
8 # Debian bug 606622.
9 RUNLEVEL=S
10 PREVLEVEL=N
11 export RUNLEVEL PREVLEVEL
12
13 mkdir -p /sysroot
14
15 rm -f /proc; mkdir /proc
16 mount -t proc /proc /proc
17 mount -t sysfs /sys /sys
18
19 if [ ! -L /etc/init.d/udev -a -x /etc/init.d/udev ]; then
20   if type service >/dev/null 2>&1; then
21      service udev start
22   else
23      /etc/init.d/udev start
24   fi
25 elif [ -x /sbin/start_udev ] && /sbin/start_udev; then
26   :
27 elif [ -x /sbin/udevd ]; then
28   echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
29   /sbin/udevd --daemon
30   /sbin/udevadm trigger
31   /sbin/udevadm settle --timeout=10
32 else
33   echo No udev, creating /dev manually
34   mount -t tmpfs none /dev
35   mkdir /dev/pts /dev/shm /dev/mapper
36   mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
37   # Must do each MAKEDEV individually, because if one device fails,
38   # MAKEDEV will quit without creating the rest (RHBZ#507374).
39   for dev in mem null port zero core full ram tty console fd \
40     hda hdb hdc hdd sda sdb sdc sdd loop sd; do
41     MAKEDEV $dev ||:
42   done
43   mknod /dev/ptmx c 5 2;    chmod 0666 /dev/ptmx
44   mknod /dev/random c 1 8;  chmod 0666 /dev/random
45   mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom
46   ln -sf /proc/self/fd/0 /dev/stdin
47   ln -sf /proc/self/fd/1 /dev/stdout
48   ln -sf /proc/self/fd/2 /dev/stderr
49
50   modprobe virtio_pci
51   modprobe virtio_net
52 fi
53
54 if grep -sq selinux=1 /proc/cmdline; then
55   mount -t selinuxfs none /selinux
56 fi
57
58 # Update the system clock.
59 hwclock -u -s
60
61 # Set up the network.
62 ifconfig lo 127.0.0.1
63 ifconfig eth0 169.254.2.10
64 route add default gw 169.254.2.2
65
66 # Scan for LVM.
67 modprobe dm_mod ||:
68
69 lvm vgscan --ignorelockingfailure
70 lvm vgchange -ay --ignorelockingfailure
71
72 # Improve virtio-blk performance (RHBZ#509383).
73 for f in /sys/block/vd*/queue/rotational; do echo 1 > $f; done
74
75 # http://kbase.redhat.com/faq/docs/DOC-5428
76 # Disabled this until https://bugzilla.redhat.com/show_bug.cgi?id=630583
77 # is fixed (broken in Linux 2.6.36).
78 #for f in /sys/block/[hsv]d*/queue/scheduler; do echo noop > $f; done
79
80 # These are useful when debugging.
81 if grep -sq guestfs_verbose=1 /proc/cmdline; then
82     ls -lR /dev
83     cat /proc/mounts
84     lvm pvs
85     lvm vgs
86     lvm lvs
87     ifconfig
88     netstat -rn
89     lsmod
90     #hwclock -r
91     date
92     #ping -n -v -c 5 10.0.2.2
93     #ping -n -v -c 5 10.0.2.4
94
95     echo -n "uptime: "; cat /proc/uptime
96 fi
97
98 if ! grep -sq guestfs_rescue=1 /proc/cmdline; then
99   # The host will kill qemu abruptly if guestfsd shuts down normally
100   guestfsd
101
102   # Otherwise we try to clean up gracefully. For example, this ensures that a
103   # core dump generated by the guest daemon will be written to disk.
104 else
105   # Use appliance in rescue mode, also used by the virt-rescue command.
106   eval $(grep -Eo 'TERM=[^[:space:]]+' /proc/cmdline)
107   PS1='><rescue> '
108   export TERM PS1
109   echo
110   echo "------------------------------------------------------------"
111   echo
112   echo "Welcome to virt-rescue, the libguestfs rescue shell."
113   echo
114   echo "Note: The contents of / are the rescue appliance."
115   echo "You have to mount the guest's partitions under /sysroot"
116   echo "before you can examine them."
117   echo
118   bash -i
119   echo
120   echo "virt-rescue: Syncing the disk now before exiting ..."
121   echo
122 fi
123
124 sync
125 /sbin/reboot -f