84ee96e3033375936cf09ffbaa94ff963b085b4c
[libguestfs.git] / appliance / init
1 #!/bin/sh
2
3 echo Starting /init script ...
4
5 PATH=/sbin:/usr/sbin:$PATH
6
7 mount -t proc /proc /proc
8 mount -t sysfs /sys /sys
9
10 if [ -x /etc/init.d/udev ]; then
11   if type service >/dev/null 2>&1; then
12      service udev start
13   else
14      /etc/init.d/udev start
15   fi
16 elif [ -x /sbin/start_udev ] && /sbin/start_udev; then
17   :
18 elif [ -x /sbin/udevd ]; then
19   echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
20   /sbin/udevd --daemon
21   /sbin/udevadm trigger
22   /sbin/udevadm settle --timeout=10
23 else
24   echo No udev, creating /dev manually
25   mount -t tmpfs none /dev
26   mkdir /dev/pts /dev/shm /dev/mapper
27   mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
28   # Must do each MAKEDEV individually, because if one device fails,
29   # MAKEDEV will quit without creating the rest (RHBZ#507374).
30   for dev in mem null port zero core full ram tty console fd \
31     hda hdb hdc hdd sda sdb sdc sdd loop sd; do
32     MAKEDEV $dev ||:
33   done
34   mknod /dev/ptmx c 5 2;    chmod 0666 /dev/ptmx
35   mknod /dev/random c 1 8;  chmod 0666 /dev/random
36   mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom
37   ln -sf /proc/self/fd/0 /dev/stdin
38   ln -sf /proc/self/fd/1 /dev/stdout
39   ln -sf /proc/self/fd/2 /dev/stderr
40
41   modprobe virtio_pci
42   modprobe virtio_net
43 fi
44
45 if grep -sq selinux=1 /proc/cmdline; then
46   mount -t selinuxfs none /selinux
47 fi
48
49 modprobe dm_mod ||:
50
51 ifconfig lo 127.0.0.1
52 ifconfig eth0 10.0.2.10
53 route add default gw 10.0.2.2
54
55 lvm vgscan --ignorelockingfailure
56 lvm vgchange -ay --ignorelockingfailure
57
58 # Improve virtio-blk performance (RHBZ#509383).
59 for f in /sys/block/vd*/queue/rotational; do echo 1 > $f; done
60
61 # Keep these to enhance the usefulness of debug output.
62 ls -l /dev
63 cat /proc/mounts
64 lvm pvs
65 lvm vgs
66 lvm lvs
67 ifconfig
68 netstat -rn
69 lsmod
70 #ping -n -v -c 5 10.0.2.2
71 #ping -n -v -c 5 10.0.2.4
72
73 echo -n "uptime: "; cat /proc/uptime
74
75 if ! grep -sq guestfs_rescue=1 /proc/cmdline; then
76   exec guestfsd -f
77 fi
78
79 # Use appliance in rescue mode, also used by the virt-rescue command.
80 TERM=linux ;# XXX library should pass this from library's environment
81 PS1='><rescue> '
82 export TERM PS1
83 echo
84 echo "Welcome to virt-rescue, the libguestfs rescue shell."
85 echo
86 echo "Note: The contents of / are the rescue appliance."
87 echo "You have to mount the guest's partitions under /sysroot"
88 echo "before you can examine them."
89 echo
90 exec bash -i