3 # Copyright (C) 2009 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # This is called from the Makefile to build the initramfs.
25 if [ "@DIST@" = "REDHAT" ]; then
27 # Decide on names for the final output. These have to match Makefile.am.
28 output=appliance/initramfs.@REPO@.@host_cpu@.img
29 koutput=appliance/vmlinuz.@REPO@.@host_cpu@
33 # Create the basic initramfs.
34 exec 5<appliance/packagelist
36 while read pkg 0<&5; do
37 packages="$packages -i $pkg"
41 @FEBOOTSTRAP@ $packages -u @UPDATES@ @REPO@ initramfs @MIRROR@
43 # /sysroot is where the guest root filesystem will be mounted.
44 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
46 # Create /tmp if it is missing.
47 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
49 # Nuke some stuff. The kernel pulls mkinitrd and plymouth which pulls in
50 # all of Python. Sheez.
51 (cd initramfs && find -name '*plymouth*' -print0) |
52 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
53 (cd initramfs && find -name '*python*' -print0) |
54 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
56 # In Fedora >= 11, it pulls in all of Perl from somewhere. Nuke from orbit.
57 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5
59 # Anaconda? JPEG images?
60 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
62 # Don't need any firmware.
63 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware
65 # Don't need any keyboard maps.
66 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd
68 # Remove anything in home directory. Because this is potentially
69 # liable to monstrous fuck-ups, we don't put a slash before 'home'.
70 (cd initramfs && echo home/*) |
71 xargs @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
73 # Remove /var/lib/yum stuff.
74 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /var/lib/yum
76 # Remove some unreadable binaries which are incompatible with
77 # the supermin appliance. Since these binaries can't be read
78 # from the host filesystem, they generate warnings like:
79 # cpio: ./usr/bin/chfn: Cannot open: Permission denied
80 # These binaries are not needed for operation of the appliance.
81 @FEBOOTSTRAP_RUN@ initramfs -- rm -f \
84 /usr/libexec/pt_chown \
88 /usr/sbin/tzdata-update \
94 $(cd initramfs && echo usr/sbin/glibc_post_upgrade.*)
96 # Kernel modules take up nearly half of the image. Only include ones
97 # which are on the whitelist.
98 exec 5<appliance/kmod.whitelist
100 while read kmod 0<&5; do
101 whitelist="$whitelist -a -not -name $kmod"
106 find lib/modules/*/kernel -name '*.ko' $whitelist -a -print0 ) |
107 xargs -0 febootstrap-run initramfs -- rm
109 # Pull the kernel out into the current directory. We don't want it in
110 # the initramfs image.
111 cp initramfs/boot/vmlinuz* $koutput
112 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
114 # Minimize the image.
115 @FEBOOTSTRAP_MINIMIZE@ initramfs
117 # Add some missing configuration files.
118 if [ ! -f initramfs/etc/hosts ]; then
119 cat > hosts.new <<'__EOF__'
120 127.0.0.1 guestfs localhost.localdomain localhost
121 ::1 localhost6.localdomain6 localhost6
123 @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
127 if [ ! -f initramfs/etc/fstab ]; then
128 @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
131 echo nameserver 10.0.2.3 > resolv.conf.new
132 @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
137 # Now directly run the update script to copy/update the daemon in the
139 cd appliance && bash update.sh
141 elif [ "@DIST@" = "DEBIAN" ]; then
142 cd @top_builddir@/appliance
143 debirf make -n debian