appliance: Change comment about unreadable binaries.
[libguestfs.git] / appliance / make.sh.in
1 #!/bin/bash -
2 # @configure_input@
3 # Copyright (C) 2009 Red Hat Inc.
4 #
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.
9 #
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.
14 #
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.
18
19 # This is called from the Makefile to build the initramfs.
20
21 unset CDPATH
22
23 set -e
24 set -x
25
26 if [ "@DIST@" = "REDHAT" ]; then
27   cd @top_builddir@
28   # Decide on names for the final output.  These have to match Makefile.am.
29   output=appliance/initramfs.@REPO@.@host_cpu@.img
30   koutput=appliance/vmlinuz.@REPO@.@host_cpu@
31   rm -f $output
32   rm -f $koutput
33
34   # Create the basic initramfs.
35   exec 5<appliance/packagelist
36   packages=
37   while read pkg 0<&5; do
38       packages="$packages -i $pkg"
39   done
40   exec 5<&-
41
42   @FEBOOTSTRAP@ $packages -u @UPDATES@ @REPO@ initramfs @MIRROR@
43
44   # Create modules.dep.  This is only used in the normal appliance
45   # (not supermin).
46   kversion=$(basename initramfs/lib/modules/*)
47   @FEBOOTSTRAP_RUN@ initramfs -- /sbin/depmod -a $kversion
48
49   # /sysroot is where the guest root filesystem will be mounted.
50   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
51
52   # Create /tmp if it is missing.
53   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
54
55   # Create /selinux if it is missing.
56   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0755 /selinux
57
58   # Nuke some stuff.  The kernel pulls mkinitrd and plymouth which pulls in
59   # all of Python.  Sheez.
60   (cd initramfs && find -name '*python*' -print0) |
61     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
62   (cd initramfs && find -name '*plymouth*' -print0) |
63     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
64   (cd initramfs && find -name 'libply-*' -print0) |
65     xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
66
67   # In Fedora >= 11, it pulls in all of Perl from somewhere.  Nuke from orbit.
68   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5
69
70   # Anaconda?  JPEG images?
71   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
72
73   # Don't need any firmware.
74   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware
75
76   # Don't need any keyboard maps.
77   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd
78
79   # Remove anything in home directory.  Because of the potential for disaster
80   # we don't put a slash before 'home'.
81   (cd initramfs && echo home/*) |
82     xargs @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
83
84   # Remove /var/lib/yum stuff.
85   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /var/lib/yum
86
87   # Remove some unreadable binaries which are incompatible with
88   # the supermin appliance.  Since these binaries can't be read
89   # from the host filesystem, they cannot be added to the supermin
90   # appliance at run time.  XXX Need a better fix for this.
91   # Probably we should change febootstrap-supermin-helper to just
92   # ignore such files.
93   @FEBOOTSTRAP_RUN@ initramfs -- rm -f \
94     /usr/bin/chfn \
95     /usr/bin/chsh \
96     /usr/libexec/pt_chown \
97     /usr/sbin/groupdel \
98     /usr/sbin/groupadd \
99     /usr/sbin/useradd \
100     /usr/sbin/tzdata-update \
101     /usr/sbin/userdel \
102     /usr/sbin/usermod \
103     /usr/sbin/groupmod \
104     /usr/sbin/groupmems \
105     /sbin/unix_update \
106     /usr/sbin/tcpd \
107     /lib/dbus-1/dbus-daemon-launch-helper \
108     /lib64/dbus-1/dbus-daemon-launch-helper \
109     /etc/passwd- \
110     /etc/group- \
111     /etc/gshadow \
112     /etc/gshadow- \
113     /etc/shadow \
114     /etc/shadow- \
115     /etc/securetty \
116     /etc/sysconfig/iptables-config \
117     /etc/default/useradd \
118     /etc/security/opasswd \
119     /etc/libaudit.conf \
120     /var/log/tallylog \
121     /var/log/maillog \
122     /var/log/secure \
123     /var/log/spooler \
124     /var/log/messages \
125     /var/log/btmp \
126     /var/log/yum.log \
127     $(cd initramfs && echo usr/sbin/glibc_post_upgrade.*)
128
129   # Kernel modules take up nearly half of the image.  Only include ones
130   # which are on the whitelist.
131   exec 5<appliance/kmod.whitelist
132   whitelist=
133   while read kmod 0<&5; do
134       whitelist="$whitelist -a -not -name $kmod"
135   done
136   exec 5<&-
137
138   (cd initramfs && \
139     find lib/modules/*/kernel -name '*.ko' $whitelist -a -print0 ) |
140     xargs -0 febootstrap-run initramfs -- rm
141
142   # Pull the kernel out into the current directory.  We don't want it in
143   # the initramfs image.
144   cp initramfs/boot/vmlinuz* $koutput
145   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
146
147   # Minimize the image.
148   @FEBOOTSTRAP_MINIMIZE@ initramfs
149
150   # Add some missing configuration files.
151   if [ ! -f initramfs/etc/hosts ]; then
152       cat > hosts.new <<'__EOF__'
153   127.0.0.1 guestfs localhost.localdomain localhost
154   ::1       localhost6.localdomain6 localhost6
155 __EOF__
156       @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
157       rm hosts.new
158   fi
159
160   if [ ! -f initramfs/etc/fstab ]; then
161       @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
162   fi
163
164   echo nameserver 10.0.2.3 > resolv.conf.new
165   @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
166   rm resolv.conf.new
167
168   ls -lh $koutput
169
170   # Now directly run the update script to copy/update the daemon in the
171   # initramfs.
172   cd appliance && bash update.sh
173
174 elif [ "@DIST@" = "DEBIAN" ]; then
175   cd @top_builddir@/appliance
176   debirf make -n debian
177   mkdir -p @top_builddir@/initramfs
178   touch @top_builddir@/initramfs/fakeroot.log
179 fi