root / create @ 89991658
History | View | Annotate | Download (3 kB)
1 | 79224631 | Lance Albertson | #!/bin/bash |
---|---|---|---|
2 | 79224631 | Lance Albertson | |
3 | 79224631 | Lance Albertson | # Copyright (C) 2007, 2008, 2009 Google Inc. |
4 | 79224631 | Lance Albertson | # |
5 | 79224631 | Lance Albertson | # This program is free software; you can redistribute it and/or modify |
6 | 79224631 | Lance Albertson | # it under the terms of the GNU General Public License as published by |
7 | 79224631 | Lance Albertson | # the Free Software Foundation; either version 2 of the License, or |
8 | 79224631 | Lance Albertson | # (at your option) any later version. |
9 | 79224631 | Lance Albertson | # |
10 | 79224631 | Lance Albertson | # This program is distributed in the hope that it will be useful, but |
11 | 79224631 | Lance Albertson | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | 79224631 | Lance Albertson | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | 79224631 | Lance Albertson | # General Public License for more details. |
14 | 79224631 | Lance Albertson | # |
15 | 79224631 | Lance Albertson | # You should have received a copy of the GNU General Public License |
16 | 79224631 | Lance Albertson | # along with this program; if not, write to the Free Software |
17 | 79224631 | Lance Albertson | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 79224631 | Lance Albertson | # 02110-1301, USA. |
19 | 79224631 | Lance Albertson | |
20 | 79224631 | Lance Albertson | set -e |
21 | 79224631 | Lance Albertson | |
22 | 79224631 | Lance Albertson | . common.sh |
23 | 79224631 | Lance Albertson | |
24 | 134c11c3 | Lance Albertson | IMAGE_FILE="$IMAGE_DIR/image-$IMAGE_NAME-$ARCH.tar.gz" |
25 | 134c11c3 | Lance Albertson | |
26 | fcce5224 | Lance Albertson | if [ "$CDINSTALL" = "no" ] ; then |
27 | fcce5224 | Lance Albertson | # If the target device is not a real block device we'll first losetup it. |
28 | fcce5224 | Lance Albertson | # This is needed for file disks. |
29 | fcce5224 | Lance Albertson | if [ ! -b $blockdev ]; then |
30 | fcce5224 | Lance Albertson | ORIGINAL_BLOCKDEV=$blockdev |
31 | fcce5224 | Lance Albertson | blockdev=$($LOSETUP -sf $blockdev) |
32 | fcce5224 | Lance Albertson | CLEANUP+=("$LOSETUP -d $blockdev") |
33 | fcce5224 | Lance Albertson | fi |
34 | fcce5224 | Lance Albertson | |
35 | a1d43218 | Lance Albertson | # Create 3 partitions, /boot, swap, & / |
36 | a1d43218 | Lance Albertson | format_disk0 $blockdev |
37 | a1d43218 | Lance Albertson | filesystem_base_dev=$(map_disk0 $blockdev) |
38 | a1d43218 | Lance Albertson | root_dev="${filesystem_base_dev}-3" |
39 | a1d43218 | Lance Albertson | boot_dev="${filesystem_base_dev}-1" |
40 | a1d43218 | Lance Albertson | swap_dev="${filesystem_base_dev}-2" |
41 | a1d43218 | Lance Albertson | CLEANUP+=("unmap_disk0 $blockdev") |
42 | fcce5224 | Lance Albertson | |
43 | a1d43218 | Lance Albertson | # Format /boot |
44 | a1d43218 | Lance Albertson | mke2fs -Fjq $boot_dev |
45 | a1d43218 | Lance Albertson | # Format / |
46 | a1d43218 | Lance Albertson | mke2fs -Fjq $root_dev |
47 | a1d43218 | Lance Albertson | # Format swap |
48 | a1d43218 | Lance Albertson | mkswap $swap_dev |
49 | fcce5224 | Lance Albertson | |
50 | fcce5224 | Lance Albertson | TMPDIR=`mktemp -d` || exit 1 |
51 | fcce5224 | Lance Albertson | CLEANUP+=("rmdir $TMPDIR") |
52 | fcce5224 | Lance Albertson | |
53 | a1d43218 | Lance Albertson | # mount filesystems |
54 | a1d43218 | Lance Albertson | mount $root_dev $TMPDIR |
55 | 135a14d0 | Lance Albertson | CLEANUP+=("umount $TMPDIR") |
56 | 12321cb5 | Lance Albertson | $MKDIR_P $TMPDIR/boot |
57 | a1d43218 | Lance Albertson | mount $boot_dev $TMPDIR/boot |
58 | a1d43218 | Lance Albertson | CLEANUP+=("umount $TMPDIR/boot") |
59 | fcce5224 | Lance Albertson | |
60 | 134c11c3 | Lance Albertson | if [ ! -f "$IMAGE_FILE" ] ; then |
61 | 134c11c3 | Lance Albertson | log_error "Can't find image file: $IMAGE_FILE" |
62 | 134c11c3 | Lance Albertson | exit 1 |
63 | 134c11c3 | Lance Albertson | fi |
64 | 134c11c3 | Lance Albertson | |
65 | 134c11c3 | Lance Albertson | # unpack image |
66 | 134c11c3 | Lance Albertson | tar pzxf $IMAGE_FILE -C $TMPDIR |
67 | a1d43218 | Lance Albertson | |
68 | e5ec11e4 | Lance Albertson | # Set disk based on type of hypervisor |
69 | e5ec11e4 | Lance Albertson | if [ "$HYPERVISOR" = "kvm" ] ; then |
70 | e5ec11e4 | Lance Albertson | disk="vda" |
71 | e5ec11e4 | Lance Albertson | else |
72 | e5ec11e4 | Lance Albertson | disk="xda" |
73 | e5ec11e4 | Lance Albertson | fi |
74 | e5ec11e4 | Lance Albertson | |
75 | e5ec11e4 | Lance Albertson | # make /dev/$disk |
76 | e5ec11e4 | Lance Albertson | mknod $TMPDIR/dev/$disk b $(stat -L -c "0x%t 0x%T" $blockdev) |
77 | e5ec11e4 | Lance Albertson | CLEANUP+=("rm -f $TMPDIR/dev/$disk") |
78 | e5ec11e4 | Lance Albertson | |
79 | e5ec11e4 | Lance Albertson | # make /dev/${disk}1 |
80 | e5ec11e4 | Lance Albertson | mknod $TMPDIR/dev/${disk}1 b $(stat -L -c "0x%t 0x%T" $boot_dev) |
81 | e5ec11e4 | Lance Albertson | CLEANUP+=("rm -f $TMPDIR/dev/${disk}1") |
82 | e5ec11e4 | Lance Albertson | |
83 | e5ec11e4 | Lance Albertson | # make /dev/${disk}1 |
84 | e5ec11e4 | Lance Albertson | mknod $TMPDIR/dev/${disk}3 b $(stat -L -c "0x%t 0x%T" $root_dev) |
85 | e5ec11e4 | Lance Albertson | CLEANUP+=("rm -f $TMPDIR/dev/${disk}3") |
86 | e5ec11e4 | Lance Albertson | |
87 | e5ec11e4 | Lance Albertson | # create device.map |
88 | e5ec11e4 | Lance Albertson | cat > "$TMPDIR/boot/grub/device.map" <<EOF |
89 | e5ec11e4 | Lance Albertson | (hd0) /dev/$disk |
90 | e5ec11e4 | Lance Albertson | EOF |
91 | e5ec11e4 | Lance Albertson | |
92 | e5ec11e4 | Lance Albertson | # install grub to the block device |
93 | 89991658 | Lance Albertson | chroot $TMPDIR grub --batch --no-floppy --device-map=/boot/grub/device.map <<EOF |
94 | 89991658 | Lance Albertson | root (hd0,0) |
95 | 89991658 | Lance Albertson | setup (hd0) |
96 | 89991658 | Lance Albertson | quit |
97 | 89991658 | Lance Albertson | EOF |
98 | e5ec11e4 | Lance Albertson | |
99 | fcce5224 | Lance Albertson | RUN_PARTS=`which run-parts` |
100 | fcce5224 | Lance Albertson | |
101 | fcce5224 | Lance Albertson | if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then |
102 | fcce5224 | Lance Albertson | TARGET=$TMPDIR |
103 | fcce5224 | Lance Albertson | BLOCKDEV=$blockdev |
104 | fcce5224 | Lance Albertson | FSYSDEV=$filesystem_dev |
105 | fcce5224 | Lance Albertson | export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV FSYSDEV |
106 | fcce5224 | Lance Albertson | $RUN_PARTS $CUSTOMIZE_DIR |
107 | fcce5224 | Lance Albertson | fi |
108 | 79224631 | Lance Albertson | fi |
109 | 79224631 | Lance Albertson | |
110 | 79224631 | Lance Albertson | # execute cleanups |
111 | 79224631 | Lance Albertson | cleanup |
112 | 79224631 | Lance Albertson | trap - EXIT |
113 | 79224631 | Lance Albertson | |
114 | 79224631 | Lance Albertson | exit 0 |