mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Disable resize on disks larger than 2TB
Change-Id: I9764fe2a06cf47e8c0daf38df41c288c280bd6f7
This commit is contained in:
parent
255f0624b4
commit
0d494fb49e
4 changed files with 83 additions and 1 deletions
|
@ -9,6 +9,7 @@ import tasks.packages
|
||||||
from bootstrapvz.common.tasks import apt
|
from bootstrapvz.common.tasks import apt
|
||||||
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
|
||||||
|
|
||||||
|
@ -55,6 +56,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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
assets = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets'))
|
|
@ -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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue