Skip to content

Commit 947a609

Browse files
committed
merge trunk at 0.6.3~bzr551
2 parents f44c0ca + ebb0642 commit 947a609

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- add option 'apt_pipelining' to address issue with S3 mirrors
3838
(LP: #948461) [Ben Howard]
3939
- warn on non-multipart, non-handled user-data [Martin Packman]
40+
- run resizefs in the background in order to not block boot (LP: #961226)
4041
0.6.2:
4142
- fix bug where update was not done unless update was explicitly set.
4243
It would not be run if 'upgrade' or packages were set to be installed

cloudinit/CloudConfig/cc_resizefs.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import subprocess
2323
import os
2424
import stat
25+
import sys
26+
import time
2527
import tempfile
2628
from cloudinit.CloudConfig import per_always
2729

@@ -34,15 +36,14 @@ def handle(_name, cfg, _cloud, log, args):
3436
if str(args[0]).lower() in ['true', '1', 'on', 'yes']:
3537
resize_root = True
3638
else:
37-
resize_root = util.get_cfg_option_bool(cfg, "resize_rootfs", True)
39+
resize_root = util.get_cfg_option_str(cfg, "resize_rootfs", True)
3840

39-
if not resize_root:
41+
if str(resize_root).lower() in ['false', '0']:
4042
return
4143

42-
# this really only uses the filename from mktemp, then we mknod into it
43-
(fd, devpth) = tempfile.mkstemp()
44-
os.unlink(devpth)
45-
os.close(fd)
44+
# we use mktemp rather than mkstemp because early in boot nothing
45+
# else should be able to race us for this, and we need to mknod.
46+
devpth = tempfile.mktemp(prefix="cloudinit.resizefs.", dir="/run")
4647

4748
try:
4849
st_dev = os.stat("/").st_dev
@@ -65,9 +66,6 @@ def handle(_name, cfg, _cloud, log, args):
6566
os.unlink(devpth)
6667
raise
6768

68-
log.debug("resizing root filesystem (type=%s, maj=%i, min=%i)" %
69-
(str(fstype).rstrip("\n"), os.major(st_dev), os.minor(st_dev)))
70-
7169
if str(fstype).startswith("ext"):
7270
resize_cmd = ['resize2fs', devpth]
7371
elif fstype == "xfs":
@@ -77,7 +75,28 @@ def handle(_name, cfg, _cloud, log, args):
7775
log.debug("not resizing unknown filesystem %s" % fstype)
7876
return
7977

78+
if resize_root == "noblock":
79+
fid = os.fork()
80+
if fid == 0:
81+
try:
82+
do_resize(resize_cmd, devpth, log)
83+
os._exit(0) # pylint: disable=W0212
84+
except Exception as exc:
85+
sys.stderr.write("Failed: %s" % exc)
86+
os._exit(1) # pylint: disable=W0212
87+
else:
88+
do_resize(resize_cmd, devpth, log)
89+
90+
log.debug("resizing root filesystem (type=%s, maj=%i, min=%i, val=%s)" %
91+
(str(fstype).rstrip("\n"), os.major(st_dev), os.minor(st_dev),
92+
resize_root))
93+
94+
return
95+
96+
97+
def do_resize(resize_cmd, devpth, log):
8098
try:
99+
start = time.time()
81100
util.subp(resize_cmd)
82101
except subprocess.CalledProcessError as e:
83102
log.warn("Failed to resize filesystem (%s)" % resize_cmd)
@@ -86,4 +105,4 @@ def handle(_name, cfg, _cloud, log, args):
86105
raise
87106

88107
os.unlink(devpth)
89-
return
108+
log.debug("resize took %s seconds" % (time.time() - start))

doc/examples/cloud-config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ rsyslog:
351351
# this allows you to launch an instance with a larger disk / partition
352352
# and have the instance automatically grow / to accomoddate it
353353
# set to 'False' to disable
354+
# by default, the resizefs is done early in boot, and blocks
355+
# if resize_rootfs is set to 'noblock', then it will be run in parallel
354356
resize_rootfs: True
355357

356358
## hostname and /etc/hosts management

0 commit comments

Comments
 (0)