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.
23 # If you want to do some extra debugging and diagnosis of the
24 # initramfs image, then uncomment this line. This makes the image
28 modules="-i kernel -i bash -i coreutils -i lvm2 -i ntfs-3g -i nfs-utils -i util-linux-ng -i MAKEDEV -i net-tools"
30 if [ "x$debug" = "xyes" ]; then
31 modules="$modules -i module-init-tools -i procps -i strace -i iputils"
34 # Decide on names for the final output. These have to match Makefile.am.
35 output=initramfs.@REPO@.@host_cpu@.img
36 koutput=vmlinuz.@REPO@.@host_cpu@
37 rm -f $output $koutput
39 # Create the basic initramfs.
40 @FEBOOTSTRAP@ $modules @REPO@ initramfs @MIRROR@
42 # Nuke some stuff. The kernel pulls mkinitrd and plymouth which pulls in
43 # all of Python. Sheez.
44 find initramfs -name '*plymouth*' -print0 | xargs -0 rm -rf
45 find initramfs -name '*python*' -print0 | xargs -0 rm -rf
47 # Modules take up nearly half of the image. It's a rough guess that
48 # we don't need any drivers (which take up most of the space).
49 # (We need to keep kernel/net/sunrpc for NFS)
50 rm -rf initramfs/lib/modules/*/kernel/{drivers,sound}
51 rm -rf initramfs/lib/modules/*/kernel/arch/x86/kvm
53 # Pull the kernel out into the current directory. We don't want it in
54 # the initramfs image.
55 mv initramfs/boot/vmlinuz* $koutput
59 @FEBOOTSTRAP_MINIMIZE@ initramfs
61 # Add some missing configuration files.
62 if [ ! -f initramfs/etc/hosts ]; then
63 cat > initramfs/etc/hosts.new <<'__EOF__'
64 127.0.0.1 guestfs localhost.localdomain localhost
65 ::1 localhost6.localdomain6 localhost6
67 @FEBOOTSTRAP_RUN@ initramfs -- \
68 install -m 0644 -o root -g root /etc/hosts.new /etc/hosts
69 rm initramfs/etc/hosts.new
72 if [ ! -f initramfs/etc/fstab ]; then
73 @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
76 # Copy the daemon into the filesystem.
77 #cp daemon/guestfsd initramfs/sbin
79 # Create the init script.
80 cat > initramfs/init.new <<'__EOF__'
82 PATH=/sbin:/usr/sbin:$PATH
83 MAKEDEV mem null port zero core full ram tty console fd \
84 hda hdb hdc hdd sda sdb sdc sdd loop sd
85 mount -t proc /proc /proc
86 mount -t sysfs /sys /sys
87 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
89 /sbin/ifconfig lo 127.0.0.1
90 lvm vgscan --ignorelockingfailure
91 lvm vgchange -ay --ignorelockingfailure
98 if [ "x$debug" != "xyes" ]; then
99 echo exec guestfsd -f >> initramfs/init.new
101 echo guestfsd >> initramfs/init.new
102 echo exec bash -i >> initramfs/init.new
105 @FEBOOTSTRAP_RUN@ initramfs -- install -m 0755 -o root -g root /init.new /init
106 rm initramfs/init.new
108 # Generate final image.
109 @FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t