forked from warewulf/warewulf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request warewulf#1191 from anderbubble/dracut-initramfs-boot
Dracut initramfs boot
- Loading branch information
Showing
17 changed files
with
461 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
info "Mounting tmpfs at $NEWROOT" | ||
mount -t tmpfs ${wwinit_tmpfs_size_option} tmpfs "$NEWROOT" | ||
|
||
for archive in "${wwinit_container}" "${wwinit_kmods}" "${wwinit_system}" "${wwinit_runtime}" | ||
do | ||
if [ -n "${archive}" ] | ||
then | ||
info "Loading ${archive}" | ||
(curl --silent -L "${archive}" | gzip -d | cpio -im --directory="${NEWROOT}") || die "Unable to load ${archive}" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
check() { | ||
# Don't include in hostonly mode | ||
[[ $hostonly ]] && return 1 | ||
|
||
# Don't include by default | ||
return 255 | ||
} | ||
|
||
depends() { | ||
echo network | ||
return 0 | ||
} | ||
|
||
install() { | ||
inst_multiple cpio curl | ||
inst_hook cmdline 30 "$moddir/parse-wwinit.sh" | ||
inst_hook pre-mount 30 "$moddir/load-wwinit.sh" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
# root=wwinit | ||
|
||
[ -z "$root" ] && root=$(getarg root=) | ||
|
||
if [ "${root}" = "wwinit" ] | ||
then | ||
info "root=${root}" | ||
export wwinit_container=$(getarg wwinit.container=); info "wwinit.container=${wwinit_container}" | ||
export wwinit_system=$(getarg wwinit.system=); info "wwinit.system=${wwinit_system}" | ||
export wwinit_runtime=$(getarg wwinit.runtime=); info "wwinit.runtime=${wwinit_runtime}" | ||
export wwinit_kmods=$(getarg wwinit.kmods=); info "wwinit.kmods=${wwinit_kmods}" | ||
|
||
wwinit_tmpfs_size=$(getarg wwinit.tmpfs.size=) | ||
if [ -n "$wwinit_tmpfs_size" ] | ||
then | ||
info "wwinit.tmpfs.size=${wwinit_tmpfs_size}" | ||
export wwinit_tmpfs_size_option="-o size=${wwinit_tmpfs_size}" | ||
fi | ||
|
||
if [ -n "${wwinit_container}" ] | ||
then | ||
info "Found root=${root} and a Warewulf container image. Will boot from Warewulf." | ||
rootok=1 | ||
else | ||
die "Found root=${root} but no container image. Cannot boot from Warewulf." | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!ipxe | ||
|
||
echo | ||
echo ================================================================================ | ||
echo Warewulf v4 now booting via dracut: {{.Fqdn}} ({{.Hwaddr}}) | ||
echo | ||
echo Container: {{.ContainerName}} | ||
{{if .KernelOverride }} | ||
echo Kernel: {{.KernelOverride}} | ||
{{else}} | ||
echo Kernel: {{.ContainerName}} (container default) | ||
{{end}} | ||
echo KernelArgs: {{.KernelArgs}} | ||
echo | ||
|
||
set uri http://{{.Ipaddr}}:{{.Port}}/provision/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid} | ||
echo Warewulf Controller: {{.Ipaddr}} | ||
|
||
echo Downloading Kernel Image: | ||
kernel --name kernel ${uri}&stage=kernel || goto reboot | ||
|
||
{{if ne .KernelOverride ""}} | ||
echo Downloading Kernel Modules: | ||
imgextract --name kmods ${uri}&stage=kmods&compress=gz || initrd --name kmods ${uri}&stage=kmods || goto reboot | ||
set kernel_mods initrd=kmods | ||
{{end}} | ||
|
||
echo Downloading initramfs | ||
initrd --name initramfs ${uri}&stage=initramfs || goto reboot | ||
|
||
set dracut_net rd.neednet=1 {{range $devname, $netdev := .NetDevs}}{{if and $netdev.Hwaddr $netdev.Device}} ifname={{$netdev.Device}}:{{$netdev.Hwaddr}} {{end}}{{end}} | ||
set dracut_wwinit root=wwinit wwinit.container=${uri}&stage=container&compress=gz wwinit.system=${uri}&stage=system&compress=gz wwinit.runtime=${uri}&stage=runtime&compress=gz {{if ne .KernelOverride ""}}wwinit.kmods=${uri}&stage=kmods&compress=gz{{end}} init=/init | ||
|
||
echo Booting initramfs | ||
#echo Network KernelArgs: ${dracut_net} | ||
#echo Dracut wwinit KernelArgs: ${dracut_wwinit} | ||
#sleep 15 | ||
boot kernel initrd=initramfs ${kernel_mods} ${dracut_net} ${dracut_wwinit} wwid={{.Hwaddr}} {{.KernelArgs}} | ||
|
||
|
||
:reboot | ||
echo | ||
echo There was an error, rebooting in 15s... | ||
echo | ||
sleep 15 | ||
reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package container | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config" | ||
) | ||
|
||
func TestInitramfsBootPath(t *testing.T) { | ||
conf := warewulfconf.Get() | ||
temp, err := os.MkdirTemp(os.TempDir(), "ww-conf-*") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(temp) | ||
conf.Paths.WWChrootdir = temp | ||
|
||
assert.NoError(t, os.MkdirAll(filepath.Join(RootFsDir("image"), "boot"), 0700)) | ||
|
||
tests := []struct { | ||
name string | ||
initramfs []string | ||
ver string | ||
err error | ||
retName string | ||
}{ | ||
{ | ||
name: "ok case 1", | ||
initramfs: []string{"initramfs-1.1.1.aarch64.img"}, | ||
ver: "1.1.1.aarch64", | ||
err: nil, | ||
}, | ||
{ | ||
name: "ok case 2", | ||
initramfs: []string{"initrd-1.1.1.aarch64"}, | ||
ver: "1.1.1.aarch64", | ||
err: nil, | ||
}, | ||
{ | ||
name: "ok case 3", | ||
initramfs: []string{"initramfs-1.1.1.aarch64"}, | ||
ver: "1.1.1.aarch64", | ||
err: nil, | ||
}, | ||
{ | ||
name: "ok case 4", | ||
initramfs: []string{"initrd-1.1.1.aarch64.img"}, | ||
ver: "1.1.1.aarch64", | ||
err: nil, | ||
}, | ||
{ | ||
name: "error case, wrong init name", | ||
initramfs: []string{"initrr-1.1.1.aarch64.img"}, | ||
ver: "1.1.1.aarch64", | ||
err: fmt.Errorf("Failed to find a target kernel version initramfs"), | ||
}, | ||
{ | ||
name: "error case, wrong ver", | ||
initramfs: []string{"initrr-1.1.1.aarch64.img"}, | ||
ver: "1.1.2.aarch64", | ||
err: fmt.Errorf("Failed to find a target kernel version initramfs"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Logf("running test: %s", tt.name) | ||
for _, init := range tt.initramfs { | ||
assert.NoError(t, os.WriteFile(filepath.Join(RootFsDir("image"), "boot", init), []byte(""), 0600)) | ||
} | ||
initPath, err := InitramfsBootPath("image", tt.ver) | ||
assert.Equal(t, tt.err, err) | ||
if err == nil { | ||
assert.NotEmpty(t, initPath) | ||
} else { | ||
assert.Empty(t, initPath) | ||
} | ||
|
||
if tt.retName != "" { | ||
assert.Equal(t, filepath.Base(initPath), tt.retName) | ||
} | ||
// remove the file | ||
for _, init := range tt.initramfs { | ||
assert.NoError(t, os.Remove(filepath.Join(RootFsDir("image"), "boot", init))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.