Implement PARTITION_STYLE='msdos'
authorGuido Trotter <ultrotter@google.com>
Wed, 28 Jan 2009 12:03:34 +0000 (12:03 +0000)
committerGuido Trotter <ultrotter@google.com>
Wed, 28 Jan 2009 12:03:34 +0000 (12:03 +0000)
With this partition style the blockdev passed in from ganeti is used as
a whole disk, a partition table is written on it, then a single primary
partition spanning the whole disk, and at last the os is installed in
this partition.

Reviewed-by: iustinp

README
create.in

diff --git a/README b/README
index fec0722..271bdd7 100644 (file)
--- a/README
+++ b/README
@@ -66,6 +66,9 @@ named 'defaults' in the source distribution for more details):
   otherwise, the value of this variable will be taken as the number of
   days after which to remove the cache file; the default is 14 (two
   weeks)
+- PARTITION_STYLE: if 'none' the device will be formatted directly, if 'msdos'
+  a partition table will be installed on it. You need to have kpartx installed
+  to use the 'msdos' option.
 
 Note that the settings file is important on the node that the instance
 is installed on, not the cluster master. This is indeed not a very good
index 315adc7..a32df5c 100755 (executable)
--- a/create.in
+++ b/create.in
@@ -71,13 +71,28 @@ if [ ! -b $blockdev ]; then
   CLEANUP+=("losetup -d $blockdev")
 fi
 
-if [ "$PARTITION_STYLE" != "none" ]; then
+if [ "$PARTITION_STYLE" = "none" ]; then
+  filesystem_dev=$blockdev
+elif [ "$PARTITION_STYLE" = "msdos" ]; then
+  # Create one big partition, and make it bootable
+  sfdisk --quiet --Linux $blockdev <<EOF
+0,,L,*
+EOF
+  block_base=`basename $blockdev`
+  filesystem_dev_base=`kpartx -l -p- $blockdev | \
+                       grep -m 1 "^$block_base.*$blockdev" | \
+                       awk '{print $1}'`
+  kpartx -a -p- $blockdev
+  CLEANUP+=("kpartx -d -p- $blockdev")
+  filesystem_dev="/dev/mapper/$filesystem_dev_base"
+else
   echo "Unknown partition style $PARTITION_STYLE"
   exit 1
 fi
 
-mke2fs -Fjq $blockdev
-root_uuid=$($VOL_ID -u $blockdev )
+mke2fs -Fjq $filesystem_dev
+root_uuid=$($VOL_ID -u $filesystem_dev )
+
 if [ -n "$swapdev" ]; then
   mkswap $swapdev
   swap_uuid=$($VOL_ID -u $swapdev )
@@ -86,7 +101,7 @@ fi
 TMPDIR=`mktemp -d` || exit 1
 CLEANUP+=("rmdir $TMPDIR")
 
-mount $blockdev $TMPDIR
+mount $filesystem_dev $TMPDIR
 CLEANUP+=("umount $TMPDIR")
 
 # remove the cache file if it's old (> 2 weeks) and writable by the owner (the