Skip to content
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

Image export from stage1 fails - No space left on device #784

Open
DanyloKD opened this issue Jul 27, 2024 · 1 comment
Open

Image export from stage1 fails - No space left on device #784

DanyloKD opened this issue Jul 27, 2024 · 1 comment

Comments

@DanyloKD
Copy link

Problem description

I'm trying to create a truly minimal system, so after reading documentation I decided to skip stages 2-5. Unfortunately, build process terminates with error during export-image step with the following error: E: Failed to fetch http://raspbian.raspberrypi.com/raspbian/dists/bookworm/main/binary-armhf/Packages Write error - write (28: No space left on device)

After closer investigation of code I've found that too small image file (IMG_SIZE) is allocated in export-image/prerun.sh. It appears that step export-image/02-set-sources installs additional packages into mounted image and fails.

apt-get -y dist-upgrade --auto-remove --purge

I was able to fix build by increasing coefficient used for calculation of ROOT_MARGIN in export-image/prerun.sh:

ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 200 * 1024 * 1024) / 1" | bc)"

Steps to reproduce

Please, use following commands to reproduce the issue.

git clone https://github.com/RPI-Distro/pi-gen.git

cd pi-gen
echo "IMG_NAME='custom'" > config

touch ./stage2/SKIP ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
touch ./stage2/SKIP_IMAGES ./stage3/SKIP_IMAGES ./stage4/SKIP_IMAGES ./stage5/SKIP_IMAGES
touch ./stage1/EXPORT_IMAGE

sudo ./build.sh

Proposed Solution

Export stage shouldn't install new packages according to this comment: #620 (comment). But I'm not sure if it will be easy to remove install command, because some people may already rely on this "side effect" to build their own images. Also, in my opinion, increase of 0.2 coefficient will rather hide than than solve a problem.

I think it would be great to defer creation of image file to the later stage after all packages are installed. In other words, I propose to add support for a postrun.sh script and allocate image after all changes to the file system are done.

The only challenge I foresee is export-image/04-set-partuuid/00-run.sh which requires image blob being allocated and partitioned:
https://github.com/RPi-Distro/pi-gen/blob/dca93d24c7dfb943d84601d2bc4a089f9b66b87f/export-image/04-set-partuuid/00-run.sh#L5C1-L5C6
But I'm happy to dedicate some time to search of alternative implementation.

Please, let me know what are your thoughts. I will be happy to prepare a PR once we reach an agreement on solution.

@XECDesign
Copy link
Member

I plan to alter the behaviour to create a sparse image of a pre-defined size to start with (in stage 0), install everything there and then shrink it down to minimum size + a bit of padding.

You're right, the coefficient is just an ugly workaround and we shouldn't be installing packages in the export stage either.

Sorry, it will take me a while to get around to implementing these changes or testing a PR, so I don't think it's wroth sending one right now. I'd feel guilty leaving it to hang for months. There are some other major changes that I need to make to pi-gen, so I'll do these at the same time.

Many thanks

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

No branches or pull requests

2 participants