From b2c3effa9e233ead382cabf46c371d6485b94b15 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 21 Mar 2011 21:35:54 -0400 Subject: fix bug with resizefs module instead of using blkid on /dev/root, create a device node ourselves with the correct device number of '/', then use blkid and resize2fs on that. I believe the problem was that /dev/root was occasionally not being present due to race. LP: #726938 --- ChangeLog | 2 ++ cloudinit/CloudConfig/cc_resizefs.py | 35 +++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61cb6e70..aac22ff4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ It would not be run if 'upgrade' or packages were set to be installed - fix bug in part-handler code, that prevented working part-handlers (LP: #739694) + - fix bug in resizefs cloud-config that would cause trace based on + failure of 'blkid /dev/root' (LP: #726938) 0.6.1: - fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509) - improve comment strings in rsyslog file tools/21-cloudinit.conf diff --git a/cloudinit/CloudConfig/cc_resizefs.py b/cloudinit/CloudConfig/cc_resizefs.py index ebb95227..e396b283 100644 --- a/cloudinit/CloudConfig/cc_resizefs.py +++ b/cloudinit/CloudConfig/cc_resizefs.py @@ -18,6 +18,9 @@ import cloudinit.util as util import subprocess import traceback +import os +import stat +import tempfile def handle(name,cfg,cloud,log,args): if len(args) != 0: @@ -29,21 +32,38 @@ def handle(name,cfg,cloud,log,args): if not resize_root: return - log.debug("resizing root filesystem on first boot") + # this really only uses the filename from mktemp, then we mknod into it + (fd, devpth) = tempfile.mkstemp() + os.unlink(devpth) + os.close(fd) + + try: + st_dev=os.stat("/").st_dev + dev=os.makedev(os.major(st_dev),os.minor(st_dev)) + os.mknod(devpth, 0400 | stat.S_IFBLK, dev) + except: + log.warn("Failed to make device node to resize /") + raise - cmd = ['blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', '/dev/root'] + cmd = [ 'blkid', '-c', '/dev/null', '-sTYPE', '-ovalue', devpth ] try: (fstype,err) = util.subp(cmd) except subprocess.CalledProcessError as e: - log.warn("Failed to get filesystem type via %s" % cmd) + log.warn("Failed to get filesystem type of maj=%s, min=%s via: %s" % + (os.major(st_dev), os.minor(st_dev), cmd)) log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1]) + os.unlink(devpth) raise + log.debug("resizing root filesystem (type=%s, maj=%i, min=%i)" % + (fstype.rstrip("\n"), os.major(st_dev), os.minor(st_dev))) + if fstype.startswith("ext"): - resize_cmd = [ 'resize2fs', '/dev/root' ] + resize_cmd = [ 'resize2fs', devpth ] elif fstype == "xfs": - resize_cmd = [ 'xfs_growfs', '/dev/root' ] + resize_cmd = [ 'xfs_growfs', devpth ] else: + os.unlink(devpth) log.debug("not resizing unknown filesystem %s" % fstype) return @@ -52,5 +72,8 @@ def handle(name,cfg,cloud,log,args): except subprocess.CalledProcessError as e: log.warn("Failed to resize filesystem (%s)" % resize_cmd) log.warn("output=%s\nerror=%s\n", e.output[0], e.output[1]) + os.unlink(devpth) raise - + + os.unlink(devpth) + return -- cgit v1.2.3