def doEnableSwap(self): if self.param.runMode not in ["normal", "setup"]: print("Operation is not supported in \"%s\" mode." % (self.param.runMode), file=sys.stderr) return 1 layout = strict_hdds.get_storage_layout() if layout is None: print("Invalid storage layout.", file=sys.stderr) return 1 self.param.swapManager.enableSwap(layout) if layout.name in ["bios-ext4", "efi-ext4"]: swapSizeStr = FmUtil.formatSize(os.path.getsize(layout.dev_swap)) print("Swap File: %s (size:%s)" % (layout.dev_swap, swapSizeStr)) elif layout.name in ["efi-bcache-btrfs", "efi-bcachefs"]: uuid = pyudev.Device.from_device_file( pyudev.Context(), layout.dev_swap).get("ID_FS_UUID") swapSizeStr = FmUtil.formatSize( FmUtil.getBlkDevSize(layout.dev_swap)) print("Swap Partition: %s (UUID:%s, size:%s)" % (layout.dev_swap, uuid, swapSizeStr)) else: assert False return 0
def __partSize(devpath): sz = FmUtil.getBlkDevSize(devpath) return FmUtil.formatSize(sz)
def doShow(self): ''' >>> Example: System status: unstable Hardware: Unknown hardware Boot mode: UEFI Main OS: Linux (kernel-x86_64-4.4.6) Rescue OS: Installed Auxillary OSes: None Storage layout: Name: efi-bcache-lvm ESP partition: /dev/sdc1 Swap partition: /dev/sdc2 (16.0GiB) Cache partition: /dev/sdc3 (102.7GiB) LVM PVs: /dev/sda,bcache0 /dev/sdb,bcache16 (total: 8.2TiB) Swap: Disabled Logging: To harddisk (/var/log) Backend graphics devices: /dev/dri/card1 /dev/dri/card2 (total: 16GiB 14.3TFLOPs) System users: root, nobody System groups: root, nobody, nogroup, wheel, users Repositories: fpemud-overlay [Dirty] (Last Update: 2016-01-01 00:00:00) local [Not Exist] Overlays: wrobel [Subversion] (https://overlays.gentoo.org/svn/dev/wrobel ) Selected packages: app-admin/ansible (repo-gentoo) app-misc/sway (overlay-uly55e5) ''' if self.param.runMode != "normal": print("WARNING: Running in \"%s\" mode!!!" % (self.param.runMode)) print("") self.param.sysChecker.basicCheckWithOverlayContent() if self.param.runMode in ["normal", "setup"]: layout = strict_hdds.get_storage_layout() bbkiObj = BbkiWrapper(layout) s = "System status: " if bbkiObj.isStable(): s += "stable" else: s += "unstable" print(s) print("") print("Hardware:") hwInfo = self.param.machineInfoGetter.hwInfo() if isinstance(hwInfo, HwInfoPcBranded): print(" %s %s" % (hwInfo.vendor, hwInfo.model)) elif isinstance(hwInfo, HwInfoPcAssembled): print(" DIY PC") else: assert False print("") if True: print("Main OS:") be = bbkiObj.get_pending_boot_entry() if be is None: be = "None" else: be = "Linux (%s)" % (be.postfix) print(" %s" % (be)) print("Rescue OS:") if bbkiObj.isRescueOsInstalled(): print(" Installed") else: print(" Not installed") auxOsInfo = bbkiObj.getAuxOsInfo() if len(auxOsInfo) > 0: print("Auxillary OSes:") for item in auxOsInfo: sys.stdout.write(" %s:" % (item.name)) for i in range(0, 20 - len(item.name)): sys.stdout.write(" ") print(item.partition_path) print("") if True: def __partSize(devpath): sz = FmUtil.getBlkDevSize(devpath) return FmUtil.formatSize(sz) print("Boot mode:") if layout.boot_mode == strict_hdds.StorageLayout.BOOT_MODE_EFI: print(" UEFI") elif layout.boot_mode == strict_hdds.StorageLayout.BOOT_MODE_BIOS: print(" BIOS") else: assert False print("Storage layout:") print(" Name: %s" % (layout.name)) print(" State: ready") if layout.name == "bios-ext4": print(" Boot disk: %s" % (layout.boot_disk)) print(" Root partititon: %s (%s)" % (layout.dev_rootfs, __partSize(layout.dev_rootfs))) elif layout.name == "efi-ext4": print(" Boot disk: %s" % (layout.boot_disk)) print(" Root partititon: %s (%s)" % (layout.dev_rootfs, __partSize(layout.dev_rootfs))) elif layout.name in ["efi-btrfs"]: print(" Boot disk: %s" % (layout.boot_disk)) totalSize = 0 pvStrList = [] for hddDevPath in layout.get_hdd_list(): parti = layout.get_hdd_data_partition(hddDevPath) pvStrList.append("%s" % (parti)) totalSize += FmUtil.getBlkDevSize(parti) print(" HDDs: %s (total: %s)" % (" ".join(pvStrList), FmUtil.formatSize(totalSize))) elif layout.name == "efi-bcache-btrfs": if layout.get_ssd() is not None: print(" SSD: %s (boot disk)" % (layout.get_ssd())) if layout.get_ssd_swap_partition() is not None: print( " Swap partition: %s (%s)" % (layout.get_ssd_swap_partition(), __partSize(layout.get_ssd_swap_partition()))) else: print(" Swap partition: None") print(" Cache partition: %s (%s)" % (layout.get_ssd_cache_partition(), __partSize(layout.get_ssd_cache_partition()))) else: print(" SSD: None") print(" Boot disk: %s" % (layout.boot_disk)) totalSize = 0 pvStrList = [] for hddDevPath in layout.get_hdd_list(): bcacheDevPath = layout.get_hdd_bcache_dev(hddDevPath) pvStrList.append( "%s,%s" % (hddDevPath, bcacheDevPath.replace("/dev/", ""))) totalSize += FmUtil.getBlkDevSize(bcacheDevPath) print(" HDDs: %s (total: %s)" % (" ".join(pvStrList), FmUtil.formatSize(totalSize))) elif layout.name == "efi-bcachefs": if layout.get_ssd() is not None: print(" SSD: %s (boot disk)" % (layout.get_ssd())) if layout.get_ssd_swap_partition() is not None: print( " Swap partition: %s (%s)" % (layout.get_ssd_swap_partition(), __partSize(layout.get_ssd_swap_partition()))) else: print(" Swap partition: None") print(" Cache partition: %s (%s)" % (layout.get_ssd_cache_partition(), __partSize(layout.get_ssd_cache_partition()))) else: print(" SSD: None") print(" Boot disk: %s" % (layout.boot_disk)) totalSize = 0 pvStrList = [] for hddDevPath in layout.get_hdd_list(): parti = layout.get_hdd_data_partition(hddDevPath) pvStrList.append("%s" % (parti)) totalSize += FmUtil.getBlkDevSize(parti) print(" HDDs: %s (total: %s)" % (" ".join(pvStrList), FmUtil.formatSize(totalSize))) else: assert False print("Swap:") if self.param.runMode == "normal": if layout.dev_swap is None: print(" Disabled") else: serviceName = FmUtil.systemdFindSwapServiceInDirectory( "/etc/systemd/system", layout.dev_swap) if serviceName is None or not FmUtil.systemdIsServiceEnabled( serviceName): print(" Disabled") else: print(" Enabled (%s)" % (FmUtil.formatSize(layout.get_swap_size()))) elif self.param.runMode == "setup": print(" Disabled") else: assert False # FIXME print("Logging:") if True: print(" To harddisk (/var/log)") print("") if True: ret = FmUtil.findBackendGraphicsDevices() if len(ret) > 0: totalMem = 0 totalFlopsForFp32 = 0 for path in ret: rc = FmUtil.getVendorIdAndDeviceIdByDevNode(path) if rc is None: totalMem = None break info = DevHwInfoDb.getDevHwInfo(rc[0], rc[1]) if info is None: totalMem = None break if "mem" not in info or not isinstance( info["mem"], int): totalMem = None break if "fp32" not in info or not isinstance( info["fp32"], int): totalMem = None break totalMem += info["mem"] totalFlopsForFp32 += info["fp32"] totalStr = "unknown" if totalMem is not None: totalStr = "%s %s" % (FmUtil.formatSize( totalMem), FmUtil.formatFlops(totalFlopsForFp32)) print("Backend graphics devices:") print(" %s (total: %s)" % (" ".join(ret), totalStr)) print("") elif self.param.runMode == "prepare": bbkiObj = BbkiWrapper(None) print("Main OS:") be = bbkiObj.get_newest_boot_entry() if be is None: be = "None" else: be = "Linux (%s)" % (be.postfix) print(" %s" % (be)) print("") else: assert False with strict_pgs.PasswdGroupShadow() as pgs: print("System users: %s" % (", ".join(pgs.getSystemUserList()))) print("System groups: %s" % (", ".join(pgs.getSystemGroupList()))) print("") print("Repositories:") repoman = EbuildRepositories() repoList = repoman.getRepositoryList() if len(repoList) > 0: maxLen = FmUtil.strListMaxLen(repoList) for repoName in repoList: s1 = FmUtil.pad(repoName, maxLen) if repoman.isRepoExist(repoName): print(" %s [Good ] Last Update: %s" % (s1, FmUtil.getDirLastUpdateTime( repoman.getRepoDir(repoName)))) else: print(" %s [Not Exist]" % (s1)) else: print(" None") print("") print("Overlays:") layman = EbuildOverlays() overlayList = layman.getOverlayList() if len(overlayList) > 0: tlist2 = [] tlist3 = [] for lname in overlayList: if layman.getOverlayType(lname) == "static": ltype = "Static" lurl = "" else: ltype, lurl = layman.getOverlayVcsTypeAndUrl(lname) if ltype == "git": ltype = "Git" elif ltype == "svn": ltype = "Subversion" else: assert False tlist2.append(ltype) tlist3.append(lurl) maxLen1 = FmUtil.strListMaxLen(overlayList) maxLen2 = FmUtil.strListMaxLen(tlist2) maxLen3 = FmUtil.strListMaxLen(tlist3) for i in range(0, len(overlayList)): s1 = FmUtil.pad(overlayList[i], maxLen1) s2 = FmUtil.pad(tlist2[i], maxLen2) s3 = FmUtil.pad(tlist3[i], maxLen3) print(" %s [%s %s] Last Update: %s" % (s1, s2, s3, FmUtil.getDirLastUpdateTime( layman.getOverlayDir(overlayList[i])))) else: print(" None") print("") print("Selected packages:") if True: pkgList = FmUtil.portageReadWorldFile(FmConst.worldFile) maxLen = max([len(x) for x in pkgList]) for repoName in repoman.getRepositoryList(): tempList = [] for pkg in pkgList: if os.path.exists( os.path.join(repoman.getRepoDir(repoName), pkg)): print(" %s (repo-%s)" % (FmUtil.pad(pkg, maxLen), repoName)) else: tempList.append(pkg) pkgList = tempList for overlayName in layman.getOverlayList(): tempList = [] for pkg in pkgList: if os.path.exists( os.path.join(layman.getOverlayDir(overlayName), pkg)): print(" %s (overlay-%s)" % (FmUtil.pad(pkg, maxLen), overlayName)) else: tempList.append(pkg) pkgList = tempList for pkg in pkgList: print(" %s" % (pkg)) return 0
def __init__(self, devType, tmpDir, hwInfo, **kwargs): self._archDirDict = { "amd64": "x86_64", "arm64": "arm64", } self._stage4Info = { "gentoo-linux": { "amd64": { "subarch": "amd64", "variant": "systemd", "profile": "default/linux/amd64/17.1", "stage3-file": None, "work-dir": gstage4.WorkDir(os.path.join(tmpDir, "stage4-gentoo-amd64")), "completed": False }, # "arm64": { # "arch": "arm64", # "completed": False # }, }, "windows-xp": { "amd64": { "arch": wstage4.Arch.X86_64, "version": wstage4.Version.WINDOWS_XP, "edition": wstage4.Edition.WINDOWS_XP_PROFESSIONAL, "lang": wstage4.Lang.en_US, "product-id": "windows-xp-professional.x86_64.en-US", "work-dir": wstage4.WorkDir(os.path.join(tmpDir, "stage4-winxp-amd64")), "completed": False, }, }, "windows-7": { "amd64": { "arch": wstage4.Arch.X86_64, "version": wstage4.Version.WINDOWS_7, "edition": wstage4.Edition.WINDOWS_7_ULTIMATE, "lang": wstage4.Lang.en_US, "product-id": "windows-7-ultimate.x86_64.en-US", "work-dir": wstage4.WorkDir(os.path.join(tmpDir, "stage4-win7-amd64")), "completed": False, }, }, } self._targetSystemInfo = { "amd64": { "subarch": "amd64", "variant": "openrc", "profile": "default/linux/amd64/17.1/no-multilib", "stage3-file": None, "work-dir": gstage4.WorkDir(os.path.join(tmpDir, "instcd-rootfs-amd64")), "completed": False }, # "arm64": { # "arch": "arm64", # "completed": False # }, } self._snapshotFile = None self._devType = devType if self._devType == self.DEV_TYPE_ISO: assert len( kwargs ) == 3 and "file_path" in kwargs and "disk_name" in kwargs and "disk_label" in kwargs self._filePath = kwargs["file_path"] self._diskName = kwargs["disk_name"] self._diskLabel = kwargs["disk_label"] # FIXME: check elif self._devType == self.DEV_TYPE_CDROM: assert len( kwargs ) == 3 and "dev_path" in kwargs and "disk_name" in kwargs and "disk_label" in kwargs self._devPath = kwargs["dev_path"] self._diskName = kwargs["disk_name"] self._diskLabel = kwargs["disk_label"] # FIXME: check elif self._devType == self.DEV_TYPE_USB_STICK: assert len( kwargs ) == 3 and "dev_path" in kwargs and "disk_name" in kwargs and "disk_label" in kwargs self._devPath = kwargs["dev_path"] self._diskName = kwargs["disk_name"] self._diskLabel = kwargs["disk_label"] if not FmUtil.isBlkDevUsbStick(self._devPath): raise Exception("device %s does not seem to be an usb-stick." % (self._devPath)) if FmUtil.getBlkDevSize(self._devPath) < DEV_MIN_SIZE: raise Exception("device %s needs to be at least %d GB." % (self._devPath, DEV_MIN_SIZE_IN_GB)) if FmUtil.isMountPoint(self._devPath): raise Exception( "device %s or any of its partitions is already mounted, umount it first." % (self._devPath)) else: assert False self._cp = gstage4.ComputingPower.new( hwInfo.hwDict["cpu"]["cores"], hwInfo.hwDict["memory"]["size"] * 1024 * 1024 * 1024, 10 if "fan" in hwInfo.hwDict else 1) cfg = windown.simple_cfg.Config() cfg.fetch_command = r'/usr/libexec/robust_layer/wget -O \"${FILE}\" \"${URI}\"' cfg.resume_command = r'/usr/libexec/robust_layer/wget -c -O \"${FILE}\" \"${URI}\"' cfg.fetch_command_quiet = r'/usr/libexec/robust_layer/wget -q -O \"${FILE}\" \"${URI}\"' cfg.resume_command_quiet = r'/usr/libexec/robust_layer/wget -q -c -O \"${FILE}\" \"${URI}\"' cfg.checksum_failure_max_tries = 1 self._winCache = windown.WindowsDownloader(cfg)