diff options
Diffstat (limited to 'recipes-core')
| -rw-r--r-- | recipes-core/images/dm-verity-image-initramfs.bb | 26 | ||||
| -rw-r--r-- | recipes-core/initrdscripts/initramfs-dm-verity.bb | 13 | ||||
| -rw-r--r-- | recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh | 46 |
3 files changed, 85 insertions, 0 deletions
diff --git a/recipes-core/images/dm-verity-image-initramfs.bb b/recipes-core/images/dm-verity-image-initramfs.bb new file mode 100644 index 0000000..f9ea376 --- /dev/null +++ b/recipes-core/images/dm-verity-image-initramfs.bb | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | DESCRIPTION = "Simple initramfs image for mounting the rootfs over the verity device mapper." | ||
| 2 | |||
| 3 | # We want a clean, minimal image. | ||
| 4 | IMAGE_FEATURES = "" | ||
| 5 | |||
| 6 | PACKAGE_INSTALL = " \ | ||
| 7 | initramfs-dm-verity \ | ||
| 8 | base-files \ | ||
| 9 | busybox \ | ||
| 10 | util-linux-mount \ | ||
| 11 | udev \ | ||
| 12 | cryptsetup \ | ||
| 13 | lvm2-udevrules \ | ||
| 14 | " | ||
| 15 | |||
| 16 | # Can we somehow inspect reverse dependencies to avoid these variables? | ||
| 17 | do_rootfs[depends] += "${DM_VERITY_IMAGE}:do_image_${DM_VERITY_IMAGE_TYPE}" | ||
| 18 | |||
| 19 | IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" | ||
| 20 | |||
| 21 | inherit core-image | ||
| 22 | |||
| 23 | deploy_verity_hash() { | ||
| 24 | install -D -m 0644 ${DEPLOY_DIR_IMAGE}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.verity.env ${IMAGE_ROOTFS}/${datadir}/dm-verity.env | ||
| 25 | } | ||
| 26 | ROOTFS_POSTPROCESS_COMMAND += "deploy_verity_hash;" | ||
diff --git a/recipes-core/initrdscripts/initramfs-dm-verity.bb b/recipes-core/initrdscripts/initramfs-dm-verity.bb new file mode 100644 index 0000000..b614956 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-dm-verity.bb | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | SUMMARY = "Simple init script that uses devmapper to mount the rootfs in read-only mode protected by dm-verity" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | |||
| 5 | SRC_URI = "file://init-dm-verity.sh" | ||
| 6 | |||
| 7 | do_install() { | ||
| 8 | install -m 0755 ${WORKDIR}/init-dm-verity.sh ${D}/init | ||
| 9 | install -d ${D}/dev | ||
| 10 | mknod -m 622 ${D}/dev/console c 5 1 | ||
| 11 | } | ||
| 12 | |||
| 13 | FILES_${PN} = "/init /dev/console" | ||
diff --git a/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh b/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh new file mode 100644 index 0000000..307d2c7 --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-dm-verity/init-dm-verity.sh | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
| 4 | RDEV="" | ||
| 5 | ROOT_DIR="/new_root" | ||
| 6 | |||
| 7 | mkdir -p /proc | ||
| 8 | mkdir -p /sys | ||
| 9 | mkdir -p /run | ||
| 10 | mkdir -p /tmp | ||
| 11 | mount -t proc proc /proc | ||
| 12 | mount -t sysfs sysfs /sys | ||
| 13 | mount -t devtmpfs none /dev | ||
| 14 | |||
| 15 | udevd --daemon | ||
| 16 | udevadm trigger --type=subsystems --action=add | ||
| 17 | udevadm trigger --type=devices --action=add | ||
| 18 | udevadm settle --timeout=10 | ||
| 19 | |||
| 20 | for PARAM in $(cat /proc/cmdline); do | ||
| 21 | case $PARAM in | ||
| 22 | root=*) | ||
| 23 | RDEV=${PARAM#root=} | ||
| 24 | ;; | ||
| 25 | esac | ||
| 26 | done | ||
| 27 | |||
| 28 | if ! [ -b $RDEV ]; then | ||
| 29 | echo "Missing root command line argument!" | ||
| 30 | exit 1 | ||
| 31 | fi | ||
| 32 | |||
| 33 | case $RDEV in | ||
| 34 | UUID=*) | ||
| 35 | RDEV=$(realpath /dev/disk/by-uuid/${RDEV#UUID=}) | ||
| 36 | ;; | ||
| 37 | esac | ||
| 38 | |||
| 39 | . /usr/share/dm-verity.env | ||
| 40 | |||
| 41 | echo "Mounting $RDEV over dm-verity as the root filesystem" | ||
| 42 | |||
| 43 | veritysetup --data-block-size=1024 --hash-offset=$DATA_SIZE create rootfs $RDEV $RDEV $ROOT_HASH | ||
| 44 | mkdir -p $ROOT_DIR | ||
| 45 | mount -o ro /dev/mapper/rootfs $ROOT_DIR | ||
| 46 | exec switch_root $ROOT_DIR /sbin/init | ||
