Skip to content

Commit

Permalink
base: resize-helper: add support for luks based rootfs
Browse files Browse the repository at this point in the history
LUKS2-based devices requires an additional resize (cryptsetup resize)
before performing the actual file system resize with resize2fs.

Signed-off-by: Ricardo Salveti <[email protected]>
  • Loading branch information
ricardosalveti committed Aug 2, 2022
1 parent 3228437 commit 6e6b7af
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ RESIZE2FS=$(which resize2fs) || { echo "E: You must have resize2fs" && exit 1; }

# find root device
ROOT_DEVICE=$(findmnt --noheadings --output=SOURCE / | cut -d'[' -f1)
# identify a possible mapper-based device (e.g. luks)
if echo ${ROOT_DEVICE} | grep -q "^/dev/mapper/"; then
DM_NAME=`basename ${ROOT_DEVICE}`
fi
# prune root device (for example UUID)
ROOT_DEVICE=$(realpath ${ROOT_DEVICE})
# check if root device is available via device-mapper / luks
if basename ${ROOT_DEVICE} | grep -q "^dm-"; then
ROOT_DEVICE="/dev/`dmsetup deps -o devname ${ROOT_DEVICE} | cut -d'(' -f2 | cut -d')' -f1`"
fi
# get the partition number and type
INFO=$(udevadm info --query=property --name=${ROOT_DEVICE})
PART_ENTRY_NUMBER=$(echo "${INFO}" | grep '^ID_PART_ENTRY_NUMBER=' | cut -d'=' -f2)
Expand Down Expand Up @@ -78,4 +86,11 @@ if [ -n "${PART_ENTRY_NAME}" ]; then
fi

${PARTX} -u ${DEVICE}
${RESIZE2FS} "${ROOT_DEVICE}"
if [ -n "${DM_NAME}" ] && cryptsetup isLuks ${ROOT_DEVICE}; then
# OP-TEE: use TEE Identity for pkcs11 authentication
export CKTEEC_LOGIN_TYPE=user
cryptsetup resize --token-only ${DM_NAME}
${RESIZE2FS} "/dev/mapper/${DM_NAME}"
else
${RESIZE2FS} "${ROOT_DEVICE}"
fi

0 comments on commit 6e6b7af

Please sign in to comment.