|
|
@ -48,9 +48,8 @@ disk_get_part_value() { |
|
|
|
# |
|
|
|
# $1 - path to disk image |
|
|
|
disk_get_part_nums() { |
|
|
|
partx --show $1 | tail -n +2 | |
|
|
|
while read line |
|
|
|
do |
|
|
|
partx --show $1 | tail -n +2 \ |
|
|
|
| while read line; do |
|
|
|
echo $line | awk '{printf "%d\n", $1}' |
|
|
|
done |
|
|
|
} |
|
|
@ -69,14 +68,14 @@ disk_extract_part() { |
|
|
|
# |
|
|
|
# $1 - MiB value |
|
|
|
disk_mb_to_sectors() { |
|
|
|
echo "$(( (${1} * 1024 * 1024) / 512 ))" |
|
|
|
echo "$(((${1} * 1024 * 1024) / 512))" |
|
|
|
} |
|
|
|
|
|
|
|
# Convert 512 sectors to MiB |
|
|
|
# |
|
|
|
# $1 - number of 512 sectors |
|
|
|
disk_sectors_to_mb() { |
|
|
|
echo "$(( (${1} * 512) / 1024 / 1024 ))" |
|
|
|
echo "$(((${1} * 512) / 1024 / 1024))" |
|
|
|
} |
|
|
|
|
|
|
|
# Align value (result is number of 512 sectors) |
|
|
@ -84,14 +83,14 @@ disk_sectors_to_mb() { |
|
|
|
# $1 - value to align (number of 512 sectors) |
|
|
|
# $2 - alignment in bytes |
|
|
|
disk_align_sectors() { |
|
|
|
local size_in_bytes=$(( ${1} * 512)) |
|
|
|
local reminder=$(( ${size_in_bytes} % ${2} )) |
|
|
|
local size_in_bytes=$((${1} * 512)) |
|
|
|
local reminder=$((${size_in_bytes} % ${2})) |
|
|
|
|
|
|
|
if [ $reminder -ne 0 ]; then |
|
|
|
size_in_bytes=$(( $size_in_bytes - $reminder + ${2} )) |
|
|
|
size_in_bytes=$(($size_in_bytes - $reminder + ${2})) |
|
|
|
fi |
|
|
|
|
|
|
|
echo "$(( $size_in_bytes / 512 ))" |
|
|
|
echo "$(($size_in_bytes / 512))" |
|
|
|
} |
|
|
|
|
|
|
|
# Write file at offset of another file |
|
|
@ -115,9 +114,9 @@ disk_create_file_system_from_folder() { |
|
|
|
run_and_log_cmd "dd if=/dev/zero of=${2} seek=${3} count=0 bs=512 status=none" |
|
|
|
|
|
|
|
case ${1} in |
|
|
|
*data/ ) EXTRA_OPTS="${MENDER_DATA_PART_MKFS_OPTS}";; |
|
|
|
*rootfs/ ) EXTRA_OPTS="${MENDER_ROOT_PART_MKFS_OPTS}";; |
|
|
|
* ) EXTRA_OPTS="";; |
|
|
|
*data/) EXTRA_OPTS="${MENDER_DATA_PART_MKFS_OPTS}" ;; |
|
|
|
*rootfs/) EXTRA_OPTS="${MENDER_ROOT_PART_MKFS_OPTS}" ;; |
|
|
|
*) EXTRA_OPTS="" ;; |
|
|
|
esac |
|
|
|
|
|
|
|
case "$4" in |
|
|
@ -185,7 +184,6 @@ disk_root_part() { |
|
|
|
echo "${root_part}" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Check if supplied argument is valid partuuid device path. |
|
|
|
# Supports both dos and gpt paths |
|
|
|
# |
|
|
@ -194,7 +192,6 @@ disk_is_valid_partuuid_device() { |
|
|
|
disk_is_valid_partuuid_gpt_device "$1" || disk_is_valid_partuuid_dos_device "$1" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Check if supplied argument is valid gpt partuuid device path. |
|
|
|
# |
|
|
|
# Example: /dev/disk/by-partuuid/26445670-f37c-408b-be2c-3ef419866620 |
|
|
@ -204,7 +201,6 @@ disk_is_valid_partuuid_gpt_device() { |
|
|
|
echo "${1}" | grep -qE '^/dev/disk/by-partuuid/([0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12})$' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Check if supplied argument is valid dos partuuid device path. |
|
|
|
# |
|
|
|
# Example: /dev/disk/by-partuuid/26445670-01 |
|
|
@ -214,7 +210,6 @@ disk_is_valid_partuuid_dos_device() { |
|
|
|
echo "${1}" | grep -qE '^/dev/disk/by-partuuid/[0-9a-f]{8}-[0-9a-f]{2}$' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Get partuuid from supplied device path. |
|
|
|
# Supports both dos and gpt paths |
|
|
|
# |
|
|
@ -226,7 +221,6 @@ disk_get_partuuid_from_device() { |
|
|
|
echo "${1}" | sed "s:/dev/disk/by-partuuid/::" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Get dos disk identifier from supplied device path. |
|
|
|
# |
|
|
|
# $1 - dos compatible partuuid device path |
|
|
@ -238,7 +232,6 @@ disk_get_partuuid_dos_diskid_from_device() { |
|
|
|
echo "$partuuid" | cut -d- -f1 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Get dos partuuid number from supplied device path. |
|
|
|
# |
|
|
|
# $1 - dos compatible partuuid device path |
|
|
@ -283,7 +276,6 @@ disk_root_part_b_device() { |
|
|
|
disk_get_part_device "${MENDER_ROOTFS_PART_B_NUMBER}" "MENDER_ROOTFS_PART_B" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Get device partition number from device path. |
|
|
|
# Unrecognized or unsupported device paths will generate an error |
|
|
|
# |
|
|
@ -291,20 +283,20 @@ disk_root_part_b_device() { |
|
|
|
disk_get_device_part_number() { |
|
|
|
dev_part="unknown" |
|
|
|
case "$1" in |
|
|
|
/dev/nvme*n*p* ) |
|
|
|
/dev/nvme*n*p*) |
|
|
|
dev_part=$(echo $1 | cut -dp -f2) |
|
|
|
;; |
|
|
|
/dev/mmcblk*p* ) |
|
|
|
/dev/mmcblk*p*) |
|
|
|
dev_part=$(echo $1 | cut -dp -f2) |
|
|
|
;; |
|
|
|
/dev/[sh]d[a-z][1-9]* ) |
|
|
|
/dev/[sh]d[a-z][1-9]*) |
|
|
|
dev_part=${1##*d[a-z]} |
|
|
|
;; |
|
|
|
ubi*_* ) |
|
|
|
ubi*_*) |
|
|
|
dev_part=$(echo $1 | cut -d_ -f2) |
|
|
|
;; |
|
|
|
/dev/disk/by-partuuid/* ) |
|
|
|
if disk_is_valid_partuuid_dos_device "$1";then |
|
|
|
/dev/disk/by-partuuid/*) |
|
|
|
if disk_is_valid_partuuid_dos_device "$1"; then |
|
|
|
dev_part=$(disk_get_partuuid_dos_part_number "$1") |
|
|
|
dev_part=$((16#${dev_part})) |
|
|
|
else |
|
|
@ -312,7 +304,7 @@ disk_get_device_part_number() { |
|
|
|
fi |
|
|
|
;; |
|
|
|
esac |
|
|
|
part=$(printf "%d" $dev_part 2>/dev/null) |
|
|
|
part=$(printf "%d" $dev_part 2> /dev/null) |
|
|
|
if [ $? = 1 ]; then |
|
|
|
log_fatal "Could not determine partition number from '${1}'" |
|
|
|
else |
|
|
@ -327,19 +319,19 @@ disk_get_device_part_number() { |
|
|
|
disk_get_device_base() { |
|
|
|
dev_base="" |
|
|
|
case "$1" in |
|
|
|
/dev/nvme*n*p* ) |
|
|
|
/dev/nvme*n*p*) |
|
|
|
dev_base=$(echo $1 | cut -dp -f1) |
|
|
|
;; |
|
|
|
/dev/mmcblk*p* ) |
|
|
|
/dev/mmcblk*p*) |
|
|
|
dev_base=$(echo $1 | cut -dp -f1) |
|
|
|
;; |
|
|
|
/dev/[sh]d[a-z][1-9]* ) |
|
|
|
/dev/[sh]d[a-z][1-9]*) |
|
|
|
dev_base=${1%%[1-9]*} |
|
|
|
;; |
|
|
|
ubi*_* ) |
|
|
|
ubi*_*) |
|
|
|
dev_base=$(echo $1 | cut -d_ -f1) |
|
|
|
;; |
|
|
|
/dev/disk/by-partuuid/* ) |
|
|
|
/dev/disk/by-partuuid/*) |
|
|
|
log_fatal "device base does not exist for GPT partuuid: '$1'" |
|
|
|
;; |
|
|
|
esac |
|
|
@ -350,18 +342,17 @@ disk_get_device_base() { |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Conditionally redefine partition number/device if fine grained variable set. |
|
|
|
# |
|
|
|
# $1 - variable name |
|
|
|
# $2 - variable value |
|
|
|
disk_override_partition_variable() { |
|
|
|
if [ "${MENDER_ENABLE_PARTUUID}" == "y" ]; then |
|
|
|
if disk_is_valid_partuuid_dos_device "${2}";then |
|
|
|
if disk_is_valid_partuuid_dos_device "${2}"; then |
|
|
|
eval "${1}"=$(disk_get_device_part_number "${2}") |
|
|
|
fi |
|
|
|
else |
|
|
|
if [ -n "${2}" ];then |
|
|
|
if [ -n "${2}" ]; then |
|
|
|
eval "${1}"=$(disk_get_device_part_number "${2}") |
|
|
|
MENDER_STORAGE_DEVICE_BASE=$(disk_get_device_base "${2}") |
|
|
|
fi |
|
|
|