Make $swapdev optional
authorGuido Trotter <ultrotter@google.com>
Thu, 16 Oct 2008 09:20:16 +0000 (09:20 +0000)
committerGuido Trotter <ultrotter@google.com>
Thu, 16 Oct 2008 09:20:16 +0000 (09:20 +0000)
In create and import we'll only use a swap device only if swapdev is
set.  This is for compatibility with the OS API version 10, where no swap
is going to be set up.

Reviewed-by: iustinp

create.in
import

index 2212286..ad6ccef 100755 (executable)
--- a/create.in
+++ b/create.in
@@ -48,10 +48,12 @@ CACHE_FILE="$CACHE_DIR/cache-${SUITE}-${DPKG_ARCH}.tar"
 
 . common.sh
 
-mkswap $swapdev
 mke2fs -Fjq $blockdev
-swap_uuid=$(/sbin/vol_id --uuid $swapdev )
 root_uuid=$(/sbin/vol_id --uuid $blockdev )
+if [ -n "$swapdev" ]; then
+  mkswap $swapdev
+  swap_uuid=$(/sbin/vol_id --uuid $swapdev )
+fi
 
 TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
@@ -111,10 +113,13 @@ cat > $TMPDIR/etc/fstab <<EOF
 #
 # <file system>   <mount point>   <type>  <options>       <dump>  <pass>
 UUID=$root_uuid   /               ext3    defaults        0       1
-UUID=$swap_uuid   swap            swap    defaults        0       0
 proc              /proc           proc    defaults        0       0
 EOF
 
+[ -n "$swapdev" ] && cat >> $TMPDIR/etc/fstab <<EOF
+UUID=$swap_uuid   swap            swap    defaults        0       0
+EOF
+
 cat > $TMPDIR/etc/network/interfaces <<EOF
 auto lo
 iface lo inet loopback
diff --git a/import b/import
index 0207fa6..2a4542e 100755 (executable)
--- a/import
+++ b/import
@@ -21,10 +21,12 @@ set -e
 
 . common.sh
 
-mkswap $swapdev
 mke2fs -Fjq $blockdev
-swap_uuid=$(/sbin/vol_id --uuid $swapdev )
 root_uuid=$(/sbin/vol_id --uuid $blockdev )
+if [ -n "$swapdev" ]; then
+  mkswap $swapdev
+  swap_uuid=$(/sbin/vol_id --uuid $swapdev )
+fi
 
 TMPDIR=`mktemp -d` || exit 1
 trap "umount $TMPDIR; rmdir $TMPDIR" EXIT
@@ -43,11 +45,17 @@ rm -f $TMPDIR/etc/udev/rules.d/z25_persistent-net.rules
 # Fix /etc/fstab with the new volumes' UUIDs
 if [ -e $TMPDIR/etc/fstab ]; then
   ROOT_LINE="UUID=$root_uuid  /     ext3  defaults  0  1"
-  SWAP_LINE="UUID=$swap_uuid  swap  swap  defaults  0  0"
-  cat $TMPDIR/etc/fstab | \
-    sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
-        -re "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \
-    > $TMPDIR/etc/fstab.new
+  if [ -n "$swapdev" ]; then
+    SWAP_LINE="UUID=$swap_uuid  swap  swap  defaults  0  0"
+    cat $TMPDIR/etc/fstab | \
+      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
+          -re "s#^(/dev/sdb|UUID=[a-f0-9-]+)\s+swap\s+.*\$#$SWAP_LINE#" \
+      > $TMPDIR/etc/fstab.new
+  else
+    cat $TMPDIR/etc/fstab | \
+      sed -re "s#^(/dev/sda|UUID=[a-f0-9-]+)\s+/\s+.*\$#$ROOT_LINE#" \
+      > $TMPDIR/etc/fstab.new
+  fi
   mv $TMPDIR/etc/fstab.new  $TMPDIR/etc/fstab
 fi