summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/image_signing/common_minimal.sh20
-rwxr-xr-xscripts/image_signing/make_dev_ssd.sh9
2 files changed, 22 insertions, 7 deletions
diff --git a/scripts/image_signing/common_minimal.sh b/scripts/image_signing/common_minimal.sh
index c57fc90d..8166d698 100644
--- a/scripts/image_signing/common_minimal.sh
+++ b/scripts/image_signing/common_minimal.sh
@@ -137,6 +137,20 @@ make_partition_dev() {
fi
}
+# Find the block size of a device in bytes
+# Args: DEVICE (e.g. /dev/sda)
+# Return: block size in bytes
+blocksize() {
+ local output=''
+ local path="$1"
+ if [ -b "${path}" ]; then
+ local dev="${path##*/}"
+ local sys="/sys/block/${dev}/queue/logical_block_size"
+ output="$(cat "${sys}" 2>/dev/null)"
+ fi
+ echo "${output:-512}"
+}
+
# Read GPT table to find the starting location of a specific partition.
# Args: DEVICE PARTNUM
# Returns: offset (in sectors) of partition PARTNUM
@@ -186,7 +200,8 @@ _mount_image_partition_retry() {
local partnum=$2
local mount_dir=$3
local ro=$4
- local offset=$(( $(partoffset "${image}" "${partnum}") * 512 ))
+ local bs="$(blocksize "${image}")"
+ local offset=$(( $(partoffset "${image}" "${partnum}") * bs ))
local out try
set -- sudo LC_ALL=C mount -o loop,offset=${offset},${ro} \
@@ -225,7 +240,8 @@ _mount_image_partition() {
local partnum=$2
local mount_dir=$3
local ro=$4
- local offset=$(( $(partoffset "${image}" "${partnum}") * 512 ))
+ local bs="$(blocksize "${image}")"
+ local offset=$(( $(partoffset "${image}" "${partnum}") * bs ))
if [ "$ro" != "ro" ]; then
# Forcibly call enable_rw_mount. It should fail on unsupported
diff --git a/scripts/image_signing/make_dev_ssd.sh b/scripts/image_signing/make_dev_ssd.sh
index b08ca48c..5871a190 100755
--- a/scripts/image_signing/make_dev_ssd.sh
+++ b/scripts/image_signing/make_dev_ssd.sh
@@ -144,13 +144,12 @@ find_valid_kernel_partitions() {
# Resigns a kernel on SSD or image.
resign_ssd_kernel() {
- # bs=512 is the fixed block size for dd and cgpt
- local bs=512
local ssd_device="$1"
+ local bs="$(blocksize "${ssd_device}")"
# reasonable size for current kernel partition
- local min_kernel_size=16000
- local max_kernel_size=65536
+ local min_kernel_size=$((8000 * 1024 / bs))
+ local max_kernel_size=$((32768 * 1024 / bs))
local resigned_kernels=0
for kernel_index in $FLAGS_partitions; do
@@ -302,7 +301,7 @@ resign_ssd_kernel() {
# (3) change kernel config to rw
if [ ${FLAGS_remove_rootfs_verification} = $FLAGS_TRUE ]; then
local root_offset_sector=$(partoffset "$ssd_device" $rootfs_index)
- local root_offset_bytes=$((root_offset_sector * 512))
+ local root_offset_bytes=$((root_offset_sector * bs))
if ! is_ext2 "$ssd_device" "$root_offset_bytes"; then
debug_msg "Non-ext2 partition: $ssd_device$rootfs_index, skip."
elif ! rw_mount_disabled "$ssd_device" "$root_offset_bytes"; then