Statistics
| Branch: | Revision:

root / import @ 6f0a1fef

History | View | Annotate | Download (2 kB)

1 79224631 Lance Albertson
#!/bin/bash
2 79224631 Lance Albertson
3 28b0b56c Lance Albertson
# Copyright (C) 2010 Oregon State University
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 6f0a1fef Lance Albertson
. common.sh
23 6f0a1fef Lance Albertson
24 28b0b56c Lance Albertson
if [ "${IMAGE_DEBUG}" = "1" ] ; then
25 28b0b56c Lance Albertson
    set -x
26 28b0b56c Lance Albertson
fi
27 28b0b56c Lance Albertson
28 79224631 Lance Albertson
# If the target device is not a real block device we'll first losetup it.
29 79224631 Lance Albertson
# This is needed for file disks.
30 79224631 Lance Albertson
if [ ! -b $blockdev ]; then
31 28b0b56c Lance Albertson
    ORIGINAL_BLOCKDEV=$blockdev
32 28b0b56c Lance Albertson
    blockdev=$($LOSETUP -sf $blockdev)
33 28b0b56c Lance Albertson
    CLEANUP+=("$LOSETUP -d $blockdev")
34 79224631 Lance Albertson
fi
35 79224631 Lance Albertson
36 28b0b56c Lance Albertson
format_disk0 $blockdev
37 28b0b56c Lance Albertson
filesystem_base_dev=$(map_disk0 $blockdev)
38 28b0b56c Lance Albertson
if [ "${SWAP}" = "yes" ] ; then
39 28b0b56c Lance Albertson
    boot_dev="${filesystem_base_dev}-1"
40 28b0b56c Lance Albertson
    swap_dev="${filesystem_base_dev}-2"
41 28b0b56c Lance Albertson
    root_dev="${filesystem_base_dev}-3"
42 79224631 Lance Albertson
else
43 28b0b56c Lance Albertson
    boot_dev="${filesystem_base_dev}-1"
44 28b0b56c Lance Albertson
    root_dev="${filesystem_base_dev}-2"
45 79224631 Lance Albertson
fi
46 28b0b56c Lance Albertson
CLEANUP+=("unmap_disk0 $blockdev")
47 79224631 Lance Albertson
48 28b0b56c Lance Albertson
mkfs_disk0 $boot_dev $root_dev $swap_dev
49 79224631 Lance Albertson
50 28b0b56c Lance Albertson
TARGET=`mktemp -d` || exit 1
51 28b0b56c Lance Albertson
CLEANUP+=("rmdir $TARGET")
52 79224631 Lance Albertson
53 28b0b56c Lance Albertson
mount_disk0 $TARGET $root_dev $boot_dev
54 79224631 Lance Albertson
55 28b0b56c Lance Albertson
( cd $TARGET; restore -r -y -f - )
56 28b0b56c Lance Albertson
rm -f $TARGET/etc/udev/rules.d/z*_persistent-net.rules
57 79224631 Lance Albertson
58 39855ac4 Lance Albertson
if [ -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" -a -x "$CUSTOMIZE_DIR/grub" ] ; then
59 39855ac4 Lance Albertson
    TARGET=$TARGET
60 39855ac4 Lance Albertson
    BLOCKDEV=$blockdev
61 39855ac4 Lance Albertson
    ROOT_DEV=$root_dev
62 39855ac4 Lance Albertson
    BOOT_DEV=$boot_dev
63 39855ac4 Lance Albertson
    export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV
64 39855ac4 Lance Albertson
    # Install grub since we're not deploying via qemu-img
65 39855ac4 Lance Albertson
    ${CUSTOMIZE_DIR}/grub
66 39855ac4 Lance Albertson
fi
67 39855ac4 Lance Albertson
68 79224631 Lance Albertson
# execute cleanups
69 79224631 Lance Albertson
cleanup
70 79224631 Lance Albertson
trap - EXIT
71 79224631 Lance Albertson
72 79224631 Lance Albertson
exit 0