Merge pull request #2028 from kosmolito/fix/mkfs-overwrite-logic

Fix mkfs overlay: handle false-positive filesystems and add safe overwrite
This commit is contained in:
Jonathon Anderson
2025-12-17 17:09:47 -07:00
committed by GitHub
4 changed files with 15 additions and 11 deletions

View File

@@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix ImageDelete API not returning error when checking if image is used by nodes/profiles
- Fix warewulf-dracut to not run the wwinit module if root is not set to `root=wwclient*`
- Fix `wwctl image import --update` #2066
- Fix filesystem overwrite/force behavior in mkfs overlay. #2028
### Dependencies

View File

@@ -49,4 +49,4 @@
* Arian Cabrera [@acabrera86](https://github.com/acabrera86)
* Dacian Reece-Stremtan <dacianstremtan@gmail.com> [@dacianstremtan](https://github.com/dacianstremtan)
* Adrian Reber <areber@redhat.com>
* Karker Said <said.karker@gmail.com>
* Karker Said <said.karker@gmail.com> [@kosmolito](https://github.com/kosmolito)

View File

@@ -105,17 +105,15 @@ already_formatted() {
if command -v mkfs >/dev/null ; then :
if false || ! already_formatted /dev/disk/by-partlabel/rootfs; then
info "warewulf: mkfs: formatting /dev/disk/by-partlabel/rootfs"
mkfs --type=ext4 /dev/disk/by-partlabel/rootfs || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/rootfs"
mkfs --type=ext4 /dev/disk/by-partlabel/rootfs || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/rootfs"
else
info "warewulf: mkfs: skipping /dev/disk/by-partlabel/rootfs"
continue
fi
if true || ! already_formatted /dev/disk/by-partlabel/scratch; then
info "warewulf: mkfs: formatting /dev/disk/by-partlabel/scratch"
mkfs --type=ext4 /dev/disk/by-partlabel/scratch || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/scratch"
mkfs --type=ext4 -F /dev/disk/by-partlabel/scratch || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/scratch"
else
info "warewulf: mkfs: skipping /dev/disk/by-partlabel/scratch"
continue
fi
else
info "warewulf: mkfs not found"
@@ -173,17 +171,15 @@ already_formatted() {
if command -v mkfs >/dev/null ; then :
if false || ! already_formatted /dev/disk/by-partlabel/rootfs; then
info "warewulf: mkfs: formatting /dev/disk/by-partlabel/rootfs"
mkfs --type=ext4 /dev/disk/by-partlabel/rootfs || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/rootfs"
mkfs --type=ext4 /dev/disk/by-partlabel/rootfs || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/rootfs"
else
info "warewulf: mkfs: skipping /dev/disk/by-partlabel/rootfs"
continue
fi
if true || ! already_formatted /dev/disk/by-partlabel/scratch; then
info "warewulf: mkfs: formatting /dev/disk/by-partlabel/scratch"
mkfs --type=ext4 /dev/disk/by-partlabel/scratch || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/scratch"
mkfs --type=ext4 -F /dev/disk/by-partlabel/scratch || die "warewulf: mkfs: failed to format /dev/disk/by-partlabel/scratch"
else
info "warewulf: mkfs: skipping /dev/disk/by-partlabel/scratch"
continue
fi
else
info "warewulf: mkfs not found"

View File

@@ -57,10 +57,17 @@ if command -v mkfs >/dev/null ; then :
{{- if and $fs.type $fs.device }}
if {{if $fs.overwrite}}true{{else}}false{{end}} || ! already_formatted {{ $fs.device }}; then
info "warewulf: mkfs: formatting {{ $fs.device }}"
mkfs {{ not (empty $fs.type) | ternary (print "--type=" $fs.type) "" }} {{ not (empty $fs.label) | ternary (print "-L " $fs.label) "" }} {{ not (empty $fs.uuid) | ternary (print "-U " $fs.uuid) "" }} {{ default "" $fs.options }} {{ $fs.device }} {{ default "" $fs.size }} || die "warewulf: mkfs: failed to format {{ $fs.device }}"
{{- $forceFlag := "" }}
{{- if $fs.overwrite }}
{{- if regexMatch "^ext[234]$" $fs.type }}
{{- $forceFlag = "-F" }}
{{- else if regexMatch "^(xfs|btrfs)$" $fs.type }}
{{- $forceFlag = "-f" }}
{{- end }}
{{- end }}
mkfs {{ not (empty $fs.type) | ternary (print "--type=" $fs.type) "" }} {{ not (empty $fs.label) | ternary (print "-L " $fs.label) "" }} {{ not (empty $fs.uuid) | ternary (print "-U " $fs.uuid) "" }} {{ default "" $fs.options }} {{ not (empty $forceFlag) | ternary (print $forceFlag) "" }} {{ $fs.device }} {{ default "" $fs.size }} || die "warewulf: mkfs: failed to format {{ $fs.device }}"
else
info "warewulf: mkfs: skipping {{ $fs.device }}"
continue
fi
{{- end }}
{{- end }}