fix(host-deployer): detect UEFI supported not correct

This commit is contained in:
Zexi Li
2021-07-06 19:32:30 +08:00
parent 703a89e53f
commit 15a160c876
2 changed files with 46 additions and 2 deletions
+45 -1
View File
@@ -504,8 +504,52 @@ func (l *sLinuxRootFs) disableSerialConsoleSystemd(rootFs IDiskPartition) {
}
}
func (l *sLinuxRootFs) dirWalk(part IDiskPartition, sPath string, wF func(path string, isDir bool) bool) bool {
stat := part.Stat(sPath, false)
if !stat.IsDir() {
if wF(sPath, false) {
return true
}
return false
}
if wF(sPath, true) {
return true
}
for _, subPath := range part.ListDir(sPath, false) {
if l.dirWalk(part, path.Join(sPath, subPath), wF) {
return true
}
}
return false
}
func (l *sLinuxRootFs) DetectIsUEFISupport(part IDiskPartition) bool {
return part.Exists("/efi", false)
// 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 {
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
}
func (l *sLinuxRootFs) IsCloudinitInstall() bool {
+1 -1
View File
@@ -65,7 +65,7 @@ func (p *SKVMGuestDiskPartition) GetPhysicalPartitionType() string {
if idxP > 0 {
dev = dev[:idxP]
}
cmd := fmt.Sprintf(`fdisk -l %s | grep "Disk label type:"`, dev)
cmd := fmt.Sprintf(`fdisk -l %s | grep "Disk.*label type:"`, dev)
output, err := procutils.NewCommand("sh", "-c", cmd).Output()
if err != nil {
log.Errorf("get disk label type error %s", output)