Statistics
| Branch: | Revision:

root / create @ f7959feb

History | View | Annotate | Download (2.7 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
    if [ ! -f "$IMAGE_FILE" ] ; then
36
      log_error "Can't find image file: $IMAGE_FILE"
37
      exit 1
38
    fi
39

    
40
    # If the image is tarball based, then we need to manually create the
41
    # volumes, filesystems, etc
42
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
43
        # Create 3 partitions, /boot, swap, & /
44
        format_disk0 $blockdev
45
    elif [ "${IMAGE_TYPE}" = "qemu" ] ; then
46
        # need a recent version of qemu for this
47
        qemu-img convert ${IMAGE_FILE} -O host_device ${blockdev}
48
    fi
49

    
50
    filesystem_base_dev=$(map_disk0 $blockdev)
51
    root_dev="${filesystem_base_dev}-3"
52
    boot_dev="${filesystem_base_dev}-1"
53
    swap_dev="${filesystem_base_dev}-2"
54
    CLEANUP+=("unmap_disk0 $blockdev")
55

    
56
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
57
        # Format /boot
58
        mke2fs -Fjq -L /boot $boot_dev
59
        # Format /
60
        mke2fs -Fjq -L / $root_dev
61
        # Format swap
62
        mkswap $swap_dev
63
    fi
64

    
65
    TMPDIR=`mktemp -d` || exit 1
66
    CLEANUP+=("rmdir $TMPDIR")
67

    
68
    # mount filesystems
69
    mount_disk0 $TMPDIR $root_dev $boot_dev
70

    
71
    if [ "${IMAGE_TYPE}" = "tarball" ] ; then
72
        # unpack image
73
        tar pzxf $IMAGE_FILE -C $TMPDIR
74
    fi
75

    
76
    RUN_PARTS=`which run-parts`
77

    
78
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
79
      TARGET=$TMPDIR
80
      BLOCKDEV=$blockdev
81
      ROOT_DEV=$root_dev
82
      BOOT_DEV=$root_dev
83
      export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV ROOT_DEV BOOT_DEV
84
      $RUN_PARTS $CUSTOMIZE_DIR
85
    fi
86
fi
87

    
88
# execute cleanups
89
cleanup
90
trap - EXIT
91

    
92
exit 0