2 # Copyright (C) 2009-2010 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # Helper script which constructs the supermin appliance at runtime.
27 echo "$p: Create supermin appliance."
30 echo "$p sourcedir host_cpu repo kernel initrd"
32 echo "This script is used by libguestfs to build the supermin appliance"
33 echo "(kernel and initrd output files). You should NOT need to run this"
34 echo "program directly except if you are debugging tricky supermin"
35 echo "appliance problems."
37 echo "NB: The kernel and initrd parameters are OUTPUT parameters. If"
38 echo "those files exist, they are overwritten by the output."
40 echo "Typical usage when debugging supermin appliance problems:"
41 echo " $p /usr/lib64/guestfs x86_64 fedora-12 /tmp/kernel /tmp/initrd"
42 echo "Note: This will OVERWRITE any existing files called /tmp/kernel"
43 echo "and /tmp/initrd."
48 # Source directory containing the supermin input files.
49 sourcedir=$(cd "$1" > /dev/null; pwd)
51 # Host CPU and repo constants passed from the library (see:
52 # https://bugzilla.redhat.com/show_bug.cgi?id=558593).
61 # Look for the most recent kernel named vmlinuz-*.<arch>* which has a
62 # corresponding directory in /lib/modules/. If the architecture is x86, look
65 # RHEL 5 didn't append the arch to the kernel name, so look for kernels
66 # without arch second.
68 arch=$(echo $host_cpu | sed 's/^i.86$/i?86/')
70 ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen ||: ;
71 ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen
74 if [ -z "$kernels" ]; then
75 echo "$0: failed to find a suitable kernel in /boot directory" >&2
81 b=$(echo "$b" | sed 's,vmlinuz-,,')
82 modpath="/lib/modules/$b"
83 if [ -d "$modpath" ]; then
90 if [ -z "$modpath" ]; then
91 echo "$0: failed to find a suitable kernel" >&2
95 # The initrd consists of these components:
96 # (1) The base skeleton appliance that we constructed at build time.
97 # name = initramfs.$repo.$host_cpu.supermin.img
98 # format = compressed cpio
99 # (2) The modules from modpath which are on the module whitelist.
100 # format = plain cpio
101 # (3) The host files which match wildcards in *.supermin.hostfiles.
102 # format = plain cpio
104 cp "$sourcedir"/initramfs.$repo.$host_cpu.supermin.img "$initrd"
106 # Kernel modules (2).
107 exec 5<"$sourcedir"/kmod.whitelist
109 while read kmod 0<&5; do
110 whitelist="$whitelist -o -name $kmod"
114 find "$modpath" \( -not -name '*.ko' $whitelist \) -a -print0 |
115 cpio --quiet -o -0 -H newc >> "$initrd"
121 cat "$sourcedir"/initramfs.$repo.$host_cpu.supermin.hostfiles
123 cpio -C 65536 --quiet -o -H newc ) >> "$initrd"