Merge pull request #192 from wrigri/disk-resize

Disable resize on disks larger than 2TB
This commit is contained in:
Anders Ingemann 2015-01-31 18:26:15 +00:00
commit c2b37c7329
4 changed files with 83 additions and 1 deletions

View file

@ -10,6 +10,7 @@ from bootstrapvz.common.tasks import apt
from bootstrapvz.common.tasks import boot from bootstrapvz.common.tasks import boot
from bootstrapvz.common.tasks import loopback from bootstrapvz.common.tasks import loopback
from bootstrapvz.common.tasks import initd from bootstrapvz.common.tasks import initd
from bootstrapvz.common.tasks import kernel
from bootstrapvz.common.tasks import ssh from bootstrapvz.common.tasks import ssh
from bootstrapvz.common.tasks import volume from bootstrapvz.common.tasks import volume
@ -58,6 +59,10 @@ def resolve_tasks(taskset, manifest):
if manifest.volume['partitions']['type'] != 'none': if manifest.volume['partitions']['type'] != 'none':
taskset.add(initd.AdjustExpandRootScript) taskset.add(initd.AdjustExpandRootScript)
if manifest.volume['partitions']['type'] != 'mbr':
taskset.update([tasks.initd.AddGrowRootDisable,
kernel.UpdateInitramfs])
if 'gcs_destination' in manifest.image: if 'gcs_destination' in manifest.image:
taskset.add(tasks.image.UploadImage) taskset.add(tasks.image.UploadImage)
if 'gce_project' in manifest.image: if 'gce_project' in manifest.image:

View file

@ -0,0 +1,52 @@
# Selectively disable growroot -*- shell-script -*-
set -e
message() { echo "DISABLE-GROWROOT:" "$@" ; }
error_exit() { message "$@"; exit 1; }
. /scripts/functions
# initramfs-tools exports the following variables, used below:
# $ROOT - Generally "/dev/disk/by-uuid/<id>" which is a link to /dev/sda1
# $ROOTFLAGS - Generally empty
# $ROOTFSTYPE - Generally empty
# $rootmnt - Set to "/root"
# Follow link to get real root location
if [ ! -L "${ROOT}" ]; then
real_root=${ROOT}
else
real_root=$(readlink -f "${ROOT}")
fi
# Remove partition number to get disk
disk=$(echo ${real_root} | sed 's/[0-9]*$//')
# Determine number of 512-byte sectors in 2TB
two_tb=$((2*(1024**4)))
max_sectors=$((${two_tb}/512))
# Determine number of sectors on disk
geometry=$(sfdisk ${disk} --show-pt-geometry)
cyl=$(echo $geometry | cut -d " " -f 2)
heads=$(echo $geometry | cut -d " " -f 4)
secs=$(echo $geometry | cut -d " " -f 6)
sectors=$((${cyl}*${heads}*${secs}))
# If disk is >2TB, disable growroot
if [ "$sectors" -gt "$max_sectors" ]; then
message "Disk size >2TB - Not expanding root partition"
# Temporarily mount filesystem
if [ -z "${ROOTFSTYPE}" ]; then
fstype=$(get_fstype "${ROOT}")
else
fstype=${ROOTFSTYPE}
fi
mount -w ${fstype:+-t ${fstype} }${ROOTFLAGS} ${ROOT} ${rootmnt} ||
error_exit "failed to mount ${ROOT}."
# Disable growroot
touch "${rootmnt}/etc/growroot-disabled"
# Unmount filesystem
umount "${rootmnt}" || error_exit "failed to umount ${rootmnt}";
fi

View file

@ -0,0 +1,3 @@
import os.path
assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))

View file

@ -1,6 +1,9 @@
from bootstrapvz.base import Task from bootstrapvz.base import Task
from bootstrapvz.common import phases from bootstrapvz.common import phases
from bootstrapvz.common.tasks import initd from bootstrapvz.common.tasks import initd
from bootstrapvz.common.tasks import kernel
from . import assets
import os.path
class AdjustExpandRootDev(Task): class AdjustExpandRootDev(Task):
@ -10,7 +13,26 @@ class AdjustExpandRootDev(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
import os.path
from bootstrapvz.common.tools import sed_i from bootstrapvz.common.tools import sed_i
script = os.path.join(info.root, 'etc/init.d/expand-root') script = os.path.join(info.root, 'etc/init.d/expand-root')
sed_i(script, '/dev/xvda', '/dev/sda') sed_i(script, '/dev/xvda', '/dev/sda')
class AddGrowRootDisable(Task):
description = 'Add script to selectively disable growroot'
phase = phases.system_modification
successors = [kernel.UpdateInitramfs]
@classmethod
def run(cls, info):
import stat
rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
stat.S_IRGRP | stat.S_IXGRP |
stat.S_IROTH | stat.S_IXOTH)
from shutil import copy
script_src = os.path.join(assets,
'initramfs-tools/scripts/local-premount/gce-disable-growroot')
script_dst = os.path.join(info.root,
'etc/initramfs-tools/scripts/local-premount/gce-disable-growroot')
copy(script_src, script_dst)
os.chmod(script_dst, rwxr_xr_x)