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