fix(host-deployer): os arch and uefi detect (#15351)

This commit is contained in:
wanyaoqi
2022-11-13 18:18:01 +08:00
committed by GitHub
parent 70755a9a1b
commit d68fd533e4
4 changed files with 53 additions and 52 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.2
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.3
MAINTAINER "Yaoqi Wan wanyaoqi@yunionyun.com"
+36 -31
View File
@@ -372,29 +372,53 @@ func (l *sLinuxRootFs) GetOs() string {
}
func (l *sLinuxRootFs) GetArch(rootFs IDiskPartition) string {
if rootFs.Exists("/lib64", false) && rootFs.Exists("/usr/lib64", false) {
files := rootFs.ListDir("/lib64", false)
getOsArch64 := func(dir string) string {
files := rootFs.ListDir(dir, false)
for i := 0; i < len(files); i++ {
if strings.HasPrefix(files[i], "ld-") {
if strings.Contains(files[i], apis.OS_ARCH_AARCH64) {
return apis.OS_ARCH_AARCH64
} else if strings.Contains(files[i], "x86") {
} else if strings.Contains(files[i], apis.OS_ARCH_X86) {
return apis.OS_ARCH_X86_64
}
}
}
return apis.OS_ARCH_X86_64
} else {
files := rootFs.ListDir("/lib", false)
return ""
}
getOsArch32 := func(dir string) string {
files := rootFs.ListDir(dir, false)
for i := 0; i < len(files); i++ {
if strings.HasPrefix(files[i], "ld-") {
if strings.Contains(files[i], "arm") {
if strings.Contains(files[i], apis.OS_ARCH_ARM) {
return apis.OS_ARCH_AARCH32
}
}
}
return apis.OS_ARCH_X86_32
}
if rootFs.Exists("/lib64", false) {
if osArch := getOsArch64("/lib64"); osArch != "" {
return osArch
}
}
if rootFs.Exists("/usr/lib64", false) {
if osArch := getOsArch64("/usr/lib64"); osArch != "" {
return osArch
}
}
if rootFs.Exists("/lib", false) {
if osArch := getOsArch32("/lib"); osArch != "" {
return osArch
}
}
if rootFs.Exists("/usr/lib", false) {
if osArch := getOsArch32("/usr/lib"); osArch != "" {
return osArch
}
}
return apis.OS_ARCH_X86_64
}
func (l *sLinuxRootFs) PrepareFsForTemplate(rootFs IDiskPartition) error {
@@ -582,32 +606,13 @@ func (l *sLinuxRootFs) dirWalk(part IDiskPartition, sPath string, wF func(path s
}
func (l *sLinuxRootFs) DetectIsUEFISupport(part IDiskPartition) bool {
// ref: https://wiki.archlinux.org/title/EFI_system_partition#Check_for_an_existing_partition
// To confirm this is the ESP, mount it and check whether it contains a directory named EFI,
// if it does this is definitely the ESP.
efiDir := "/EFI"
exits := part.Exists(efiDir, false)
if !exits {
partDev := part.GetPartDev()
output, err := procutils.NewCommand("efibootmgr", part.GetPartDev()).Output()
if err != nil {
log.Infof("part is not efi partition %s: %s, %s", partDev, output, err)
return false
}
hasEFIFirmware := false
l.dirWalk(part, efiDir, func(path string, isDir bool) bool {
if isDir {
return false
}
// check file is UEFI firmware
if strings.HasSuffix(path, ".efi") {
log.Infof("EFI firmware %s found", path)
hasEFIFirmware = true
return true
}
// continue walk
return false
})
return hasEFIFirmware
return true
}
func (l *sLinuxRootFs) IsCloudinitInstall() bool {
+16 -1
View File
@@ -26,6 +26,7 @@ import (
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
@@ -106,7 +107,7 @@ func (w *SWindowsRootFs) GetReleaseInfo(IDiskPartition) *deployapi.ReleaseInfo {
if tool.CheckPath() {
distro := tool.GetProductName()
version := tool.GetVersion()
arch := tool.GetArch(hostCpuArch)
arch := w.GetArch(hostCpuArch)
lan := tool.GetInstallLanguage()
return &deployapi.ReleaseInfo{
Distro: distro,
@@ -154,6 +155,20 @@ func (w *SWindowsRootFs) GetLoginAccount(rootFs IDiskPartition, sUser string, de
return selUsr, nil
}
func (w *SWindowsRootFs) GetArch(hostCpuArch string) string {
if w.rootFs.Exists("/program files (x86)", true) {
return apis.OS_ARCH_X86_64
} else if w.rootFs.Exists("/program files (arm)", true) {
return apis.OS_ARCH_AARCH64
}
if hostCpuArch == apis.OS_ARCH_AARCH32 {
return apis.OS_ARCH_AARCH32
} else {
return apis.OS_ARCH_X86_32
}
}
func (w *SWindowsRootFs) IsWindows10() bool {
info := w.GetReleaseInfo(nil)
if info != nil && strings.HasPrefix(info.Distro, "Windows 10 ") {
-19
View File
@@ -28,7 +28,6 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/apis"
"yunion.io/x/onecloud/pkg/util/procutils"
"yunion.io/x/onecloud/pkg/util/regutils2"
)
@@ -606,24 +605,6 @@ func (w *SWinRegTool) GetInstallLanguage() string {
}
}
func (w *SWinRegTool) GetArch(hostCpuArch string) string {
prodKey := `HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\CurrentVersion`
ver := w.GetRegistry(prodKey)
if len(ver) > 0 {
if hostCpuArch == apis.OS_ARCH_AARCH64 {
return apis.OS_ARCH_AARCH64
} else {
return apis.OS_ARCH_X86_64
}
} else {
if hostCpuArch == apis.OS_ARCH_AARCH32 {
return apis.OS_ARCH_AARCH32
} else {
return apis.OS_ARCH_X86_32
}
}
}
func (w *SWinRegTool) LogontypePath() string {
return `HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LogonType`
}