Skip to content

Commit

Permalink
[Release 1.0] Add support for 4096 byte sector size input base images (
Browse files Browse the repository at this point in the history
…#462)

Added support for 4096 byte sector size input base images (#448)

* Added support for 4096 byte sector size input base images

* Fixing tests

* Fixing RAW_FILE misplacement

Co-authored-by: Rhys Oxenham <[email protected]>
  • Loading branch information
atanasdinov and rdoxenham authored Jun 3, 2024
1 parent 09c5508 commit 5eaeada
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## General

* Added the ability to consume both 512/4096 byte sector size disk input base-images
* Added version command and version marker on CRB images

## API
Expand All @@ -16,6 +17,7 @@

* [#442](https://github.com/suse-edge/edge-image-builder/issues/442) - Only get images from specific Kubernetes objects
* [#429](https://github.com/suse-edge/edge-image-builder/issues/429) - Automatically set execute bit on scripts
* [#447](https://github.com/suse-edge/edge-image-builder/issues/447) - Support >512 byte sector size base images

---

Expand Down
4 changes: 2 additions & 2 deletions pkg/build/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestWriteModifyScript(t *testing.T) {
includeCombustion: true,
renameFilesystem: true,
expectedContains: []string{
fmt.Sprintf("guestfish --format=raw --rw -a %s", outputImageFilename),
fmt.Sprintf("guestfish --blocksize=$BLOCKSIZE --format=raw --rw -a %s", outputImageFilename),
fmt.Sprintf("copy-in %s", builder.context.CombustionDir),
"download /boot/grub2/grub.cfg /tmp/grub.cfg",
"btrfs filesystem label / INSTALL",
Expand All @@ -87,7 +87,7 @@ func TestWriteModifyScript(t *testing.T) {
includeCombustion: false,
renameFilesystem: false,
expectedContains: []string{
fmt.Sprintf("guestfish --format=raw --rw -a %s", outputImageFilename),
fmt.Sprintf("guestfish --blocksize=$BLOCKSIZE --format=raw --rw -a %s", outputImageFilename),
"download /boot/grub2/grub.cfg /tmp/grub.cfg",
"sed -i '/ignition.platform/ s/$/ alpha beta /' /tmp/grub.cfg",
},
Expand Down
9 changes: 8 additions & 1 deletion pkg/build/templates/modify-raw-image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ set -euo pipefail
#
# Guestfish Command Documentation: https://libguestfs.org/guestfish.1.html

# Test the block size of the base image and adapt to suit either 512/4096 byte images
BLOCKSIZE=512
if ! guestfish -i --blocksize=$BLOCKSIZE -a {{.ImagePath}} echo "[INFO] 512 byte sector check successful."; then
echo "[WARN] Failed to access image with 512 byte sector size, trying 4096 bytes."
BLOCKSIZE=4096
fi

# Resize the raw disk image to accommodate the users desired raw disk image size
# This is also required if embedding content into /combustion, especially for airgap.
# Should *only* execute if the user is building a raw disk image.
Expand All @@ -24,7 +31,7 @@ cp {{.ImagePath}}.expanded {{.ImagePath}}
rm -f {{.ImagePath}}.expanded
{{ end }}

guestfish --format=raw --rw -a {{.ImagePath}} -i <<'EOF'
guestfish --blocksize=$BLOCKSIZE --format=raw --rw -a {{.ImagePath}} -i <<'EOF'
# Enables write access to the read only filesystem
sh "btrfs property set / ro false"
Expand Down
22 changes: 19 additions & 3 deletions pkg/rpm/resolver/templates/prepare-tarball.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ if [ `wc -w <<< $RAW_FILE` -ne 1 ]; then
exit 1
fi
virt-tar-out -a $RAW_FILE / - | pigz --best > $WORK_DIR/{{.ArchiveName}}
# Test the block size of the base image and adapt to suit either 512/4096 byte images
BLOCKSIZE=512
if ! guestfish -i --blocksize=$BLOCKSIZE -a $RAW_FILE echo "[INFO] 512 byte sector check successful."; then
echo "[WARN] Failed to access image with 512 byte sector size, trying 4096 bytes."
BLOCKSIZE=4096
fi
virt-tar-out --blocksize=$BLOCKSIZE -a $RAW_FILE / - | pigz --best > $WORK_DIR/{{.ArchiveName}}
{{ else }}
virt-tar-out -a $IMG_PATH / - | pigz --best > $WORK_DIR/{{.ArchiveName}}
{{ end }}
# Test the block size of the base image and adapt to suit either 512/4096 byte images
BLOCKSIZE=512
if ! guestfish -i --blocksize=$BLOCKSIZE -a $IMG_PATH echo "[INFO] 512 byte sector check successful."; then
echo "[WARN] Failed to access image with 512 byte sector size, trying 4096 bytes."
BLOCKSIZE=4096
fi
virt-tar-out --blocksize=$BLOCKSIZE -a $IMG_PATH / - | pigz --best > $WORK_DIR/{{.ArchiveName}}
{{ end }}

0 comments on commit 5eaeada

Please sign in to comment.