SHA256
1
0
forked from pool/libguestfs
libguestfs/libguestfs.mkinitrd.boot.sh

98 lines
2.5 KiB
Bash

#!/bin/bash
#%stage: block
#
#%modules: dm-mod
#%modules: virtio_blk
#%modules: virtio_console
#%modules: virtio_net
#%modules: virtio_pci
#%modules: virtio_scsi
#
#%programs: cat
#%programs: date
#%programs: guestfsd
#%programs: lvm
#%programs: ip
#%programs: lsmod
#%programs: grep
#@GUESTFS_EXT_CMDS@
#
missing_commands="@GUESTFS_MISSING_CMDS@"
# from libguestfs-1.19.34/appliance/init:
# Scan for MDs.
mdadm -As --auto=yes --run
# Scan for LVM.
modprobe dm_mod ||:
lvm vgscan --ignorelockingfailure
lvm vgchange -ay --ignorelockingfailure
# Improve virtio-blk performance (RHBZ#509383).
for f in /sys/block/vd*/queue/rotational; do if test -f $f ; then echo 1 > $f; fi ; done
# These are useful when debugging.
if grep -sq guestfs_verbose=1 /proc/cmdline; then
ls -lR /dev
cat /proc/mounts
lvm pvs
lvm vgs
lvm lvs
ip a
ip r
lsmod
#hwclock -r
date
#ping -n -v -c 5 10.0.2.2
#ping -n -v -c 5 10.0.2.4
echo -n "uptime: "; cat /proc/uptime
fi
echo "These commands might be called by guestfsd, but they were not available at buildtime:"
echo "missing commands: $missing_commands"
echo
if ! grep -sq guestfs_rescue=1 /proc/cmdline; then
# Run the daemon under valgrind if ./configure --enable-valgrind-daemon
vg_channel=/dev/virtio-ports/org.libguestfs.valgrind
if [ -w $vg_channel ]; then
if [ -r /etc/guestfsd.suppressions ]; then
suppressions="--suppressions=/etc/guestfsd.suppressions"
fi
exec 3>$vg_channel
vg="valgrind --leak-check=full --log-fd=3 --error-exitcode=119 --max-stackframe=8388608 --child-silent-after-fork=yes $suppressions"
echo "enabling valgrind: $vg"
fi
# The host will kill qemu abruptly if guestfsd shuts down normally
$vg guestfsd
# Otherwise we try to clean up gracefully. For example, this ensures that a
# core dump generated by the guest daemon will be written to disk.
else
# Use appliance in rescue mode, also used by the virt-rescue command.
eval $(grep -Eo 'TERM=[^[:space:]]+' /proc/cmdline)
PS1='><rescue> '
export TERM PS1
echo
echo "------------------------------------------------------------"
echo
echo "Welcome to virt-rescue, the libguestfs rescue shell."
echo
echo "Note: The contents of / are the rescue appliance."
echo "You have to mount the guest's partitions under /sysroot"
echo "before you can examine them."
echo
bash -i
echo
echo "virt-rescue: Syncing the disk now before exiting ..."
echo
fi
echo "Leaving."
echo s > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger
exit 0