Skip to content

Commit

Permalink
replace dd with mv_data to reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nkraetzschmar committed Jun 15, 2023
1 parent a6e626e commit 7efe47b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
FROM debian:bookworm AS mv_data
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential ca-certificates git
RUN git clone --depth=1 https://github.com/nkraetzschmar/mv_data
RUN make -C mv_data install

FROM debian:bookworm AS aws-kms-pkcs11
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential awscli ca-certificates cmake git libcurl4-openssl-dev libengine-pkcs11-openssl libjson-c-dev libssl-dev libp11-kit-dev libp11-dev zlib1g-dev
RUN git clone --depth=1 --recurse-submodules -b 1.11.25 https://github.com/aws/aws-sdk-cpp
Expand All @@ -9,6 +14,7 @@ RUN cp "/usr/lib/$(uname -m)-linux-gnu/pkcs11/aws_kms_pkcs11.so" /aws_kms_pkcs11
FROM debian:bookworm
COPY pkg.list /pkg.list
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends $(cat /pkg.list) && rm /pkg.list
COPY --from=mv_data /usr/bin/mv_data /usr/bin/mv_data
COPY --from=aws-kms-pkcs11 /aws_kms_pkcs11.so /aws_kms_pkcs11.so
RUN mv /aws_kms_pkcs11.so "/usr/lib/$(uname -m)-linux-gnu/pkcs11/aws_kms_pkcs11.so"
COPY builder /builder
Expand Down
5 changes: 4 additions & 1 deletion builder/image.d/makedisk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ while IFS=$'\t' read -r part_uuid type size syslinux file label; do
gpt_entry=$(grep -iF "uuid=$part_uuid" <<< "$gpt_dump")
start_sector=$(grep -oP '(?<=start=) *[0-9]+' <<< "$gpt_entry" | tr -d '[:blank:]')
num_sectors=$(grep -oP '(?<=size=) *[0-9]+' <<< "$gpt_entry" | tr -d '[:blank:]')
dd if="$file" of="$img" bs="$sector_size" seek="$start_sector" count="$num_sectors" conv=notrunc

offset=$(( sector_size * start_sector ))
len=$(( sector_size * num_sectors ))
mv_data --input "$file" --output "$img" --output-offset "$offset" --length "$len"
rm "$file"
done <<< "$second_pass"
2 changes: 1 addition & 1 deletion setup_namespace
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eufo pipefail

if [ "${1-}" = --second-stage ]; then
shift
mount -t tmpfs -o size=8G tmpfs /tmp
mount -t tmpfs -o size=4G tmpfs /tmp
"$@"
else
unshare --map-root-user --map-users auto --map-groups auto --mount "$0" --second-stage "$@"
Expand Down

0 comments on commit 7efe47b

Please # to comment.