mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-01 05:22:24 +08:00
feat(baremetal): grub http boot initrd and kernel (#13414)
This commit is contained in:
@@ -1044,13 +1044,21 @@ func (b *SBaremetalInstance) GetNotifyUrl() string {
|
||||
return fmt.Sprintf("%s/baremetals/%s/notify", b.manager.Agent.GetListenUri(), b.GetId())
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) getTftpFileUrl(filename string) string {
|
||||
func (b *SBaremetalInstance) getTftpEndpoint() (string, error) {
|
||||
serverIP, err := b.manager.Agent.GetDHCPServerIP()
|
||||
if err != nil {
|
||||
log.Errorf("Get http file server: %v", err)
|
||||
return "", errors.Wrap(err, "GetDHCPServerIP")
|
||||
}
|
||||
return fmt.Sprintf("%s:%d", serverIP, o.Options.Port+1000), nil
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) getTftpFileUrl(filename string) string {
|
||||
endpoint, err := b.getTftpEndpoint()
|
||||
if err != nil {
|
||||
log.Errorf("Get http file server endpoint: %v", err)
|
||||
return filename
|
||||
}
|
||||
return fmt.Sprintf("http://%s:%d/tftp/%s", serverIP, o.Options.Port+1000, filename)
|
||||
return fmt.Sprintf("http://%s/tftp/%s", endpoint, filename)
|
||||
}
|
||||
|
||||
func (b *SBaremetalInstance) GetImageCacheUrl() string {
|
||||
@@ -1167,8 +1175,12 @@ func (b *SBaremetalInstance) getGrubPXEConf(isTftp bool) string {
|
||||
// TODO: support not tftp situation
|
||||
kernelArgs := b.getKernelArgs(isTftp, initrd)
|
||||
var resp string
|
||||
endpoint, err := b.getTftpEndpoint()
|
||||
if err != nil {
|
||||
log.Fatalf("getTftpEndpoint %s", err)
|
||||
}
|
||||
if b.NeedPXEBoot() {
|
||||
resp = grub.GetYunionOSConfig(3, kernel, kernelArgs, initrd)
|
||||
resp = grub.GetYunionOSConfig(3, endpoint, kernel, kernelArgs, initrd)
|
||||
} else {
|
||||
resp = grub.GetAutoFindConfig()
|
||||
b.ClearSSHConfig()
|
||||
|
||||
@@ -53,7 +53,7 @@ type BaremetalOptions struct {
|
||||
SendMetricsIntervalSeconds int `help:"interval to send baremetal metrics, default is 300 seconds" default:"300"`
|
||||
|
||||
TftpFileMap map[string]string `help:"map of filename to real file path for tftp"`
|
||||
BootLoader string `help:"PXE boot loader" default:"syslinux"`
|
||||
BootLoader string `help:"PXE boot loader" default:"grub"`
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -16,9 +16,12 @@ package grub
|
||||
|
||||
import "fmt"
|
||||
|
||||
func GetYunionOSConfig(sleepTime int, kernel string, kernelArgs string, initrd string) string {
|
||||
func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string) string {
|
||||
kernel = fmt.Sprintf("(http,${http_site})/tftp/%s", kernel)
|
||||
initrd = fmt.Sprintf("(http,${http_site})/tftp/%s", initrd)
|
||||
return fmt.Sprintf(`
|
||||
set timeout=%d
|
||||
set http_site=%s
|
||||
menuentry 'YunionOS for PXE' --class os {
|
||||
echo "Loading linux %s ..."
|
||||
linux %s %s
|
||||
@@ -26,7 +29,7 @@ menuentry 'YunionOS for PXE' --class os {
|
||||
echo "Loading initrd %s ..."
|
||||
initrd %s
|
||||
}
|
||||
`, sleepTime, kernel, kernel, kernelArgs, initrd, initrd)
|
||||
`, sleepTime, httpSite, kernel, kernel, kernelArgs, initrd, initrd)
|
||||
}
|
||||
|
||||
// REF: https://github.com/bluebanquise/infrastructure/blob/master/packages/ipxe-bluebanquise/grub2-efi-autofind.cfg
|
||||
|
||||
Reference in New Issue
Block a user