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