Statistics
| Branch: | Revision:

root / create @ 12321cb5

History | View | Annotate | Download (2.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
    $MKDIR_P $TMPDIR/boot
56
    mount $boot_dev $TMPDIR/boot
57
    CLEANUP+=("umount $TMPDIR/boot")
58
    CLEANUP+=("umount $TMPDIR")
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
    RUN_PARTS=`which run-parts`
69

    
70
    if [ -n "$RUN_PARTS" -a -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" ]; then
71
      TARGET=$TMPDIR
72
      BLOCKDEV=$blockdev
73
      FSYSDEV=$filesystem_dev
74
      export TARGET SUITE ARCH PARTITION_STYLE EXTRA_PKGS BLOCKDEV FSYSDEV
75
      $RUN_PARTS $CUSTOMIZE_DIR
76
    fi
77
fi
78

    
79
# execute cleanups
80
cleanup
81
trap - EXIT
82

    
83
exit 0