root / create @ baca98f3
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="" |
25 |
if [ "$IMAGE_TYPE" = "tarball" ] ; then |
26 |
IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz" |
27 |
elif [ "$IMAGE_TYPE" = "qemu" ] ; then |
28 |
IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img" |
29 |
fi |
30 |
|
31 |
if [ "$CDINSTALL" = "no" ] ; then |
32 |
# If the target device is not a real block device we'll first losetup it. |
33 |
# This is needed for file disks. |
34 |
if [ ! -b $blockdev ]; then |
35 |
ORIGINAL_BLOCKDEV=$blockdev |
36 |
blockdev=$($LOSETUP -sf $blockdev) |
37 |
CLEANUP+=("$LOSETUP -d $blockdev") |
38 |
fi |
39 |
|
40 |
if [ ! -f "$IMAGE_FILE" ] ; then |
41 |
log_error "Can't find image file: $IMAGE_FILE" |
42 |
exit 1 |
43 |
fi |
44 |
|
45 |
# If the image is tarball based, then we need to manually create the |
46 |
# volumes, filesystems, etc |
47 |
if [ "${IMAGE_TYPE}" = "tarball" ] ; then |
48 |
# Create 3 partitions, /boot, swap, & / |
49 |
format_disk0 $blockdev |
50 |
elif [ "${IMAGE_TYPE}" = "qemu" ] ; then |
51 |
# need a recent version of qemu for this |
52 |
${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev} |
53 |
fi |
54 |
|
55 |
filesystem_base_dev=$(map_disk0 $blockdev) |
56 |
if [ "${SWAP}" = "yes" ] ; then |
57 |
boot_dev="${filesystem_base_dev}-1" |
58 |
swap_dev="${filesystem_base_dev}-2" |
59 |
root_dev="${filesystem_base_dev}-3" |
60 |
else |
61 |
boot_dev="${filesystem_base_dev}-1" |
62 |
root_dev="${filesystem_base_dev}-2" |
63 |
fi |
64 |
CLEANUP+=("unmap_disk0 $blockdev") |
65 |
|
66 |
if [ "${IMAGE_TYPE}" = "tarball" ] ; then |
67 |
# Format /boot |
68 |
mke2fs -Fjq -L /boot $boot_dev |
69 |
# Format / |
70 |
mke2fs -Fjq -L / $root_dev |
71 |
if [ "${SWAP}" = "yes" ] ; then |
72 |
# Format swap |
73 |
mkswap $swap_dev |
74 |
fi |
75 |
fi |
76 |
|
77 |
TARGET=`mktemp -d` || exit 1 |
78 |
CLEANUP+=("rmdir $TARGET") |
79 |
|
80 |
# mount filesystems |
81 |
mount_disk0 $TARGET $root_dev $boot_dev |
82 |
|
83 |
if [ "${IMAGE_TYPE}" = "tarball" ] ; then |
84 |
# unpack image |
85 |
tar pzxf $IMAGE_FILE -C $TARGET |
86 |
fi |
87 |
|
88 |
RUN_PARTS=`which run-parts` |
89 |
|
90 |
if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then |
91 |
TARGET=$TARGET |
92 |
BLOCKDEV=$blockdev |
93 |
ROOT_DEV=$root_dev |
94 |
BOOT_DEV=$boot_dev |
95 |
export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV ROOT_DEV BOOT_DEV |
96 |
$RUN_PARTS $CUSTOMIZE_DIR |
97 |
fi |
98 |
fi |
99 |
|
100 |
# execute cleanups |
101 |
cleanup |
102 |
trap - EXIT |
103 |
|
104 |
exit 0 |