diff options
author | Chad Smith <chad.smith@canonical.com> | 2017-10-23 14:34:23 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2017-10-23 14:34:23 -0600 |
commit | 17a15f9e0ae78e4fc4e24fab0caebdf78f06ef66 (patch) | |
tree | af6338a254acdafe9a89b59e9666e60b01e2d0b7 /cloudinit/config/cc_resizefs.py | |
parent | 5b6fd3ae353dd65e57ab138d7dca640d1c88d32c (diff) | |
download | vyos-cloud-init-17a15f9e0ae78e4fc4e24fab0caebdf78f06ef66.tar.gz vyos-cloud-init-17a15f9e0ae78e4fc4e24fab0caebdf78f06ef66.zip |
resizefs: Fix regression when system booted with root=PARTUUID=
A recent cleanup of the resizefs module broke resizing when a system was
booted with root=PARTUUID=<uuid> and the device /dev/root does not exist.
This path is exposed with the Ubuntu 16.04 but not with Ubuntu 17.10. A
recreate exists under bug 1684869.
LP: #1725067
Diffstat (limited to 'cloudinit/config/cc_resizefs.py')
-rw-r--r-- | cloudinit/config/cc_resizefs.py | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py index f774baa3..0d282e63 100644 --- a/cloudinit/config/cc_resizefs.py +++ b/cloudinit/config/cc_resizefs.py @@ -145,25 +145,6 @@ RESIZE_FS_PRECHECK_CMDS = { } -def rootdev_from_cmdline(cmdline): - found = None - for tok in cmdline.split(): - if tok.startswith("root="): - found = tok[5:] - break - if found is None: - return None - - if found.startswith("/dev/"): - return found - if found.startswith("LABEL="): - return "/dev/disk/by-label/" + found[len("LABEL="):] - if found.startswith("UUID="): - return "/dev/disk/by-uuid/" + found[len("UUID="):] - - return "/dev/" + found - - def can_skip_resize(fs_type, resize_what, devpth): fstype_lc = fs_type.lower() for i, func in RESIZE_FS_PRECHECK_CMDS.items(): @@ -172,14 +153,15 @@ def can_skip_resize(fs_type, resize_what, devpth): return False -def is_device_path_writable_block(devpath, info, log): - """Return True if devpath is a writable block device. +def maybe_get_writable_device_path(devpath, info, log): + """Return updated devpath if the devpath is a writable block device. - @param devpath: Path to the root device we want to resize. + @param devpath: Requested path to the root device we want to resize. @param info: String representing information about the requested device. @param log: Logger to which logs will be added upon error. - @returns Boolean True if block device is writable + @returns devpath or updated devpath per kernel commandline if the device + path is a writable block device, returns None otherwise. """ container = util.is_container() @@ -189,12 +171,12 @@ def is_device_path_writable_block(devpath, info, log): devpath = util.rootdev_from_cmdline(util.get_cmdline()) if devpath is None: log.warn("Unable to find device '/dev/root'") - return False + return None log.debug("Converted /dev/root to '%s' per kernel cmdline", devpath) if devpath == 'overlayroot': log.debug("Not attempting to resize devpath '%s': %s", devpath, info) - return False + return None try: statret = os.stat(devpath) @@ -207,7 +189,7 @@ def is_device_path_writable_block(devpath, info, log): devpath, info) else: raise exc - return False + return None if not stat.S_ISBLK(statret.st_mode) and not stat.S_ISCHR(statret.st_mode): if container: @@ -216,8 +198,8 @@ def is_device_path_writable_block(devpath, info, log): else: log.warn("device '%s' not a block device. cannot resize: %s" % (devpath, info)) - return False - return True + return None + return devpath # The writable block devpath def handle(name, cfg, _cloud, log, args): @@ -242,8 +224,9 @@ def handle(name, cfg, _cloud, log, args): info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what) log.debug("resize_info: %s" % info) - if not is_device_path_writable_block(devpth, info, log): - return + devpth = maybe_get_writable_device_path(devpth, info, log) + if not devpth: + return # devpath was not a writable block device resizer = None if can_skip_resize(fs_type, resize_what, devpth): |