]> rtime.felk.cvut.cz Git - jailhouse.git/blob - tools/jailhouse-config-collect.tmpl
Merge remote-tracking branch 'kiszka/master'
[jailhouse.git] / tools / jailhouse-config-collect.tmpl
1 #!/bin/sh
2 #
3 # Jailhouse, a Linux-based partitioning hypervisor
4 #
5 # Copyright (c) Siemens AG, 2014
6 #
7 # This work is licensed under the terms of the GNU GPL, version 2.  See
8 # the COPYING file in the top-level directory.
9 #
10 # This script will collect information needed to generate a Jailhouse
11 # configuration for hypervisor and root cell (Linux).
12 #
13 # Run it like that:
14 #  $ jailhouse-config-collect.sh mytarget.tar
15 #
16 # Copying files and directories from /sys and /proc is surprisingly hard
17 # it would be nice to use just one tool together with the list of files.
18 # The main problem is that stat does not report the correct file sizes. In
19 # procfs files seem to have a size of 0 while in sysfs they often appear
20 # bigger than they really are.
21 # Archivers like tar/cpio etc. can not be used for procfs and sysfs.
22 # This script first gets a temporary copy of all the files we want. After
23 # copying the files can be archived with tar.
24
25 set -e
26
27 if test "x$( id -u )" != "x0"; then
28         echo "Please run as root" 1>&2
29         exit 1
30 fi
31
32 if test -z "$1"; then
33         echo "Usage: $0 mytarget.tar" 1>&2
34         exit 1
35 fi
36
37 filelist="${filelist}"
38 filelist_opt="${filelist_opt}"
39 filelist_intel="${filelist_intel}"
40 filelist_amd="${filelist_amd}"
41
42 tmpdir=/tmp/jailhouse-config-collect.$$
43
44 rm -rf $tmpdir
45 mkdir $tmpdir
46
47 copy_file()
48 {
49         dstdir=$tmpdir/$(dirname $1)
50         if [ ! -d $dstdir ]; then
51                 mkdir -p $dstdir
52         fi
53         cp -p $1 $tmpdir/$1
54 }
55
56 # copy all the files we need to a temporary directory first
57 for f in $filelist; do
58         copy_file $f
59 done
60 grep GenuineIntel /proc/cpuinfo > /dev/null &&
61         for f in $filelist_intel; do
62                 copy_file $f
63         done
64 grep AuthenticAMD /proc/cpuinfo > /dev/null &&
65         for f in $filelist_amd; do
66                 copy_file $f
67         done
68 for f in $filelist_opt; do
69         if [ -f $f ]; then
70                 copy_file $f
71         fi
72 done
73
74 # now archive it and remove temporary copy
75 tar -C $tmpdir -cf $1 .
76 rm -rf $tmpdir
77
78 exit 0