3 # Copyright (C) 2007, 2008, 2009 Google Inc.
4 # Portions Copyright 2013 Equinox Software, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 # If the target device is not a real block device we'll first losetup it.
26 # This is needed for file disks.
27 if [ ! -b $blockdev ]; then
28 ORIGINAL_BLOCKDEV=$blockdev
29 blockdev=$(losetup -sf $blockdev)
30 CLEANUP+=("losetup -d $blockdev")
33 # First line in the dump contains the partion and/or
36 if [ "$export_type" = "swap" ]; then
41 if [ "$PARTITION_STYLE" = "none" ]; then
42 filesystem_dev=$blockdev
43 elif [ "$PARTITION_STYLE" = "msdos" ]; then
44 # Create one big partition, and make it bootable
45 format_disk0 $blockdev
46 filesystem_dev=$(map_disk0 $blockdev)
47 CLEANUP+=("unmap_disk0 $blockdev")
49 echo "Unknown partition style $PARTITION_STYLE"
53 mke2fs -Fjq $filesystem_dev
54 root_uuid=$($VOL_ID $filesystem_dev )
56 if [ -n "$swapdev" ]; then
58 swap_uuid=$($VOL_ID $swapdev || true )
61 TMPDIR=`mktemp -d` || exit 1
62 CLEANUP+=("rmdir $TMPDIR")
64 mount $filesystem_dev $TMPDIR
65 CLEANUP+=("umount $TMPDIR")
67 ( cd $TMPDIR; restore -r -y -f - )
68 rm -f $TMPDIR/etc/udev/rules.d/z*_persistent-net.rules
70 # Fix /etc/fstab with the new volumes' UUIDs
71 if [ -e $TMPDIR/etc/fstab ]; then
72 ROOT_LINE="UUID=$root_uuid / ext3 defaults 0 1"
73 if [ -n "$swapdev" -a -n "$swap_uuid" ]; then
74 SWAP_LINE="UUID=$swap_uuid swap swap defaults 0 0"
75 cat $TMPDIR/etc/fstab | \
76 sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
77 -e "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \
78 > $TMPDIR/etc/fstab.new
80 cat $TMPDIR/etc/fstab | \
81 sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
82 > $TMPDIR/etc/fstab.new
84 mv $TMPDIR/etc/fstab.new $TMPDIR/etc/fstab