Skip to content

Commit

Permalink
add 'resize_rootfs' cloud-config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
smoser committed Jan 20, 2011
1 parent 05230a3 commit a685809
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
syslog writing to it (LP: #704509)
- rework of /var/lib/cloud layout
- remove updates-check (LP: #653220)
- support resizing / on first boot (enabled by default)
54 changes: 54 additions & 0 deletions cloudinit/CloudConfig/cc_resizefs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# vi: ts=4 expandtab
#
# Copyright (C) 2011 Canonical Ltd.
#
# Author: Scott Moser <scott.moser@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cloudinit.util as util
import subprocess
import traceback

def handle(name,cfg,cloud,log,args):
if len(args) != 0:
resize_root = False
if str(value).lower() in [ 'true', '1', 'on', 'yes']:
resize_root = True
else:
resize_root = util.get_cfg_option_bool(cfg,"resize_rootfs",False)

if not resize_root: return

log.debug("resizing root filesystem on first boot")

cmd = ['blkid', '-sTYPE', '-ovalue', '/dev/root']
try:
(fstype,err) = util.subp(cmd)
except Exception, e:
log.warn("Failed to get filesystem type via %s" % cmd)
raise

if fstype.startswith("ext"):
resize_cmd = [ 'resize2fs', '/dev/root' ]
elif fstype == "xfs":
resize_cmd = [ 'xfs_growfs', '/dev/root' ]
else:
log.debug("not resizing unknown filesystem %s" % fstype)
return

try:
(out,err) = util.subp(resize_cmd)
except Exception, e:
log.warn("Failed to resize filesystem (%s,%s)" % cmd)
raise

1 change: 1 addition & 0 deletions config/cloud.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ disable_root: 1
preserve_hostname: False

cloud_config_modules:
- resizefs
- mounts
- rsyslog
- ssh-import-id
Expand Down
6 changes: 6 additions & 0 deletions doc/examples/cloud-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,9 @@ rsyslog:
- filename: 01-examplecom.conf
content: |
*.* @@syslogd.example.com

# resize_rootfs should the / filesytem be resized on first boot
# this allows you to launch an instance with a larger disk / partition
# and have the instance automatically grow / to accomoddate it
# set to 'False' to disable
resize_rootfs: True

0 comments on commit a685809

Please sign in to comment.