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