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