diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-03-21 21:35:54 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-03-21 21:35:54 -0400 |
commit | b2c3effa9e233ead382cabf46c371d6485b94b15 (patch) | |
tree | dd0f7a17dbd339016aedc7c79dab932862968e28 /cloudinit | |
parent | 46631c678531500ff5685644874a1ae56ac90055 (diff) | |
download | vyos-cloud-init-b2c3effa9e233ead382cabf46c371d6485b94b15.tar.gz vyos-cloud-init-b2c3effa9e233ead382cabf46c371d6485b94b15.zip |
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
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/CloudConfig/cc_resizefs.py | 35 |
1 files changed, 29 insertions, 6 deletions
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 |