Limit memory to 30000MB for ARM mach_virt.
[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         systemd
43         util-linux
44     "
45 elif [[ "$distro" =~ ^debian- ]]; then
46     packages="
47         bash
48         coreutils
49         grep
50         qemu-system-x86
51         sgabios
52         sysvinit-core
53         util-linux
54     "
55 else
56     echo "$0: $distro not known.  You need to edit this script to add support for this distro."
57     exit 1
58 fi
59
60 # Run the prepare step.
61 echo "Preparing the supermin appliance containing:" $packages
62 "$supermin" --prepare $packages -o tmp-supermin.d
63
64 # Add the init & run-supernested.sh scripts.
65 tar cf tmp-supermin.d/init.tar init run-supernested.sh
66
67 # Add the excludefiles.
68 cp excludefiles tmp-supermin.d/
69
70 # Run the build step.
71 echo "Building the full appliance ..."
72 echo "If you see 'Permission denied' errors here, you can probably ignore"
73 echo "them, but encourage your distro to stop using security-through-obscurity."
74 "$supermin" --build --format ext2 tmp-supermin.d -o tmp-appliance.d
75
76 # Add the kernel and initrd to the image.
77 # We have to do this here, AFTER the build step, because we don't
78 # have the kernel & initrd before this.
79 "$guestfish" --format=raw -a tmp-appliance.d/root -m /dev/sda <<'EOF'
80   echo "Adding kernel and initrd to the disk image ..."
81   upload tmp-appliance.d/kernel /kernel
82   upload tmp-appliance.d/initrd /initrd
83
84   echo "Adjusting configuration files in the image ..."
85   mkdir-p /etc/modprobe.d
86   write /etc/modprobe.d/kvm.conf "options kvm_intel nested=1"
87 EOF
88
89 # Copy out the kernel, initrd and disk image.
90 mv tmp-appliance.d/kernel .
91 mv tmp-appliance.d/initrd .
92 qemu-img convert -f raw tmp-appliance.d/root -O qcow2 "$output"
93
94 #rm -rf tmp-supermin.d tmp-appliance.d