| 1 |
#!/bin/sh |
| 2 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 3 |
# Copyright (C) 2023 Canonical Ltd |
| 4 |
# Author: Isaac True <[email protected]> |
| 5 |
# |
| 6 |
# This file is part of kiwi. |
| 7 |
# |
| 8 |
# kiwi is free software: you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation, either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# kiwi is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with kiwi. If not, see <http://www.gnu.org/licenses/> |
| 20 |
# |
| 21 |
# shellcheck disable=SC1091 |
| 22 |
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh |
| 23 |
|
| 24 |
if ! getarg "verityroot="; then |
| 25 |
return |
| 26 |
fi |
| 27 |
|
| 28 |
VERITY_ROOT=$(getarg "verityroot=") |
| 29 |
|
| 30 |
if [ ! -e "${VERITY_ROOT}" ]; then |
| 31 |
# Source device does not exist (yet?) |
| 32 |
exit 1 |
| 33 |
fi |
| 34 |
|
| 35 |
if [ -e "/dev/mapper/verityRoot" ]; then |
| 36 |
# Mapping already exists - we don't need to do it again |
| 37 |
exit 0 |
| 38 |
fi |
| 39 |
|
| 40 |
ROOT_HASH=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o root-hash) |
| 41 |
ALGORITHM=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o algorithm) |
| 42 |
HASH_TYPE=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o hash-type) |
| 43 |
HASH_BLOCK_SIZE=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o hash-blocksize) |
| 44 |
DATA_BLOCK_SIZE=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o data-blocksize) |
| 45 |
SALT=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o salt) |
| 46 |
DATA_BLOCKS=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o data-blocks) |
| 47 |
HASH_START_BLOCK=$(kiwi-parse-verity -p "${VERITY_ROOT}" -o hash-start-block) |
| 48 |
HASH_OFFSET=$(( "${HASH_START_BLOCK}" * "${HASH_BLOCK_SIZE}" )) |
| 49 |
|
| 50 |
veritysetup open "${VERITY_ROOT}" verityRoot "${VERITY_ROOT}" "${ROOT_HASH}" \ |
| 51 |
--no-superblock --hash "${ALGORITHM}" --format "${HASH_TYPE}" \ |
| 52 |
--hash-block-size "${HASH_BLOCK_SIZE}" --data-block-size "${DATA_BLOCK_SIZE}" \ |
| 53 |
--salt "${SALT}" --data-blocks "${DATA_BLOCKS}" --hash-offset "${HASH_OFFSET}" |