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