Depend on new febootstrap 2.0, and use febootstrap-install.
[libguestfs.git] / make-initramfs.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 set -e
22
23 unset CDPATH
24
25 modules="
26 -i augeas-libs
27 -i bash
28 -i binutils
29 -i coreutils
30 -i dosfstools
31 -i file
32 -i grub
33 -i iputils
34 -i kernel
35 -i lvm2
36 -i MAKEDEV
37 -i module-init-tools
38 -i net-tools
39 -i ntfs-3g
40 -i ntfsprogs
41 -i procps
42 -i strace
43 -i util-linux-ng
44 "
45
46 # Decide on names for the final output.  These have to match Makefile.am.
47 output=initramfs.@REPO@.@host_cpu@.img
48 koutput=vmlinuz.@REPO@.@host_cpu@
49 rm -f $output
50 rm -f $koutput
51
52 # Create the basic initramfs.
53 @FEBOOTSTRAP@ $modules -u @UPDATES@ @REPO@ initramfs @MIRROR@
54
55 # /sysroot is where the guest root filesystem will be mounted.
56 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /sysroot
57
58 # Create /tmp if it is missing.
59 @FEBOOTSTRAP_RUN@ initramfs -- mkdir -p --mode=0777 /tmp
60
61 # Nuke some stuff.  The kernel pulls mkinitrd and plymouth which pulls in
62 # all of Python.  Sheez.
63 (cd initramfs && find -name '*plymouth*' -print0) |
64   xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
65 (cd initramfs && find -name '*python*' -print0) |
66   xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf
67
68 # Modules take up nearly half of the image.  It's a rough guess that
69 # we don't need many drivers (which take up most of the space).
70 (cd initramfs && find lib/modules/*/kernel \
71   -name '*.ko' \
72   -a ! -name 'virtio.ko' \
73   -a ! -name 'virtio_net.ko' \
74   -a ! -name 'virtio_pci.ko' \
75   -a ! -name 'virtio_ring.ko' \
76   -a ! -name 'ext2.ko' \
77   -a ! -name 'ext4.ko' \
78   -a ! -name 'crc16.ko' \
79   -a ! -name 'jbd2.ko' \
80   -a ! -name 'fuse.ko' \
81   -a ! -name 'vfat.ko' \
82   -a ! -name 'fat.ko' \
83   -a ! -name 'udf.ko' \
84   -a ! -name 'crc_itu_t.ko' \
85   -a ! -name 'nls_utf8.ko' \
86   -a ! -name 'dm-*.ko' \
87   -a -print0 ) |
88   xargs -0 @FEBOOTSTRAP_RUN@ initramfs -- rm
89
90 # Pull the kernel out into the current directory.  We don't want it in
91 # the initramfs image.
92 cp initramfs/boot/vmlinuz* $koutput
93 @FEBOOTSTRAP_RUN@ initramfs -- rm -rf boot
94
95 # Minimize the image.
96 @FEBOOTSTRAP_MINIMIZE@ initramfs
97
98 # Add some missing configuration files.
99 if [ ! -f initramfs/etc/hosts ]; then
100     cat > hosts.new <<'__EOF__'
101 127.0.0.1 guestfs localhost.localdomain localhost
102 ::1       localhost6.localdomain6 localhost6
103 __EOF__
104     @FEBOOTSTRAP_INSTALL@ initramfs hosts.new /etc/hosts 0644 root.root
105     rm hosts.new
106 fi
107
108 if [ ! -f initramfs/etc/fstab ]; then
109     @FEBOOTSTRAP_RUN@ initramfs -- touch /etc/fstab
110 fi
111
112 echo nameserver 10.0.2.3 > resolv.conf.new
113 @FEBOOTSTRAP_INSTALL@ initramfs resolv.conf.new /etc/resolv.conf 0644 root.root
114 rm resolv.conf.new
115
116 # Create the init script.
117 cat > init.new <<'__EOF__'
118 #!/bin/sh
119 PATH=/sbin:/usr/sbin:$PATH
120 MAKEDEV mem null port zero core full ram tty console fd \
121   hda hdb hdc hdd sda sdb sdc sdd loop sd
122 mount -t proc /proc /proc
123 mount -t sysfs /sys /sys
124 mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
125 modprobe virtio_pci
126 modprobe virtio_net
127 modprobe dm_mod ||:
128 /sbin/ifconfig lo 127.0.0.1
129 /sbin/ifconfig eth0 10.0.2.10
130 /sbin/route add default gw 10.0.2.2
131 lvm vgscan --ignorelockingfailure
132 lvm vgchange -ay --ignorelockingfailure
133 exec guestfsd -f
134 __EOF__
135
136 @FEBOOTSTRAP_INSTALL@ initramfs init.new /init 0755 root.root
137 rm init.new
138
139 # Copy the daemon into the filesystem.
140 @FEBOOTSTRAP_INSTALL@ initramfs @abs_builddir@/daemon/guestfsd /sbin/guestfsd 0755 root.root
141
142 # Generate final image.
143 @FEBOOTSTRAP_TO_INITRAMFS@ initramfs > $output-t
144 mv $output-t $output
145 ls -lh $output
146 ls -lh $koutput