Statistics
| Branch: | Revision:

root / import @ 9f4b2c31

History | View | Annotate | Download (2.3 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
format_disk0 $blockdev
35 494927a8 Lance Albertson
filesystem_dev=$(map_disk0 $blockdev)
36 28b0b56c Lance Albertson
CLEANUP+=("unmap_disk0 $blockdev")
37 494927a8 Lance Albertson
root_dev=$(map_partition $filesystem_dev root)
38 494927a8 Lance Albertson
boot_dev=$(map_partition $filesystem_dev boot)
39 494927a8 Lance Albertson
swap_dev=$(map_partition $filesystem_dev swap)
40 79224631 Lance Albertson
41 77449e7c Lance Albertson
mkfs_disk0
42 3903b7f1 Lance Albertson
root_uuid="$($VOL_ID $root_dev)"
43 3903b7f1 Lance Albertson
[ -n "$boot_dev" ] && boot_uuid="$($VOL_ID $boot_dev)"
44 3903b7f1 Lance Albertson
[ -n "$swap_dev" ] && swap_uuid="$($VOL_ID $swap_dev)"
45 79224631 Lance Albertson
46 28b0b56c Lance Albertson
TARGET=`mktemp -d` || exit 1
47 28b0b56c Lance Albertson
CLEANUP+=("rmdir $TARGET")
48 39b1484a Lance Albertson
DUMPDIR=`mktemp -d` || exit 1
49 39b1484a Lance Albertson
CLEANUP+=("rm -rf $DUMPDIR")
50 79224631 Lance Albertson
51 77449e7c Lance Albertson
mount_disk0 $TARGET
52 79224631 Lance Albertson
53 39b1484a Lance Albertson
# import dumps from tar file
54 8d72e8d8 Lance Albertson
( cd $DUMPDIR; tar -xf - )
55 8d72e8d8 Lance Albertson
( cd $TARGET ; restore -r -y -f ${DUMPDIR}/root.dump )
56 77449e7c Lance Albertson
if [ -n "${boot_dev}" ] ; then
57 77449e7c Lance Albertson
    ( cd ${TARGET}/boot ; restore -r -y -f ${DUMPDIR}/boot.dump )
58 77449e7c Lance Albertson
fi
59 39b1484a Lance Albertson
60 3903b7f1 Lance Albertson
setup_fstab $TARGET
61 3903b7f1 Lance Albertson
62 9f4b2c31 Lance Albertson
if [ "${INSTANCE_HV_serial_console}" = "True" ] ; then
63 9f4b2c31 Lance Albertson
    setup_console $TARGET
64 9f4b2c31 Lance Albertson
fi
65 9f4b2c31 Lance Albertson
66 28b0b56c Lance Albertson
rm -f $TARGET/etc/udev/rules.d/z*_persistent-net.rules
67 79224631 Lance Albertson
68 39855ac4 Lance Albertson
if [ -n "$CUSTOMIZE_DIR" -a -d "$CUSTOMIZE_DIR" -a -x "$CUSTOMIZE_DIR/grub" ] ; then
69 39855ac4 Lance Albertson
    TARGET=$TARGET
70 39855ac4 Lance Albertson
    BLOCKDEV=$blockdev
71 39855ac4 Lance Albertson
    ROOT_DEV=$root_dev
72 39855ac4 Lance Albertson
    BOOT_DEV=$boot_dev
73 99cc268e Lance Albertson
    IMPORT_SCRIPT="1"
74 99cc268e Lance Albertson
    export TARGET SUITE BLOCKDEV ROOT_DEV BOOT_DEV IMPORT_SCRIPT
75 39855ac4 Lance Albertson
    # Install grub since we're not deploying via qemu-img
76 39855ac4 Lance Albertson
    ${CUSTOMIZE_DIR}/grub
77 39855ac4 Lance Albertson
fi
78 39855ac4 Lance Albertson
79 79224631 Lance Albertson
# execute cleanups
80 79224631 Lance Albertson
cleanup
81 79224631 Lance Albertson
trap - EXIT
82 79224631 Lance Albertson
83 79224631 Lance Albertson
exit 0