diff --git a/build/docker/Dockerfile.baremetal-agent b/build/docker/Dockerfile.baremetal-agent index 462d615189..8ea045523d 100644 --- a/build/docker/Dockerfile.baremetal-agent +++ b/build/docker/Dockerfile.baremetal-agent @@ -1,4 +1,4 @@ -FROM registry.cn-beijing.aliyuncs.com/yunionio/baremetal-base:v0.3.9-20230812.0 +FROM registry.cn-beijing.aliyuncs.com/yunionio/baremetal-base:v0.3.9-20231219.0 MAINTAINER "Zexi Li " diff --git a/build/docker/Dockerfile.baremetal-base b/build/docker/Dockerfile.baremetal-base index 7057b04ded..3f9213b52f 100644 --- a/build/docker/Dockerfile.baremetal-base +++ b/build/docker/Dockerfile.baremetal-base @@ -1,7 +1,7 @@ #FROM --platform=linux/amd64 registry.cn-beijing.aliyuncs.com/yunionio/centos-build:1.1-4 as build #RUN yum install -y https://iso.yunion.cn/vm-images/baremetal-pxerom-1.1.0-21092209.x86_64.rpm #RUN yum install -y http://192.168.23.50:8083/baremetal-pxerom-1.1.0-21092209.x86_64.rpm -FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v0.1.8-20230812.0 as yunionos +FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v3.10.8-20231215.0 as yunionos FROM centos:8 as grub-stage diff --git a/build/docker/Makefile b/build/docker/Makefile index 0b63811c2a..fcb8fa721b 100644 --- a/build/docker/Makefile +++ b/build/docker/Makefile @@ -30,7 +30,7 @@ WEBCONSOLE_BASE_VERSION = 20230731.2 webconsole-base: $(DOCKER_BUILDX)/webconsole-base:$(WEBCONSOLE_BASE_VERSION) -f ./Dockerfile.webconsole-base . -BAREMETAL_BASE_VERSION = v0.3.9-20230812.0 +BAREMETAL_BASE_VERSION = v0.3.9-20231219.1 baremetal-base: $(DOCKER_BUILDX)/baremetal-base:$(BAREMETAL_BASE_VERSION) -f ./Dockerfile.baremetal-base . diff --git a/pkg/apis/identity/consts.go b/pkg/apis/identity/consts.go index 455311d8e0..edf0da5a93 100644 --- a/pkg/apis/identity/consts.go +++ b/pkg/apis/identity/consts.go @@ -211,6 +211,7 @@ var ( "force_dhcp_probe_ipmi", "tftp_block_size_in_bytes", "tftp_max_timeout_retries", + "enable_grub_tftp_download", "lengthy_worker_count", "short_worker_count", // "default_ipmi_password", diff --git a/pkg/baremetal/manager.go b/pkg/baremetal/manager.go index bb6e592a4b..74f9e0b61f 100644 --- a/pkg/baremetal/manager.go +++ b/pkg/baremetal/manager.go @@ -1061,7 +1061,7 @@ func (b *SBaremetalInstance) GetNotifyUrl() string { return fmt.Sprintf("%s/baremetals/%s/notify", b.manager.Agent.GetListenUri(), b.GetId()) } -func (b *SBaremetalInstance) getTftpEndpoint() (string, error) { +func (b *SBaremetalInstance) getHTTPEndpoint() (string, error) { serverIP, err := b.manager.Agent.GetDHCPServerIP() if err != nil { return "", errors.Wrap(err, "GetDHCPServerIP") @@ -1069,8 +1069,8 @@ func (b *SBaremetalInstance) getTftpEndpoint() (string, error) { return fmt.Sprintf("%s:%d", serverIP, o.Options.Port+1000), nil } -func (b *SBaremetalInstance) getTftpFileUrl(filename string) string { - endpoint, err := b.getTftpEndpoint() +func (b *SBaremetalInstance) getHTTPFileUrl(filename string) string { + endpoint, err := b.getHTTPEndpoint() if err != nil { log.Errorf("Get http file server endpoint: %v", err) return filename @@ -1123,7 +1123,7 @@ func (b *SBaremetalInstance) getIsolinuxConf() string { func (b *SBaremetalInstance) getSyslinuxPath(filename string, isTftp bool) string { if isTftp { - return b.getTftpFileUrl(filename) + return b.getHTTPFileUrl(filename) } else { return filename } @@ -1203,12 +1203,12 @@ func (b *SBaremetalInstance) getGrubPXEConf(isTftp bool) string { kernelArgs = fmt.Sprintf("root=/dev/nfs nfsroot=%s rw", o.Options.NfsBootRootfs) } var resp string - endpoint, err := b.getTftpEndpoint() + endpoint, err := b.getHTTPEndpoint() if err != nil { - log.Fatalf("getTftpEndpoint %s", err) + log.Fatalf("getHTTPEndpoint %s", err) } if b.NeedPXEBoot() { - resp = grub.GetYunionOSConfig(3, endpoint, kernel, kernelArgs, initrd) + resp = grub.GetYunionOSConfig(3, endpoint, kernel, kernelArgs, initrd, o.Options.EnableGrubTftpDownload) } else { resp = grub.GetAutoFindConfig() b.ClearSSHConfig() @@ -1229,8 +1229,8 @@ LABEL start kernel := "vmlinuz" initramfs := "initrd.img" if isTftp { - kernel = b.getTftpFileUrl("kernel") - initramfs = b.getTftpFileUrl("initramfs") + kernel = b.getHTTPFileUrl("kernel") + initramfs = b.getHTTPFileUrl("initramfs") } resp += fmt.Sprintf(" kernel %s\n", kernel) args := []string{ diff --git a/pkg/baremetal/options/options.go b/pkg/baremetal/options/options.go index 4c315a61f9..099c6389e2 100644 --- a/pkg/baremetal/options/options.go +++ b/pkg/baremetal/options/options.go @@ -52,9 +52,10 @@ type BaremetalOptions struct { LogFetchIntervalSeconds int `help:"interval to fetch baremetal log, default is 900 seconds" default:"900"` 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:"grub"` - UseMegaRaidPerccli bool `help:"Use MegaRAID perccli" default:"false"` + TftpFileMap map[string]string `help:"map of filename to real file path for tftp"` + BootLoader string `help:"PXE boot loader" default:"grub"` + EnableGrubTftpDownload bool `help:"Enable grub using tftp to download kernel and initrd"` + UseMegaRaidPerccli bool `help:"Use MegaRAID perccli" default:"false"` NfsBootRootfs string `help:"nfs root fs URL"` diff --git a/pkg/baremetal/utils/grub/grub.go b/pkg/baremetal/utils/grub/grub.go index 894be812a6..4886049ab8 100644 --- a/pkg/baremetal/utils/grub/grub.go +++ b/pkg/baremetal/utils/grub/grub.go @@ -14,16 +14,22 @@ package grub -import "fmt" +import ( + "fmt" + "strings" +) -func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string) string { - kernel = fmt.Sprintf("(http,${http_site})/tftp/%s", kernel) - // kernel = fmt.Sprintf("(tftp,10.127.100.2)/%s", kernel) - initrd = fmt.Sprintf("(http,${http_site})/tftp/%s", initrd) - // initrd = fmt.Sprintf("(tftp,10.127.100.2)/%s", initrd) +func GetYunionOSConfig(sleepTime int, httpSite, kernel string, kernelArgs string, initrd string, useTftpDownload bool) string { + if useTftpDownload { + site := strings.Split(httpSite, ":")[0] + kernel = fmt.Sprintf("(tftp,%s)/%s", site, kernel) + initrd = fmt.Sprintf("(tftp,%s)/%s", site, initrd) + } else { + kernel = fmt.Sprintf("(http,%s)/tftp/%s", httpSite, kernel) + initrd = fmt.Sprintf("(http,%s)/tftp/%s", httpSite, initrd) + } return fmt.Sprintf(` set timeout=%d -set http_site=%s menuentry 'YunionOS for PXE' --class os { echo "Loading linux %s ..." linux %s %s @@ -31,7 +37,7 @@ menuentry 'YunionOS for PXE' --class os { echo "Loading initrd %s ..." initrd %s } -`, sleepTime, httpSite, kernel, kernel, kernelArgs, initrd, initrd) +`, sleepTime, kernel, kernel, kernelArgs, initrd, initrd) } // REF: https://github.com/bluebanquise/infrastructure/blob/master/packages/ipxe-bluebanquise/grub2-efi-autofind.cfg