Statistics
| Branch: | Revision:

root / create @ 916b6dd1

History | View | Annotate | Download (2.9 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 b05b1ab6 Lance Albertson
    if [ ! -f "$IMAGE_FILE" ] ; then
36 b05b1ab6 Lance Albertson
      log_error "Can't find image file: $IMAGE_FILE"
37 b05b1ab6 Lance Albertson
      exit 1
38 b05b1ab6 Lance Albertson
    fi
39 b05b1ab6 Lance Albertson
40 b05b1ab6 Lance Albertson
    # If the image is tarball based, then we need to manually create the
41 b05b1ab6 Lance Albertson
    # volumes, filesystems, etc
42 b05b1ab6 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
43 b05b1ab6 Lance Albertson
        # Create 3 partitions, /boot, swap, & /
44 b05b1ab6 Lance Albertson
        format_disk0 $blockdev
45 b05b1ab6 Lance Albertson
    elif [ "${IMAGE_TYPE}" = "qemu" ] ; then
46 b05b1ab6 Lance Albertson
        # need a recent version of qemu for this
47 b05b1ab6 Lance Albertson
        qemu-img convert ${IMAGE_FILE} -O host_device ${blockdev}
48 b05b1ab6 Lance Albertson
    fi
49 b05b1ab6 Lance Albertson
50 a1d43218 Lance Albertson
    filesystem_base_dev=$(map_disk0 $blockdev)
51 e21b8802 Lance Albertson
    if [ "${SWAP}" = "yes" ] ; then
52 e21b8802 Lance Albertson
        boot_dev="${filesystem_base_dev}-1"
53 e21b8802 Lance Albertson
        swap_dev="${filesystem_base_dev}-2"
54 e21b8802 Lance Albertson
        root_dev="${filesystem_base_dev}-3"
55 e21b8802 Lance Albertson
    else
56 e21b8802 Lance Albertson
        boot_dev="${filesystem_base_dev}-1"
57 e21b8802 Lance Albertson
        root_dev="${filesystem_base_dev}-2"
58 e21b8802 Lance Albertson
    fi
59 a1d43218 Lance Albertson
    CLEANUP+=("unmap_disk0 $blockdev")
60 fcce5224 Lance Albertson
61 b05b1ab6 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
62 b05b1ab6 Lance Albertson
        # Format /boot
63 b05b1ab6 Lance Albertson
        mke2fs -Fjq -L /boot $boot_dev
64 b05b1ab6 Lance Albertson
        # Format /
65 b05b1ab6 Lance Albertson
        mke2fs -Fjq -L / $root_dev
66 e21b8802 Lance Albertson
        if [ "${SWAP}" = "yes" ] ; then
67 e21b8802 Lance Albertson
            # Format swap
68 e21b8802 Lance Albertson
            mkswap $swap_dev
69 e21b8802 Lance Albertson
        fi
70 b05b1ab6 Lance Albertson
    fi
71 fcce5224 Lance Albertson
72 916b6dd1 Lance Albertson
    TARGET=`mktemp -d` || exit 1
73 916b6dd1 Lance Albertson
    CLEANUP+=("rmdir $TARGET")
74 fcce5224 Lance Albertson
75 a1d43218 Lance Albertson
    # mount filesystems
76 916b6dd1 Lance Albertson
    mount_disk0 $TARGET $root_dev $boot_dev
77 b05b1ab6 Lance Albertson
78 b05b1ab6 Lance Albertson
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
79 b05b1ab6 Lance Albertson
        # unpack image
80 916b6dd1 Lance Albertson
        tar pzxf $IMAGE_FILE -C $TARGET
81 b05b1ab6 Lance Albertson
    fi
82 e5ec11e4 Lance Albertson
83 fcce5224 Lance Albertson
    RUN_PARTS=`which run-parts`
84 fcce5224 Lance Albertson
85 fcce5224 Lance Albertson
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
86 916b6dd1 Lance Albertson
      TARGET=$TARGET
87 fcce5224 Lance Albertson
      BLOCKDEV=$blockdev
88 f7959feb Lance Albertson
      ROOT_DEV=$root_dev
89 c29e092d Lance Albertson
      BOOT_DEV=$boot_dev
90 f7959feb Lance Albertson
      export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV ROOT_DEV BOOT_DEV
91 fcce5224 Lance Albertson
      $RUN_PARTS $CUSTOMIZE_DIR
92 fcce5224 Lance Albertson
    fi
93 79224631 Lance Albertson
fi
94 79224631 Lance Albertson
95 79224631 Lance Albertson
# execute cleanups
96 79224631 Lance Albertson
cleanup
97 79224631 Lance Albertson
trap - EXIT
98 79224631 Lance Albertson
99 79224631 Lance Albertson
exit 0