File bundle-vol-copy-fs-info.patch of Package euca2ools
Description: euca-bundle-vol: copy fs label, uuid, fs_type
If the bootloader is configured to locate the disk that the kernel/ramdisk
lives on via filesystem "label" or "uuid", then euca-bundle-vol must
either copy that label and uuid, or modify the boot loader configuration
(/boot/grub/menu.lst or /boot/grub/grub.cfg).
.
It seems safer to copy filesystem attributes so that no parsing or
updating of the target filesystem is needed.
Author: Scott Moser <scott.moser@canonical.com>
Last-Update: 2011-01-12
Bug: https://bugs.launchpad.net/euca2ools/+bug/667793
Bug: https://bugs.launchpad.net/euca2ools/+bug/672986
Forwarded: yes
--- a/bin/euca-bundle-vol
+++ b/bin/euca-bundle-vol
@@ -41,6 +41,8 @@
NotFoundError, CommandFailed, UnsupportedException
from subprocess import *
import platform
+import tempfile
+import stat
usage_string = \
"""
@@ -193,6 +195,36 @@
if os.path.exists(path):
os.remove(path)
+def get_fs_info(path):
+ fs_type = None
+ uuid = None
+ label = None
+ devpth = None
+ tmpd = None
+ try:
+ st_dev=os.stat(path).st_dev
+ dev=os.makedev(os.major(st_dev),os.minor(st_dev))
+ tmpd=tempfile.mkdtemp()
+ devpth=("%s/dev" % tmpd)
+ os.mknod(devpth,0400 | stat.S_IFBLK ,dev)
+ except:
+ raise
+
+ ret = { }
+ pairs = { 'LABEL' : 'label', 'UUID' : 'uuid' , 'TYPE' : 'fs_type' }
+ for (blkid_n, my_n) in pairs.iteritems():
+ cmd = [ 'blkid', '-s%s' % blkid_n, '-ovalue', devpth ]
+ try:
+ output = Popen(cmd, stdout=PIPE).communicate()[0]
+ ret[my_n]=output.rstrip()
+ except Exception, e:
+ os.unlink(devpth)
+ os.rmdir(tmpd)
+ raise UnsupportedException("Unable to determine %s for %s" % (blkid_n, path))
+
+ os.unlink(devpth)
+ os.rmdir(tmpd)
+ return(ret)
def main():
euca = None
@@ -366,9 +398,18 @@
if product_code_string:
product_codes = add_product_codes(product_code_string,
product_codes)
+
+ try:
+ fsinfo = get_fs_info(volume_path)
+ except UnsupportedException, e:
+ print e
+ sys.exit(1)
try:
image_path = euca.make_image(size_in_MB, excludes, prefix,
- destination_path)
+ destination_path,
+ fs_type=fsinfo['fs_type'], uuid=fsinfo['uuid'],
+ label=fsinfo['label'])
+
except NotFoundError:
sys.exit(1)
except UnsupportedException:
--- a/euca2ools/euca2ools/__init__.py
+++ b/euca2ools/euca2ools/__init__.py
@@ -211,13 +211,40 @@
print 'Creating disk image...', image_path
Popen(dd_cmd, PIPE).communicate()[0]
- def make_fs(self, image_path):
- Util().check_prerequisite_command(self.MAKEFS_CMD)
+ def make_fs(self, image_path, fs_type = None, uuid = None, label = None):
+ mkfs_prog = self.MAKEFS_CMD
+ if fs_type:
+ mkfs_prog = "mkfs.%s" % fs_type
+ else:
+ fs_type = "ext3"
+
+ tunecmd = [ ]
+ if fs_type.startswith("ext"):
+ mkfs = [ mkfs_prog , '-F', image_path ]
+ if uuid: mkfs.extend([ '-U', uuid ])
+ if label: mkfs.extend([ '-L', label ])
+ elif fs_type == "xfs":
+ mkfs = [ mkfs_prog , image_path ]
+ if label: mkfs.extend([ '-L', label ])
+ tunecmd = [ 'xfs_admin', '-U', uuid ]
+
+ elif fs_type == "btrfs":
+ if uuid: raise(UnsupportedException("btrfs with uuid not supported"))
+ if label: mkfs.extend([ '-L', label ])
+ else:
+ raise(UnsupportedException("unsupported fs %s" % fs_type))
+
+
+ Util().check_prerequisite_command(mkfs_prog)
if self.debug:
- print 'Creating filesystem...'
- makefs_cmd = Popen([self.MAKEFS_CMD, '-F', image_path],
- PIPE).communicate()[0]
+ print 'Creating filesystem with %s' % mkfs
+
+ makefs_cmd = Popen(mkfs,PIPE).communicate()[0]
+
+ if len(tunecmd):
+ Util().check_prerequisite_command(tunecmd[0])
+ tune_cmd = Popen(tunecmd,PIPE).communicate[0]
def add_fstab(
self,
@@ -290,7 +317,7 @@
print 'Sorry. Solaris not supported yet'
raise UnsupportedException
- def make_fs(self, image_path):
+ def make_fs(self, image_path, fstype = None, uuid = None, label = None):
print 'Sorry. Solaris not supported yet'
raise UnsupportedException
@@ -425,8 +452,11 @@
class UnsupportedException:
- def __init__(self):
- self.message = 'Not supported'
+ def __init__(self, msg=None):
+ if msg:
+ self.message = 'Not supported: %s' % msg
+ else:
+ self.message = 'Not supported'
class CommandFailed:
@@ -1209,6 +1239,7 @@
excludes,
prefix,
destination_path,
+ fs_type = None, uuid = None, label = None
):
image_file = '%s.img' % prefix
image_path = '%s/%s' % (destination_path, image_file)
@@ -1218,7 +1249,7 @@
print 'Platform not fully supported.'
raise UnsupportedException
self.img.create_image(size_in_MB, image_path)
- self.img.make_fs(image_path)
+ self.img.make_fs(image_path, fs_type=fs_type, uuid=uuid, label=label)
return image_path
def create_loopback(self, image_path):