Skip to content

make-disk-image: pre/post-format-files copies content of source path #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sedlund
Copy link
Contributor

@sedlund sedlund commented Jun 24, 2025

Problem

diskoImagesScripts --pre-format-files destination does not work when its only one level deep


when using diskoImagesScript --pre-format-files using a destination of one path deep

nix build .#checks.x86_64-linux.make-disk-image-luks-interactive-impure (diskoImagesScript)

./result --pre-format-files $PWD/pre /tmp
----------8<-------8<-------------
++ for src in /tmp/xchg/copy_before_disko/*
++ '[' -e /tmp/xchg/copy_before_disko/L3RtcAo= ']'
+++ basename /tmp/xchg/copy_before_disko/L3RtcAo=
+++ base64 -d
++ dst=/tmp
+++ dirname /tmp
++ mkdir -p /
++ cp -rv /tmp/xchg/copy_before_disko/L3RtcAo= /tmp
'/tmp/xchg/copy_before_disko/L3RtcAo=' -> '/tmp/L3RtcAo='
'/tmp/xchg/copy_before_disko/L3RtcAo=/secret.key' -> '/tmp/L3RtcAo=/secret.key'
----------8<-------8<-------------
+ passwordFile=/tmp/secret.key
----------8<-------8<-------------
+ cryptsetup -q luksFormat /dev/disk/by-partlabel/disk-main-luks --key-file /dev/fd/63
cat: /tmp/secret.key: No such file or directory
Nothing to read on input.
+ rm -rf /tmp/tmp.vQKPk8IlAw
[    9.533714] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100
----------8<-------8<-------------

Two levels deep looks like this

./result --pre-format-files $PWD/pre /tmp/pre
----------8<-------8<-------------
++ for src in /tmp/xchg/copy_before_disko/*
++ '[' -e /tmp/xchg/copy_before_disko/L3RtcC9wcmUK ']'
+++ basename /tmp/xchg/copy_before_disko/L3RtcC9wcmUK
+++ base64 -d
++ dst=/tmp/pre
+++ dirname /tmp/pre
++ mkdir -p /tmp
++ cp -rv /tmp/xchg/copy_before_disko/L3RtcC9wcmUK /tmp/pre
'/tmp/xchg/copy_before_disko/L3RtcC9wcmUK' -> '/tmp/pre'
'/tmp/xchg/copy_before_disko/L3RtcC9wcmUK/secret.key' -> '/tmp/pre/secret.key'

Solution

cp content of src, remove dirname from mkdir to make the full destination path

./result --pre-format-files $PWD/pre /tmp
----------8<-------8<-------------
++ for src in /tmp/xchg/copy_before_disko/*
++ '[' -e /tmp/xchg/copy_before_disko/L3RtcAo= ']'
+++ basename /tmp/xchg/copy_before_disko/L3RtcAo=
+++ base64 -d
++ dst=/tmp
++ mkdir -p /tmp
++ cp -rv /tmp/xchg/copy_before_disko/L3RtcAo=/. /tmp
'/tmp/xchg/copy_before_disko/L3RtcAo=/./secret.key' -> '/tmp/./secret.key'
----------8<-------8<-------------
installation finished!
++ umount -Rv /mnt
umount: /mnt/boot unmounted
umount: /mnt unmounted
[   68.424421] reboot: Power down

done
set -f
${partitioner}
set +f
for src in /tmp/xchg/copy_after_disko/*; do
[ -e "$src" ] || continue
dst=/mnt/$(basename "$src" | base64 -d)
mkdir -p "$(dirname "$dst")"
cp -r "$src" "$dst"
mkdir -p "$dst"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this break if we someone used files instead of directories before? Was this supported even?

Copy link
Contributor Author

@sedlund sedlund Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a single file with original I get this:

./result --pre-format-files pre/secret.key /tmp
cp: cannot stat 'pre/secret.key': No such file or directory

ll pre/secret.key
.rw-r--r-- 12 sedlund 1 week  pre/secret.key

@sedlund sedlund force-pushed the make-disk-image-files branch from bcb3f2a to d00e5ee Compare July 4, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants