Revision 28b0b56c

b/import
1 1
#!/bin/bash
2 2

  
3
# Copyright (C) 2007, 2008, 2009 Google Inc.
3
# Copyright (C) 2010 Oregon State University
4 4
#
5 5
# This program is free software; you can redistribute it and/or modify
6 6
# it under the terms of the GNU General Public License as published by
......
19 19

  
20 20
set -e
21 21

  
22
if [ "${IMAGE_DEBUG}" = "1" ] ; then
23
    set -x
24
fi
25

  
22 26
. common.sh
23 27

  
24 28
# If the target device is not a real block device we'll first losetup it.
25 29
# This is needed for file disks.
26 30
if [ ! -b $blockdev ]; then
27
  ORIGINAL_BLOCKDEV=$blockdev
28
  blockdev=$($LOSETUP -sf $blockdev)
29
  CLEANUP+=("$LOSETUP -d $blockdev")
31
    ORIGINAL_BLOCKDEV=$blockdev
32
    blockdev=$($LOSETUP -sf $blockdev)
33
    CLEANUP+=("$LOSETUP -d $blockdev")
30 34
fi
31 35

  
32
if [ "$PARTITION_STYLE" = "none" ]; then
33
  filesystem_dev=$blockdev
34
elif [ "$PARTITION_STYLE" = "msdos" ]; then
35
  # Create one big partition, and make it bootable
36
  format_disk0 $blockdev
37
  filesystem_dev=$(map_disk0 $blockdev)
38
  CLEANUP+=("unmap_disk0 $blockdev")
36
format_disk0 $blockdev
37
filesystem_base_dev=$(map_disk0 $blockdev)
38
if [ "${SWAP}" = "yes" ] ; then
39
    boot_dev="${filesystem_base_dev}-1"
40
    swap_dev="${filesystem_base_dev}-2"
41
    root_dev="${filesystem_base_dev}-3"
39 42
else
40
  echo "Unknown partition style $PARTITION_STYLE"
41
  exit 1
42
fi
43

  
44
mke2fs -Fjq $filesystem_dev
45
root_uuid=$($VOL_ID $filesystem_dev )
46

  
47
if [ -n "$swapdev" ]; then
48
  mkswap $swapdev
49
  swap_uuid=$($VOL_ID $swapdev || true )
43
    boot_dev="${filesystem_base_dev}-1"
44
    root_dev="${filesystem_base_dev}-2"
50 45
fi
46
CLEANUP+=("unmap_disk0 $blockdev")
51 47

  
52
TMPDIR=`mktemp -d` || exit 1
53
CLEANUP+=("rmdir $TMPDIR")
48
mkfs_disk0 $boot_dev $root_dev $swap_dev
54 49

  
55
mount $filesystem_dev $TMPDIR
56
CLEANUP+=("umount $TMPDIR")
50
TARGET=`mktemp -d` || exit 1
51
CLEANUP+=("rmdir $TARGET")
57 52

  
58
( cd $TMPDIR; restore -r -y -f - )
59
rm -f $TMPDIR/etc/udev/rules.d/z*_persistent-net.rules
53
mount_disk0 $TARGET $root_dev $boot_dev
60 54

  
61
# Fix /etc/fstab with the new volumes' UUIDs
62
if [ -e $TMPDIR/etc/fstab ]; then
63
  ROOT_LINE="UUID=$root_uuid  /     ext3  defaults  0  1"
64
  if [ -n "$swapdev" -a -n "$swap_uuid" ]; then
65
    SWAP_LINE="UUID=$swap_uuid  swap  swap  defaults  0  0"
66
    cat $TMPDIR/etc/fstab | \
67
      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
68
          -e "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \
69
      > $TMPDIR/etc/fstab.new
70
  else
71
    cat $TMPDIR/etc/fstab | \
72
      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
73
      > $TMPDIR/etc/fstab.new
74
  fi
75
  mv $TMPDIR/etc/fstab.new  $TMPDIR/etc/fstab
76
fi
55
( cd $TARGET; restore -r -y -f - )
56
rm -f $TARGET/etc/udev/rules.d/z*_persistent-net.rules
77 57

  
78 58
# execute cleanups
79 59
cleanup

Also available in: Unified diff