mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 10:19:35 +00:00
matchbox/http: Update grub endpoint to use profile kernel args
This commit is contained in:
committed by
Dalton Hubble
parent
fd2c5e303d
commit
2a83612ffb
@@ -57,7 +57,18 @@ You can chainload from a menu entry or use other [iPXE commands](http://ipxe.org
|
||||
|
||||
## GRUB
|
||||
|
||||
Needs docs.
|
||||
Needs more docs.
|
||||
|
||||
`grub-mknetdir --net-directory=/var/lib/tftpboot`
|
||||
|
||||
/var/lib/tftpboot/boot/grub/grub.cfg:
|
||||
```ini
|
||||
insmod i386-pc/http.mod
|
||||
set root=http,matchbox.foo:8080
|
||||
configfile /grub
|
||||
```
|
||||
|
||||
Make sure to replace variables in the example config files; instead of iPXE variables, use GRUB variables. Check the [GRUB2 manual](https://www.gnu.org/software/grub/manual/grub.html#Network).
|
||||
|
||||
### Configuring DHCP
|
||||
|
||||
|
||||
@@ -10,12 +10,19 @@ import (
|
||||
)
|
||||
|
||||
var grubTemplate = template.Must(template.New("GRUB2 config").Parse(`default=0
|
||||
fallback=1
|
||||
timeout=1
|
||||
menuentry "CoreOS" {
|
||||
menuentry "CoreOS (EFI)" {
|
||||
echo "Loading kernel"
|
||||
linuxefi "{{.Kernel}}"{{range $key, $value := .Cmdline}} {{if $value}}"{{$key}}={{$value}}"{{else}}"{{$key}}"{{end}}{{end}}
|
||||
linuxefi "{{.Kernel}}"{{range $arg := .Args}} {{$arg}}{{end}}{{range $key, $value := .Cmdline}} {{if $value}}"{{$key}}={{$value}}"{{else}}"{{$key}}"{{end}}{{end}}
|
||||
echo "Loading initrd"
|
||||
initrdefi {{ range $element := .Initrd }}"{{$element}}" {{end}}
|
||||
initrdefi {{ range $element := .Initrd }} "{{$element}}"{{end}}
|
||||
}
|
||||
menuentry "CoreOS (BIOS)" {
|
||||
echo "Loading kernel"
|
||||
linux "{{.Kernel}}"{{range $arg := .Args}} {{$arg}}{{end}}{{range $key, $value := .Cmdline}} {{if $value}}"{{$key}}={{$value}}"{{else}}"{{$key}}"{{end}}{{end}}
|
||||
echo "Loading initrd"
|
||||
initrd {{ range $element := .Initrd }} "{{$element}}"{{end}}
|
||||
}
|
||||
`))
|
||||
|
||||
|
||||
43
matchbox/http/grub_test.go
Normal file
43
matchbox/http/grub_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"context"
|
||||
logtest "github.com/Sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
fake "github.com/coreos/matchbox/matchbox/storage/testfakes"
|
||||
)
|
||||
|
||||
func TestGrubHandler(t *testing.T) {
|
||||
logger, _ := logtest.NewNullLogger()
|
||||
srv := NewServer(&Config{Logger: logger})
|
||||
h := srv.grubHandler()
|
||||
ctx := withProfile(context.Background(), fake.Profile)
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/", nil)
|
||||
h.ServeHTTP(ctx, w, req)
|
||||
// assert that:
|
||||
// - the Profile's NetBoot config is rendered as a GRUB2 config
|
||||
expectedScript := `default=0
|
||||
fallback=1
|
||||
timeout=1
|
||||
menuentry "CoreOS (EFI)" {
|
||||
echo "Loading kernel"
|
||||
linuxefi "/image/kernel" a=b c
|
||||
echo "Loading initrd"
|
||||
initrdefi "/image/initrd_a" "/image/initrd_b"
|
||||
}
|
||||
menuentry "CoreOS (BIOS)" {
|
||||
echo "Loading kernel"
|
||||
linux "/image/kernel" a=b c
|
||||
echo "Loading initrd"
|
||||
initrd "/image/initrd_a" "/image/initrd_b"
|
||||
}
|
||||
`
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
assert.Equal(t, expectedScript, w.Body.String())
|
||||
}
|
||||
Reference in New Issue
Block a user