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.
47 # Decide on names for the final output. These have to match Makefile.am.
48 output=initramfs.@REPO@.@host_cpu@.img
49 koutput=vmlinuz.@REPO@.@host_cpu@
53 # Create the basic initramfs.
54 @FEBOOTSTRAP@ $modules -u @UPDATES@ @REPO@ initramfs @MIRROR@
56 # /sysroot is where the guest root filesystem will be mounted.
57 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
59 # Create /tmp if it is missing.
60 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
62 # Nuke some stuff. The kernel pulls mkinitrd and plymouth which pulls in
63 # all of Python. Sheez.
64 (cd initramfs && find -name '*plymouth*' -print0) |
65 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
66 (cd initramfs && find -name '*python*' -print0) |
67 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
69 # In Fedora >= 11, it pulls in all of Perl from somewhere. Nuke from orbit.
70 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5
72 # Anaconda? JPEG images?
73 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
75 # Modules take up nearly half of the image. It's a rough guess that
76 # we don't need many drivers (which take up most of the space).
77 (cd initramfs && find lib/modules/*/kernel \
79 -a ! -name 'virtio.ko' \
80 -a ! -name 'virtio_net.ko' \
81 -a ! -name 'virtio_pci.ko' \
82 -a ! -name 'virtio_ring.ko' \
83 -a ! -name 'ext2.ko' \
84 -a ! -name 'ext4.ko' \
85 -a ! -name 'crc16.ko' \
86 -a ! -name 'jbd2.ko' \
87 -a ! -name 'fuse.ko' \
88 -a ! -name 'vfat.ko' \
91 -a ! -name 'crc_itu_t.ko' \
92 -a ! -name 'nls_utf8.ko' \
93 -a ! -name 'dm-*.ko' \
95 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm
97 # Pull the kernel out into the current directory. We don't want it in
98 # the initramfs image.
99 cp initramfs/boot/vmlinuz* $koutput
100 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
102 # Minimize the image.
103 @FEBOOTSTRAP_MINIMIZE@ initramfs
105 # Add some missing configuration files.
106 if [ ! -f initramfs/etc/hosts ]; then
107 cat > hosts.new <<'__EOF__'
108 127.0.0.1 guestfs localhost.localdomain localhost
109 ::1 localhost6.localdomain6 localhost6
111 @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
115 if [ ! -f initramfs/etc/fstab ]; then
116 @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
119 echo nameserver 10.0.2.3 > resolv.conf.new
120 @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
123 # Create the init script.
124 cat > init.new <<'__EOF__'
126 PATH=/sbin:/usr/sbin:$PATH
127 MAKEDEV mem null port zero core full ram tty console fd \
128 hda hdb hdc hdd sda sdb sdc sdd loop sd
129 mount -t proc /proc /proc
130 mount -t sysfs /sys /sys
131 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
135 /sbin/ifconfig lo 127.0.0.1
136 /sbin/ifconfig eth0 10.0.2.10
137 /sbin/route add default gw 10.0.2.2
138 lvm vgscan --ignorelockingfailure
139 lvm vgchange -ay --ignorelockingfailure
143 @FEBOOTSTRAP_INSTALL@ initramfs init.new /init 0755 root.root
146 # Copy the daemon into the filesystem.
147 @FEBOOTSTRAP_INSTALL@ initramfs @abs_builddir@/daemon/guestfsd /sbin/guestfsd 0755 root.root
149 # Generate final image.
150 @FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t