If qemu dies during launch, set an error message (RHBZ#588851).
[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 mount -t proc /proc /proc
9 mount -t sysfs /sys /sys
10
11 if [ -x /etc/init.d/udev ]; then
12   if type service >/dev/null 2>&1; then
13      service udev start
14   else
15      /etc/init.d/udev start
16   fi
17 elif [ -x /sbin/start_udev ] && /sbin/start_udev; then
18   :
19 elif [ -x /sbin/udevd ]; then
20   echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
21   /sbin/udevd --daemon
22   /sbin/udevadm trigger
23   /sbin/udevadm settle --timeout=10
24 else
25   echo No udev, creating /dev manually
26   mount -t tmpfs none /dev
27   mkdir /dev/pts /dev/shm /dev/mapper
28   mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
29   # Must do each MAKEDEV individually, because if one device fails,
30   # MAKEDEV will quit without creating the rest (RHBZ#507374).
31   for dev in mem null port zero core full ram tty console fd \
32     hda hdb hdc hdd sda sdb sdc sdd loop sd; do
33     MAKEDEV $dev ||:
34   done
35   mknod /dev/ptmx c 5 2;    chmod 0666 /dev/ptmx
36   mknod /dev/random c 1 8;  chmod 0666 /dev/random
37   mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom
38   ln -sf /proc/self/fd/0 /dev/stdin
39   ln -sf /proc/self/fd/1 /dev/stdout
40   ln -sf /proc/self/fd/2 /dev/stderr
41
42   modprobe virtio_pci
43   modprobe virtio_net
44 fi
45
46 if grep -sq selinux=1 /proc/cmdline; then
47   mount -t selinuxfs none /selinux
48 fi
49
50 # Update the system clock.
51 hwclock -u -s
52
53 # Set up the network.
54 ifconfig lo 127.0.0.1
55 ifconfig eth0 169.254.2.10
56 route add default gw 169.254.2.2
57
58 # Scan for LVM.
59 modprobe dm_mod ||:
60
61 lvm vgscan --ignorelockingfailure
62 lvm vgchange -ay --ignorelockingfailure
63
64 # Improve virtio-blk performance (RHBZ#509383).
65 for f in /sys/block/vd*/queue/rotational; do echo 1 > $f; done
66
67 # Keep these to enhance the usefulness of debug output.
68 ls -l /dev
69 cat /proc/mounts
70 lvm pvs
71 lvm vgs
72 lvm lvs
73 ifconfig
74 netstat -rn
75 lsmod
76 #hwclock -r
77 date
78 #ping -n -v -c 5 10.0.2.2
79 #ping -n -v -c 5 10.0.2.4
80
81 echo -n "uptime: "; cat /proc/uptime
82
83 if ! grep -sq guestfs_rescue=1 /proc/cmdline; then
84   exec guestfsd -f
85 fi
86
87 # Use appliance in rescue mode, also used by the virt-rescue command.
88 eval $(grep -Eo 'TERM=[^[:space:]]+' /proc/cmdline)
89 PS1='><rescue> '
90 export TERM PS1
91 echo
92 echo "------------------------------------------------------------"
93 echo
94 echo "Welcome to virt-rescue, the libguestfs rescue shell."
95 echo
96 echo "Note: The contents of / are the rescue appliance."
97 echo "You have to mount the guest's partitions under /sysroot"
98 echo "before you can examine them."
99 echo
100 bash -i
101 echo
102 echo "virt-rescue: Syncing the disk now before exiting ..."
103 echo "(Don't worry if you see a 'Kernel panic' message below)"
104 echo
105 sync
106 sleep 1
107 sync