mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-25 07:31:01 +02:00
fix(disk_util): Remove support for --adjust_part
This isn't a feature we've been using as far as I know and if someone needs a custom partition layout it's probably better to just add it to the json file. Removing this avoids some complexity.
This commit is contained in:
parent
cc341f856b
commit
576c8996f4
@ -71,8 +71,6 @@ locate_gpt
|
|||||||
set +e
|
set +e
|
||||||
|
|
||||||
# Now parse the build settings from ${OUTPUT_DIR}/boot.desc
|
# Now parse the build settings from ${OUTPUT_DIR}/boot.desc
|
||||||
DEFINE_string adjust_part "" \
|
|
||||||
"Adjustments to apply to the partition table"
|
|
||||||
DEFINE_string board "${DEFAULT_BOARD}" \
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
||||||
"Board we're building for."
|
"Board we're building for."
|
||||||
DEFINE_string output_dir "/tmp" \
|
DEFINE_string output_dir "/tmp" \
|
||||||
|
@ -13,8 +13,6 @@ SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|||||||
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
|
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
|
||||||
|
|
||||||
# Developer-visible flags.
|
# Developer-visible flags.
|
||||||
DEFINE_string adjust_part "" \
|
|
||||||
"Adjustments to apply to the partition table"
|
|
||||||
DEFINE_string board "${DEFAULT_BOARD}" \
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
||||||
"The board to build an image for."
|
"The board to build an image for."
|
||||||
DEFINE_string boot_args "" \
|
DEFINE_string boot_args "" \
|
||||||
|
@ -215,7 +215,7 @@ create_base_image() {
|
|||||||
emit_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}"
|
emit_gpt_scripts "${BUILD_DIR}/${image_name}" "${BUILD_DIR}"
|
||||||
|
|
||||||
${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \
|
${SCRIPTS_DIR}/bin/cros_make_image_bootable "${BUILD_DIR}" \
|
||||||
${image_name} --adjust_part="${FLAGS_adjust_part}"
|
"${image_name}"
|
||||||
|
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,6 @@
|
|||||||
CGPT_PY="${BUILD_LIBRARY_DIR}/disk_util"
|
CGPT_PY="${BUILD_LIBRARY_DIR}/disk_util"
|
||||||
|
|
||||||
cgpt_py() {
|
cgpt_py() {
|
||||||
if [[ -n "${FLAGS_adjust_part-}" ]]; then
|
|
||||||
set -- --adjust_part "${FLAGS_adjust_part}" "$@"
|
|
||||||
if [[ ! -t 0 ]]; then
|
|
||||||
warn "The --adjust_part flag was passed." \
|
|
||||||
"This option must ONLY be used interactively. If" \
|
|
||||||
"you need to pass a size from another script, you're" \
|
|
||||||
"doing it wrong and should be using a disk layout type."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
"${CGPT_PY}" "$@"
|
"${CGPT_PY}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
@ -125,78 +124,9 @@ def GetPartitionTable(options, config):
|
|||||||
for k, v in partition_t.items():
|
for k, v in partition_t.items():
|
||||||
partition[k] = v
|
partition[k] = v
|
||||||
|
|
||||||
for adjustment_str in options.adjust_part.split():
|
|
||||||
adjustment = adjustment_str.split(':')
|
|
||||||
if len(adjustment) < 2:
|
|
||||||
raise InvalidAdjustment('Adjustment specified was incomplete')
|
|
||||||
|
|
||||||
label = adjustment[0]
|
|
||||||
operator = adjustment[1][0]
|
|
||||||
operand = adjustment[1][1:]
|
|
||||||
ApplyPartitionAdjustment(partitions, metadata, label, operator, operand)
|
|
||||||
|
|
||||||
return partitions
|
return partitions
|
||||||
|
|
||||||
|
|
||||||
def ApplyPartitionAdjustment(partitions, metadata, label, operator, operand):
|
|
||||||
"""Applies an adjustment to a partition specified by label
|
|
||||||
|
|
||||||
Args:
|
|
||||||
partitions: Partition table to modify
|
|
||||||
metadata: Partition table metadata
|
|
||||||
label: The label of the partition to adjust
|
|
||||||
operator: Type of adjustment (+/-/=)
|
|
||||||
operand: How much to adjust by
|
|
||||||
"""
|
|
||||||
|
|
||||||
partition = GetPartitionByLabel(partitions, label)
|
|
||||||
|
|
||||||
operand_digits = re.sub('\D', '', operand)
|
|
||||||
size_factor = block_factor = 1
|
|
||||||
suffix = operand[len(operand_digits):]
|
|
||||||
if suffix:
|
|
||||||
size_factors = { 'B': 0, 'K': 1, 'M': 2, 'G': 3, 'T': 4, }
|
|
||||||
try:
|
|
||||||
size_factor = size_factors[suffix[0].upper()]
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidAdjustment('Unknown size type %s' % suffix)
|
|
||||||
if size_factor == 0 and len(suffix) > 1:
|
|
||||||
raise InvalidAdjustment('Unknown size type %s' % suffix)
|
|
||||||
block_factors = { '': 1024, 'B': 1000, 'IB': 1024, }
|
|
||||||
try:
|
|
||||||
block_factor = block_factors[suffix[1:].upper()]
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidAdjustment('Unknown size type %s' % suffix)
|
|
||||||
|
|
||||||
operand_bytes = int(operand_digits) * pow(block_factor, size_factor)
|
|
||||||
|
|
||||||
if operand_bytes % metadata['block_size'] == 0:
|
|
||||||
operand_blocks = operand_bytes / metadata['block_size']
|
|
||||||
else:
|
|
||||||
raise InvalidAdjustment('Adjustment size not divisible by block size')
|
|
||||||
|
|
||||||
if operator == '+':
|
|
||||||
partition['blocks'] += operand_blocks
|
|
||||||
partition['bytes'] += operand_bytes
|
|
||||||
elif operator == '-':
|
|
||||||
partition['blocks'] -= operand_blocks
|
|
||||||
partition['bytes'] -= operand_bytes
|
|
||||||
elif operator == '=':
|
|
||||||
partition['blocks'] = operand_blocks
|
|
||||||
partition['bytes'] = operand_bytes
|
|
||||||
else:
|
|
||||||
raise ValueError('unknown operator %s' % operator)
|
|
||||||
|
|
||||||
if partition['type'] == 'rootfs':
|
|
||||||
# If we're adjusting a rootFS partition, we assume the full partition size
|
|
||||||
# specified is being used for the filesytem, minus the space reserved for
|
|
||||||
# the hashpad.
|
|
||||||
partition['fs_bytes'] = partition['bytes']
|
|
||||||
partition['fs_blocks'] = partition['fs_bytes'] / metadata['fs_block_size']
|
|
||||||
partition['blocks'] = int(partition['blocks'] * 1.15)
|
|
||||||
partition['bytes'] = partition['blocks'] * metadata['block_size']
|
|
||||||
|
|
||||||
|
|
||||||
def GetPartitionTableFromConfig(options):
|
def GetPartitionTableFromConfig(options):
|
||||||
"""Loads a partition table and returns a given partition table type
|
"""Loads a partition table and returns a given partition table type
|
||||||
|
|
||||||
@ -453,8 +383,6 @@ def main(argv):
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
parser.add_argument('--adjust_part', default='',
|
|
||||||
help='adjust partition sizes')
|
|
||||||
parser.add_argument('--disk_layout_file', default=default_layout_file,
|
parser.add_argument('--disk_layout_file', default=default_layout_file,
|
||||||
help='path to disk layout json file')
|
help='path to disk layout json file')
|
||||||
parser.add_argument('--disk_layout', default=default_layout_type,
|
parser.add_argument('--disk_layout', default=default_layout_type,
|
||||||
|
@ -26,8 +26,6 @@ assert_inside_chroot
|
|||||||
. "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || exit 1
|
. "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || exit 1
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
DEFINE_string adjust_part "" \
|
|
||||||
"Adjustments to apply to the partition table"
|
|
||||||
DEFINE_string board "${DEFAULT_BOARD}" \
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
||||||
"Board for which the image was built"
|
"Board for which the image was built"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user