2170cecbd9a354bf3da90d8766d1a2c62b0b2e19
[libguestfs.git] / images / guest-aux / make-debian-img.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2010 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 # Make a Debian image which is enough to fool the inspection heuristics.
20
21 export LANG=C
22 set -e
23
24 # fstab file.
25 cat > fstab.tmp <<EOF
26 LABEL=BOOT /boot ext2 default 0 0
27 /dev/debian/root / ext2 default 0 0
28 /dev/debian/usr /usr ext2 default 1 2
29 /dev/debian/var /var ext2 default 1 2
30 /dev/debian/home /home ext2 default 1 2
31 EOF
32
33 # Create a disk image.
34 ../fish/guestfish <<'EOF'
35 sparse debian.img.tmp 512M
36 run
37
38 # Format the disk.
39 part-init /dev/sda mbr
40 part-add /dev/sda p 64     524287
41 part-add /dev/sda p 524288    -64
42
43 pvcreate /dev/sda2
44 vgcreate debian /dev/sda2
45 lvcreate root debian 64
46 lvcreate usr debian 32
47 lvcreate var debian 32
48 lvcreate home debian 32
49
50 # Phony /boot filesystem.
51 mkfs-opts ext2 /dev/sda1 blocksize:4096
52 set-e2label /dev/sda1 BOOT
53 set-e2uuid /dev/sda1 01234567-0123-0123-0123-012345678901
54
55 # Phony root and other filesystems.
56 mkfs-opts ext2 /dev/debian/root blocksize:4096
57 set-e2uuid /dev/debian/root 01234567-0123-0123-0123-012345678902
58 mkfs-opts ext2 /dev/debian/usr blocksize:4096
59 set-e2uuid /dev/debian/usr 01234567-0123-0123-0123-012345678903
60 mkfs-opts ext2 /dev/debian/var blocksize:4096
61 set-e2uuid /dev/debian/var 01234567-0123-0123-0123-012345678904
62 mkfs-opts ext2 /dev/debian/home blocksize:4096
63 set-e2uuid /dev/debian/home 01234567-0123-0123-0123-012345678905
64
65 # Enough to fool inspection API.
66 mount-options "" /dev/debian/root /
67 mkdir /boot
68 mount-options "" /dev/sda1 /boot
69 mkdir /usr
70 mount-options "" /dev/debian/usr /usr
71 mkdir /var
72 mount-options "" /dev/debian/var /var
73 mkdir /home
74 mount-options "" /dev/debian/home /home
75 mkdir /bin
76 mkdir /etc
77 mkdir-p /var/lib/dpkg
78
79 upload fstab.tmp /etc/fstab
80 write /etc/debian_version "5.0.1"
81 write /etc/hostname "debian.invalid"
82
83 upload guest-aux/debian-packages /var/lib/dpkg/status
84
85 upload bin-x86_64-dynamic /bin/ls
86
87 mkdir /boot/grub
88 touch /boot/grub/grub.conf
89 EOF
90
91 rm fstab.tmp
92 mv debian.img.tmp debian.img