systemd icon indicating copy to clipboard operation
systemd copied to clipboard

systemd-repart refuses to copy blocks from unaligned files

Open waldiTM opened this issue 9 months ago • 1 comments

systemd version the issue has been seen with

256~rc1-1~exp2

Used distribution

Debian Sid

Linux kernel version used

No response

CPU architectures issue was seen on

None

Component

systemd-repart

Expected behaviour you didn't see

CopyBlocks copies a file into the resulting image, regardless of alignment. Even if you assume that you have to write whole blocks on block devices, the sector size of the block devices is not fixed at 512 bytes.

Unexpected behaviour you saw

It expects files to be aligned to 512 bytes, which is properly documented. However nowhere seems to exist a technical limitation that warrants this limitation. The copy_bytes_full function that is used seems to be quite capable of copying single bytes. And the size of the partition is also round up to a way greater value.

Steps to reproduce the problem

Try to create a PReP Boot partition from a linked grub file, using:

[Partition]
Type=9E1A2D38-C612-4316-AA26-8B49521E5A8B
CopyBlocks=/boot/grub/grub
SizeMinBytes=6M
SizeMaxBytes=6M

Additional program output to the terminal or log subsystem illustrating the issue

File to copy bytes from '/target/boot/grub/grub' has size that is not multiple of 512, refusing.

waldiTM avatar May 05 '24 06:05 waldiTM

It expects files to be aligned to 512 bytes, which is properly documented. However nowhere seems to exist a technical limitation that warrants this limitation.

Linux block devices have a sector size, which must be an exponent of 2, with 512 as smallest supported sector size.

Typical sector sizes are 512 (old hdds), 2048 (cdroms) and 4096 (new hdds).

Reading/Writing from block devices is only supported in multiples of the native sector size. Hence, by checking for a multiple of 512 early we just do a lightweight, early, superficial validity test, that filters out the worst offenders, but shouldn't limit us on any devices, because 512 after all is the minimum sector size linux knows, and 2048 and 4096 are multiples of it.

The copy_bytes_full function that is used seems to be quite capable of copying single bytes. And the size of the partition is also round up to a way greater value.

Sure it's generic, you can use it to copy files to files, as well as to copy into block devices. For the former it's good it can work byte exact, but for the block devices things must be sector based.

What kind of fs image are you trying to write into your partition? How could it possibly not be a multiple of 512bytes?

poettering avatar May 06 '24 09:05 poettering