cf772e06426c6cabd6c160ed573396ccf6fba9c4
[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
25 if [ "@DIST@" = "REDHAT" ]; then
26   cd @top_builddir@
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@
30   rm -f $output
31   rm -f $koutput
32
33   # Create the basic initramfs.
34   exec 5<appliance/packagelist
35   packages=
36   while read pkg 0<&5; do
37       packages="$packages -i $pkg"
38   done
39   exec 5<&-
40
41   @FEBOOTSTRAP@ $packages -u @UPDATES@ @REPO@ initramfs @MIRROR@
42
43   # /sysroot is where the guest root filesystem will be mounted.
44   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
45
46   # Create /tmp if it is missing.
47   @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
48
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
55
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
58
59   # Anaconda?  JPEG images?
60   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
61
62   # Don't need any firmware.
63   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware
64
65   # Don't need any keyboard maps.
66   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/kbd
67
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
72
73   # Remove /var/lib/yum stuff.
74   @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /var/lib/yum
75
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 \
82     /usr/bin/chfn \
83     /usr/bin/chsh \
84     /usr/libexec/pt_chown \
85     /usr/sbin/groupdel \
86     /usr/sbin/groupadd \
87     /usr/sbin/useradd \
88     /usr/sbin/tzdata-update \
89     /usr/sbin/userdel \
90     /usr/sbin/usermod \
91     /usr/sbin/groupmod \
92     /usr/sbin/groupmems \
93     /sbin/unix_update \
94     $(cd initramfs && echo usr/sbin/glibc_post_upgrade.*)
95
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
99   whitelist=
100   while read kmod 0<&5; do
101       whitelist="$whitelist -a -not -name $kmod"
102   done
103   exec 5<&-
104
105   (cd initramfs && \
106     find lib/modules/*/kernel -name '*.ko' $whitelist -a -print0 ) |
107     xargs -0 febootstrap-run initramfs -- rm
108
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
113
114   # Minimize the image.
115   @FEBOOTSTRAP_MINIMIZE@ initramfs
116
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
122 __EOF__
123       @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
124       rm hosts.new
125   fi
126
127   if [ ! -f initramfs/etc/fstab ]; then
128       @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
129   fi
130
131   echo nameserver 10.0.2.3 > resolv.conf.new
132   @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
133   rm resolv.conf.new
134
135   ls -lh $koutput
136
137   # Now directly run the update script to copy/update the daemon in the
138   # initramfs.
139   cd appliance && bash update.sh
140
141 elif [ "@DIST@" = "DEBIAN" ]; then
142   cd @top_builddir@/appliance
143   debirf make -n debian
144 fi
145