Statistics
| Branch: | Revision:

root / export @ 47c86659

History | View | Annotate | Download (2.5 kB)

1 79224631 Lance Albertson
#!/bin/bash
2 79224631 Lance Albertson
3 fe46a148 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 fe46a148 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 fe46a148 Lance Albertson
    ORIGINAL_BLOCKDEV=$blockdev
30 fe46a148 Lance Albertson
    blockdev=$($LOSETUP -sf $blockdev)
31 fe46a148 Lance Albertson
    CLEANUP+=("$LOSETUP -d $blockdev")
32 79224631 Lance Albertson
fi
33 79224631 Lance Albertson
34 8727c57d Lance Albertson
if [ ! "${NOMOUNT}" = "yes" ] ; then
35 8727c57d Lance Albertson
    filesystem_dev=$(map_disk0 $blockdev)
36 8727c57d Lance Albertson
    CLEANUP+=("unmap_disk0 $blockdev")
37 8727c57d Lance Albertson
    root_dev=$(map_partition $filesystem_dev root)
38 8727c57d Lance Albertson
    boot_dev=$(map_partition $filesystem_dev boot)
39 8727c57d Lance Albertson
fi
40 79224631 Lance Albertson
41 1b617fb5 Lance Albertson
TARGET=`mktemp -d` || exit 1
42 1b617fb5 Lance Albertson
CLEANUP+=("rmdir $TARGET")
43 1b617fb5 Lance Albertson
44 8727c57d Lance Albertson
if [ "${NOMOUNT}" = "yes" ] ; then
45 8727c57d Lance Albertson
    # convert block device to qcow2 image to support OS's like Windows. Use
46 8727c57d Lance Albertson
    # qcow2 to conserve on space.
47 8727c57d Lance Albertson
    $QEMU_IMG convert $blockdev -O qcow2 ${TARGET}/disk.img
48 8727c57d Lance Albertson
    CLEANUP+=("rm ${TARGET}/disk.img")
49 8727c57d Lance Albertson
else
50 8727c57d Lance Albertson
    vol_type_root="$($VOL_TYPE $root_dev)"
51 8727c57d Lance Albertson
    if [ -n "${boot_dev}" ] ; then
52 8727c57d Lance Albertson
        vol_type_boot="$($VOL_TYPE $boot_dev)"
53 39b1484a Lance Albertson
    fi
54 8727c57d Lance Albertson
55 8727c57d Lance Albertson
    for fs in boot root ; do
56 8727c57d Lance Albertson
        # use indirect reference to make the variables dynamic
57 8727c57d Lance Albertson
        dev="$(eval "echo \${$(echo ${fs}_dev)"})"
58 8727c57d Lance Albertson
        vol_type="$(eval echo \$vol_type_${fs})"
59 8727c57d Lance Albertson
        if [ -z "$vol_type" -a -n "${dev}" ] ; then
60 8727c57d Lance Albertson
            log_error "Unable to find ${fs} filesystem type at ${dev}"
61 77449e7c Lance Albertson
            exit 1
62 77449e7c Lance Albertson
        fi
63 8727c57d Lance Albertson
        if [ -n "${dev}" ] ; then
64 8727c57d Lance Albertson
            if [ "$vol_type" = "ext3" -o "$vol_type" = "ext2" \
65 8727c57d Lance Albertson
                    -o "$vol_type" = "ext4" ] ; then
66 8727c57d Lance Albertson
                $DUMP -0 -q -z9 -f ${TARGET}/${fs}.dump $dev
67 8727c57d Lance Albertson
                CLEANUP+=("rm ${TARGET}/${fs}.dump")
68 8727c57d Lance Albertson
            else
69 8727c57d Lance Albertson
                log_error "${fs} is not a supported filesystem. Please use ext{2,3,4}"
70 8727c57d Lance Albertson
                exit 1
71 8727c57d Lance Albertson
            fi
72 8727c57d Lance Albertson
        fi
73 8727c57d Lance Albertson
    done
74 8727c57d Lance Albertson
fi
75 dfec2908 Lance Albertson
76 39b1484a Lance Albertson
( cd $TARGET ; tar -cf - . )
77 79224631 Lance Albertson
78 79224631 Lance Albertson
# execute cleanups
79 79224631 Lance Albertson
cleanup
80 79224631 Lance Albertson
trap - EXIT
81 79224631 Lance Albertson
82 79224631 Lance Albertson
exit 0