Compress the qcow2 file.
[supernested.git] / build-supernested.sh.in
1 #!/bin/bash -
2 # supernested Makefile.am
3 # @configure_input@
4 # (C) Copyright 2014 Red Hat Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 # Written by Richard W.M. Jones <rjones@redhat.com>
21
22 unset CDPATH
23 set -e
24
25 supermin="@SUPERMIN@"
26 distro="@DISTRO@"
27 guestfish="@GUESTFISH@"
28
29 output="$1"
30 if [ -z "$output" ]; then
31     echo "$0: do not run this script directly, use 'make'"
32     exit 1
33 fi
34
35 # Get the list of package names.  This is distro-specific.
36 if [[ "$distro" =~ ^fedora- ]]; then
37     packages="
38         bash
39         coreutils
40         grep
41         qemu
42         qemu-kvm-rhev
43         systemd-udev
44         util-linux
45     "
46 elif [[ "$distro" =~ ^debian- ]]; then
47     packages="
48         bash
49         coreutils
50         grep
51         qemu-system-x86
52         sgabios
53         sysvinit-core
54         util-linux
55     "
56 else
57     echo "$0: $distro not known.  You need to edit this script to add support for this distro."
58     exit 1
59 fi
60
61 # Run the prepare step.
62 echo "Preparing the supermin appliance containing:" $packages
63 "$supermin" --prepare $packages -o tmp-supermin.d
64
65 # Add the init & run-supernested.sh scripts.
66 tar cf tmp-supermin.d/init.tar init run-supernested.sh
67
68 # Add the excludefiles.
69 cp excludefiles tmp-supermin.d/
70
71 # Run the build step.
72 echo "Building the full appliance ..."
73 "$supermin" --build --format ext2 tmp-supermin.d -o tmp-appliance.d
74
75 # Add the kernel and initrd to the image.
76 # We have to do this here, AFTER the build step, because we don't
77 # have the kernel & initrd before this.
78 "$guestfish" --format=raw -a tmp-appliance.d/root -m /dev/sda <<'EOF'
79   echo "Adding kernel and initrd to the disk image ..."
80   upload tmp-appliance.d/kernel /kernel
81   upload tmp-appliance.d/initrd /initrd
82
83   echo "Adjusting configuration files in the image ..."
84   mkdir-p /etc/modprobe.d
85   write /etc/modprobe.d/kvm.conf "options kvm_intel nested=1"
86 EOF
87
88 # Copy out the kernel, initrd and disk image.
89 mv tmp-appliance.d/kernel .
90 mv tmp-appliance.d/initrd .
91 qemu-img convert -f raw tmp-appliance.d/root -O qcow2 -c "$output"
92
93 #rm -rf tmp-supermin.d tmp-appliance.d