Statistics
| Branch: | Revision:

root / create @ e84e87cd

History | View | Annotate | Download (3.1 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
if [ "${DEBUG_LEVEL} " = 1 ] ; then
23
    set -x
24
fi
25

    
26
. common.sh
27

    
28
IMAGE_FILE=""
29
if [ "$IMAGE_TYPE" = "tarball" ] ; then
30
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.tar.gz"
31
elif [ "$IMAGE_TYPE" = "qemu" ] ; then
32
    IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME}-${ARCH}.img"
33
fi
34

    
35
if [ "$CDINSTALL" = "no" ] ; then
36
    # If the target device is not a real block device we'll first losetup it.
37
    # This is needed for file disks.
38
    if [ ! -b $blockdev ]; then
39
      ORIGINAL_BLOCKDEV=$blockdev
40
      blockdev=$($LOSETUP -sf $blockdev)
41
      CLEANUP+=("$LOSETUP -d $blockdev")
42
    fi
43

    
44
    if [ ! -f "$IMAGE_FILE" ] ; then
45
      log_error "Can't find image file: $IMAGE_FILE"
46
      exit 1
47
    fi
48

    
49
    # If the image is tarball based, then we need to manually create the
50
    # volumes, filesystems, etc
51
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
52
        # Create 3 partitions, /boot, swap, & /
53
        format_disk0 $blockdev
54
    elif [ "${IMAGE_TYPE}" = "qemu" ] ; then
55
        # need a recent version of qemu for this
56
        ${QEMU_IMG} convert ${IMAGE_FILE} -O host_device ${blockdev}
57
    fi
58

    
59
    filesystem_base_dev=$(map_disk0 $blockdev)
60
    if [ "${SWAP}" = "yes" ] ; then
61
        boot_dev="${filesystem_base_dev}-1"
62
        swap_dev="${filesystem_base_dev}-2"
63
        root_dev="${filesystem_base_dev}-3"
64
    else
65
        boot_dev="${filesystem_base_dev}-1"
66
        root_dev="${filesystem_base_dev}-2"
67
    fi
68
    CLEANUP+=("unmap_disk0 $blockdev")
69

    
70
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
71
        # Format /boot
72
        mke2fs -Fjq -L /boot $boot_dev
73
        # Format /
74
        mke2fs -Fjq -L / $root_dev
75
        if [ "${SWAP}" = "yes" ] ; then
76
            # Format swap
77
            mkswap $swap_dev
78
        fi
79
    fi
80

    
81
    TARGET=`mktemp -d` || exit 1
82
    CLEANUP+=("rmdir $TARGET")
83

    
84
    # mount filesystems
85
    mount_disk0 $TARGET $root_dev $boot_dev
86

    
87
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
88
        # unpack image
89
        tar pzxf $IMAGE_FILE -C $TARGET
90
    fi
91

    
92
    RUN_PARTS=`which run-parts`
93

    
94
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
95
      TARGET=$TARGET
96
      BLOCKDEV=$blockdev
97
      ROOT_DEV=$root_dev
98
      BOOT_DEV=$boot_dev
99
      export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV ROOT_DEV BOOT_DEV
100
      $RUN_PARTS $CUSTOMIZE_DIR
101
    fi
102
fi
103

    
104
# execute cleanups
105
cleanup
106
trap - EXIT
107

    
108
exit 0