Statistics
| Branch: | Revision:

root / import @ 8afaedb3

History | View | Annotate | Download (2.6 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 e7a2d1ad Lance Albertson
debug set -x
25 28b0b56c Lance Albertson
26 79224631 Lance Albertson
# If the target device is not a real block device we'll first losetup it.
27 79224631 Lance Albertson
# This is needed for file disks.
28 79224631 Lance Albertson
if [ ! -b $blockdev ]; then
29 28b0b56c Lance Albertson
    ORIGINAL_BLOCKDEV=$blockdev
30 28b0b56c Lance Albertson
    blockdev=$($LOSETUP -sf $blockdev)
31 28b0b56c Lance Albertson
    CLEANUP+=("$LOSETUP -d $blockdev")
32 79224631 Lance Albertson
fi
33 79224631 Lance Albertson
34 28b0b56c Lance Albertson
TARGET=`mktemp -d` || exit 1
35 28b0b56c Lance Albertson
CLEANUP+=("rmdir $TARGET")
36 39b1484a Lance Albertson
DUMPDIR=`mktemp -d` || exit 1
37 39b1484a Lance Albertson
CLEANUP+=("rm -rf $DUMPDIR")
38 79224631 Lance Albertson
39 8727c57d Lance Albertson
if [ ! "${NOMOUNT}" = "yes" ] ; then
40 8727c57d Lance Albertson
    format_disk0 $blockdev
41 8727c57d Lance Albertson
    filesystem_dev=$(map_disk0 $blockdev)
42 8727c57d Lance Albertson
    CLEANUP+=("unmap_disk0 $blockdev")
43 8727c57d Lance Albertson
    root_dev=$(map_partition $filesystem_dev root)
44 8727c57d Lance Albertson
    boot_dev=$(map_partition $filesystem_dev boot)
45 8727c57d Lance Albertson
    swap_dev=$(map_partition $filesystem_dev swap)
46 39b1484a Lance Albertson
47 8727c57d Lance Albertson
    mkfs_disk0
48 8727c57d Lance Albertson
    root_uuid="$($VOL_ID $root_dev)"
49 8727c57d Lance Albertson
    [ -n "$boot_dev" ] && boot_uuid="$($VOL_ID $boot_dev)"
50 8727c57d Lance Albertson
    [ -n "$swap_dev" ] && swap_uuid="$($VOL_ID $swap_dev)"
51 3903b7f1 Lance Albertson
52 8727c57d Lance Albertson
    mount_disk0 $TARGET
53 9f4b2c31 Lance Albertson
fi
54 9f4b2c31 Lance Albertson
55 8727c57d Lance Albertson
# import dumps from tar file
56 8727c57d Lance Albertson
( cd $DUMPDIR; tar -xf - )
57 8727c57d Lance Albertson
58 8727c57d Lance Albertson
if [ "${NOMOUNT}" = "yes" ] ; then
59 8727c57d Lance Albertson
    ( $QEMU_IMG convert ${DUMPDIR}/disk.img -O host_device ${blockdev} )
60 8727c57d Lance Albertson
else
61 8727c57d Lance Albertson
    ( cd $TARGET ; restore -r -y -f ${DUMPDIR}/root.dump )
62 8727c57d Lance Albertson
    if [ -n "${boot_dev}" ] ; then
63 8727c57d Lance Albertson
        ( cd ${TARGET}/boot ; restore -r -y -f ${DUMPDIR}/boot.dump )
64 8727c57d Lance Albertson
    fi
65 8727c57d Lance Albertson
66 8727c57d Lance Albertson
    setup_fstab $TARGET
67 8727c57d Lance Albertson
68 8727c57d Lance Albertson
    if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then
69 8727c57d Lance Albertson
        setup_console $TARGET
70 8727c57d Lance Albertson
    fi
71 8727c57d Lance Albertson
72 8727c57d Lance Albertson
    rm -f $TARGET/etc/udev/rules.d/z*_persistent-net.rules
73 8727c57d Lance Albertson
74 8727c57d Lance Albertson
    if [ -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" -a -x "$CUSTOMIZE_DIR/grub" ] ; then
75 8727c57d Lance Albertson
        TARGET=$TARGET
76 8727c57d Lance Albertson
        BLOCKDEV=$blockdev
77 8727c57d Lance Albertson
        ROOT_DEV=$root_dev
78 8727c57d Lance Albertson
        BOOT_DEV=$boot_dev
79 8727c57d Lance Albertson
        IMPORT_SCRIPT="1"
80 8727c57d Lance Albertson
        export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV IMPORT_SCRIPT
81 8727c57d Lance Albertson
        # Install grub since we're not deploying via qemu-img
82 8727c57d Lance Albertson
        ${CUSTOMIZE_DIR}/grub
83 8727c57d Lance Albertson
    fi
84 af758a63 Lance Albertson
fi
85 39855ac4 Lance Albertson
86 79224631 Lance Albertson
# execute cleanups
87 79224631 Lance Albertson
cleanup
88 79224631 Lance Albertson
trap - EXIT
89 79224631 Lance Albertson
90 79224631 Lance Albertson
exit 0