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.
49 # Decide on names for the final output. These have to match Makefile.am.
50 output=appliance/initramfs.@REPO@.@host_cpu@.img
51 koutput=appliance/vmlinuz.@REPO@.@host_cpu@
55 # Create the basic initramfs.
56 @FEBOOTSTRAP@ $modules -u @UPDATES@ @REPO@ initramfs @MIRROR@
58 # /sysroot is where the guest root filesystem will be mounted.
59 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
61 # Create /tmp if it is missing.
62 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
64 # Nuke some stuff. The kernel pulls mkinitrd and plymouth which pulls in
65 # all of Python. Sheez.
66 (cd initramfs && find -name '*plymouth*' -print0) |
67 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
68 (cd initramfs && find -name '*python*' -print0) |
69 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
71 # In Fedora >= 11, it pulls in all of Perl from somewhere. Nuke from orbit.
72 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/perl5 /usr/lib64/perl5
74 # Anaconda? JPEG images?
75 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /usr/lib/anaconda-runtime
77 # Don't need any firmware.
78 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf /lib/firmware
80 # Modules take up nearly half of the image. It's a rough guess that
81 # we don't need many drivers (which take up most of the space).
82 (cd initramfs && find lib/modules/*/kernel \
84 -a ! -name 'virtio.ko' \
85 -a ! -name 'virtio_net.ko' \
86 -a ! -name 'virtio_pci.ko' \
87 -a ! -name 'virtio_ring.ko' \
88 -a ! -name 'ext2.ko' \
89 -a ! -name 'ext3.ko' \
90 -a ! -name 'ext4*.ko' \
91 -a ! -name 'crc16.ko' \
93 -a ! -name 'jbd2.ko' \
94 -a ! -name 'fuse.ko' \
95 -a ! -name 'vfat.ko' \
98 -a ! -name 'crc_itu_t.ko' \
99 -a ! -name 'nls_utf8.ko' \
100 -a ! -name 'dm-*.ko' \
101 -a ! -name 'cramfs.ko' \
102 -a ! -name 'squashfs.ko' \
103 -a ! -name 'hfsplus.ko' \
104 -a ! -name 'ufs.ko' \
105 -a ! -name 'exportfs.ko' \
106 -a ! -name 'xfs.ko' \
108 xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm
110 # Pull the kernel out into the current directory. We don't want it in
111 # the initramfs image.
112 cp initramfs/boot/vmlinuz* $koutput
113 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
115 # Minimize the image.
116 @FEBOOTSTRAP_MINIMIZE@ initramfs
118 # Add some missing configuration files.
119 if [ ! -f initramfs/etc/hosts ]; then
120 cat > hosts.new <<'__EOF__'
121 127.0.0.1 guestfs localhost.localdomain localhost
122 ::1 localhost6.localdomain6 localhost6
124 @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
128 if [ ! -f initramfs/etc/fstab ]; then
129 @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
132 echo nameserver 10.0.2.3 > resolv.conf.new
133 @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
136 # Create the init script.
137 cat > init.new <<'__EOF__'
139 echo Starting /init script ...
140 PATH=/sbin:/usr/sbin:$PATH
141 mount -t tmpfs none /dev
142 mkdir /dev/pts /dev/shm /dev/mapper
143 MAKEDEV mem null port zero core full ram tty console fd \
144 hda hdb hdc hdd sda sdb sdc sdd loop sd
145 mknod /dev/ptmx c 5 2; chmod 0666 /dev/ptmx
146 mknod /dev/random c 1 8; chmod 0666 /dev/random
147 mknod /dev/urandom c 1 9; chmod 0444 /dev/urandom
148 mount -t proc /proc /proc
149 mount -t sysfs /sys /sys
150 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
151 ln -sf /proc/self/fd/0 /dev/stdin
152 ln -sf /proc/self/fd/1 /dev/stdout
153 ln -sf /proc/self/fd/2 /dev/stderr
157 /sbin/ifconfig lo 127.0.0.1
158 /sbin/ifconfig eth0 10.0.2.10
159 /sbin/route add default gw 10.0.2.2
160 lvm vgscan --ignorelockingfailure
161 lvm vgchange -ay --ignorelockingfailure
162 if grep -sq guestfs_rescue=1 /proc/cmdline; then
168 @FEBOOTSTRAP_INSTALL@ initramfs init.new /init 0755 root.root
171 # Just in case the kernel isn't looking for /init, make /sbin/init
172 # be our script, not the real init.
173 #@FEBOOTSTRAP_RUN@ initramfs -- ln -f /init /sbin/init
177 # Now directly run the update script to copy/update the daemon in the
179 cd appliance && bash update.sh