def test_is_mounted1(self): #If not mounted, mount it if not Functions.is_mounted(self.path): self.assertEqual( CoreTools.mount_partition(self.path, "/tmp/wxfixbootmtpt"), 0) self.assertTrue(CoreTools.is_mounted(self.path))
def get_oss(): """Get the names of all OSs on the HDDs.""" logger.info("get_oss(): Finding operating systems...") root_filesystem = CoreTools.get_partition_mounted_at("/") os_info = {} #Get Linux OSs. keys = list(DISK_INFO.keys()) keys.sort() for partition in keys: if DISK_INFO[partition]["Type"] == "Device": continue elif DISK_INFO[partition]["FileSystem"] in ("hfsplus", "hfs", "apfs"): #TODO Check if this is what APFS shows up as. #Look for macOS. os_name = "macOS ("+partition+")" logger.debug("get_oss(): Looking for macOS on "+partition+"...") #Check if we need to mount the partition. was_mounted = False if CoreTools.is_mounted(partition): #If mounted, get the mountpoint. mount_point = CoreTools.get_mount_point_of(partition) else: #Mount the partition and check if anything went wrong. mount_point = "/mnt/wxfixboot/mountpoints"+partition if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. logger.warning("get_oss(): Couldn't mount "+partition + "! Skipping this partition...") continue was_mounted = True if os.path.exists(mount_point+"/mach_kernel") \ or os.path.exists(mount_point+"/System/Library/Kernels/kernel"): #Create OS_INFO entry for it. logger.debug("get_oss(): Found "+os_name+"...") os_info[os_name] = {} os_info[os_name]["Name"] = os_name os_info[os_name]["IsCurrentOS"] = False os_info[os_name]["Arch"] = "Unknown" os_info[os_name]["Partition"] = partition os_info[os_name]["PackageManager"] = "Mac App Store" os_info[os_name]["RawFSTabInfo"], os_info[os_name]["EFIPartition"], \ os_info[os_name]["BootPartition"] = (["Unknown"], "Unknown", "Unknown") #unmount the filesystem if needed. if was_mounted: if CoreTools.unmount(mount_point) != 0: logger.error("get_oss(): Couldn't unmount "+partition + "! Doing emergency exit...") CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for " + "operating systems on it! Please reboot your " + "computer and try again.") elif DISK_INFO[partition]["FileSystem"] in ("vfat", "ntfs", "exfat"): #Look for Windows. NOTE: It seems NTFS volumes can't be mounted twice, which is why #we're being more careful here. #TODO ^ Check, I think it worked before. Good to be cautious either way. logger.debug("get_oss(): Looking for Windows on "+partition+"...") #Check if we need to mount the partition. was_mounted = False if CoreTools.is_mounted(partition): #If mounted, get the mountpoint. mount_point = CoreTools.get_mount_point_of(partition) else: #Mount the partition and check if anything went wrong. mount_point = "/mnt/wxfixboot/mountpoints"+partition if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. logger.warning("get_oss(): Couldn't mount "+partition + "! Skipping this partition...") continue was_mounted = True #Check if there's a Windows/WinNT dir. if not (os.path.isdir(mount_point+"/WinNT") or os.path.isdir(mount_point+"/Windows") \ or os.path.isdir(mount_point+"/WINDOWS")): #Skip this partition, and unmount if needed. logger.info("get_oss(): Windows wasn't found...") else: #Look for lots of different Windows editions. #Look for the newest ones first, due to references to old versions #in the licenses messing up our version detection. if CoreStartupTools.has_windows_10(mount_point): os_name = "Windows 10" elif CoreStartupTools.has_windows_8(mount_point): os_name = "Windows 8/8.1" elif CoreStartupTools.has_windows_7(mount_point): os_name = "Windows 7" elif CoreStartupTools.has_windows_vista(mount_point): os_name = "Windows Vista" elif CoreStartupTools.has_windows_xp(mount_point): os_name = "Windows XP" elif CoreStartupTools.has_windows_9x(mount_point): os_name = "Windows 95/98/ME" else: #Unknown Windows. os_name = "Windows" #Create os_info entry for it. os_name = os_name+" ("+partition+")" logger.debug("get_oss(): Found "+os_name+"...") os_info[os_name] = {} os_info[os_name]["Name"] = os_name os_info[os_name]["IsCurrentOS"] = False os_info[os_name]["Arch"] = "Unknown" os_info[os_name]["Partition"] = partition os_info[os_name]["PackageManager"] = "Windows Installer" os_info[os_name]["RawFSTabInfo"], os_info[os_name]["EFIPartition"], \ os_info[os_name]["BootPartition"] = (["Unknown"], "Unknown", "Unknown") #unmount the filesystem if needed. if was_mounted: if CoreTools.unmount(mount_point) != 0: logger.error("get_oss(): Couldn't unmount "+partition +"! Doing emergency exit...") CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for " + "operating systems on it! Please reboot your " + "computer and try again.") else: #Look for Linux. #The python command runs on python 3. logger.debug("get_oss(): Looking for Linux on "+partition+"...") #If there are aliases for partition, check if the root FS is one of those too. root_filesystem_is_alias = False if "Aliases" in DISK_INFO[partition]: logger.debug("get_oss(): Checking if RootFS is an alias for "+partition+"...") if root_filesystem in DISK_INFO[partition]["Aliases"]: logger.debug("get_oss(): RootFS is an alias...") root_filesystem_is_alias = True else: logger.debug("get_oss(): RootFS isn't an alias...") root_filesystem_is_alias = False if partition == root_filesystem or root_filesystem_is_alias: cmd = "cat /etc/os-release" apt_cmd = "which apt-get" dnf_cmd = "which dnf" chroot = False is_current_os = True mount_point = "" else: mount_point = "/mnt/wxfixboot/mountpoints"+partition cmd = "cat "+mount_point+"/etc/os-release" apt_cmd = "chroot "+mount_point+" which apt-get" dnf_cmd = "chroot "+mount_point+" which dnf" chroot = True is_current_os = False #Mount the partition and check if anything went wrong. if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. logger.warning("get_oss(): Couldn't mount "+partition + "! Skipping this partition...") continue #Look for Linux on this partition. retval, temp = CoreTools.start_process(cmd, return_output=True) os_name = "" try: for line in temp.split("\n"): if "PRETTY_NAME" in line: os_name = line.split("=")[1].replace('\"', '') except IndexError: os_name = "" #Run the function to get the architechure. os_architecture = CoreStartupTools.determine_os_architecture(mount_point=mount_point) #If the OS's name wasn't found, but its architecture was, there must be an OS here, so #try to use lsb_release if possible before asking the user. Catch if the name is just #whitespace too. if (retval != 0 or os_name == "" or os_name.isspace()) and os_architecture != None: os_name = CoreStartupTools.get_os_name_with_lsb(partition=partition, mount_point=mount_point, is_current_os=is_current_os) #If we really have to, ask the user. if os_name is None: logger.warning("get_oss(): Asking user for OS name instead...") os_name = CoreStartupTools.ask_for_os_name(partition=partition, is_current_os=is_current_os) #Look for APT. package_manager = CoreStartupTools.determine_package_manager(apt_cmd=apt_cmd, dnf_cmd=dnf_cmd) #Also check if CoreStartupTools.ask_for_os_name was used to determine the name. #If the user skipped naming the OS, ignore it and skip the rest of this loop iteration. if os_name is not None and os_architecture is not None and package_manager != "Unknown": #Add this information to os_info. os_info[os_name] = {} os_info[os_name]["Name"] = os_name os_info[os_name]["IsCurrentOS"] = is_current_os os_info[os_name]["Arch"] = os_architecture os_info[os_name]["Partition"] = partition os_info[os_name]["PackageManager"] = package_manager os_info[os_name]["RawFSTabInfo"], os_info[os_name]["EFIPartition"], \ os_info[os_name]["BootPartition"] = \ CoreStartupTools.get_fstab_info(mount_point, os_name) if chroot is False: SYSTEM_INFO["CurrentOS"] = os_info[os_name].copy() if chroot: #unmount the filesystem. if CoreTools.unmount(mount_point) != 0: logger.error("get_oss(): Couldn't unmount "+partition + "! Doing emergency exit...") CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for " + "operating systems on it! Please reboot your " + "computer and try again.") #Check that at least one Linux OS was detected. linux_oss = [] #Get list of Linux OSs. for _os in os_info: if _os[0] not in ("Windows", "macOS"): linux_oss.append(os_name) if not linux_oss: logger.critical("get_oss(): No Linux installations found! If you do have Linux " + "installations but WxFixBoot hasn't found them, please file a bug or " + "ask a question on WxFixBoot's launchpad page. If you're using Windows " + "or macOS, then sorry as WxFixBoot has no support for these operating " + "systems. You could instead use the tools provided by Microsoft and " + "Apple to fix any issues with your computer. Exiting...") #Exit. CoreTools.emergency_exit("You don't appear to have any Linux installations on your hard " + "disks. If you do have Linux installations but WxFixBoot " + "hasn't found them, please file a bug or ask a question on " + "WxFixBoot's launchpad page. If you're using Windows or macOS, " + "then sorry as WxFixBoot has no support for these operating " + "systems. You could instead use the tools provided by Microsoft " + "and Apple to fix any issues with your computer.") #Otherwise... logger.debug("get_oss(): Done, os_info Populated okay. Contents: "+str(os_info)) return os_info, SYSTEM_INFO
def check_for_live_disk(): """Try to determine if we're running on a live disk.""" logger.info("MainStartupTools(): check_for_live_disk(): Attempting to check if we're on a " + "live disk...") #Detect Parted Magic automatically. if "pmagic" in CoreTools.start_process("uname -r", return_output=True)[1]: logger.info("MainStartupTools(): check_for_live_disk(): Running on Parted Magic...") SYSTEM_INFO["IsLiveDisk"] = True SYSTEM_INFO["OnPartedMagic"] = True #Try to detect ubuntu-based livecds. elif CoreTools.is_mounted("/cow", "/") and os.path.isfile("/cdrom/casper/filesystem.squashfs"): logger.info("MainStartupTools(): check_for_live_disk(): " + "Running on Ubuntu-based live disk...") SYSTEM_INFO["IsLiveDisk"] = True SYSTEM_INFO["OnPartedMagic"] = False #Try to detect fedora-based livecds. elif CoreTools.is_mounted("/dev/mapper/live-rw", "/") \ and os.path.isfile("/run/initramfs/live/LiveOS/squashfs.img"): logger.info("MainStartupTools(): check_for_live_disk(): " + "Running on Fedora-based live disk...") SYSTEM_INFO["IsLiveDisk"] = True SYSTEM_INFO["OnPartedMagic"] = False #Try to detect Disk Verifier/any other live disks. elif CoreTools.is_mounted("overlay", "/") \ or os.path.isfile("/run/live/medium/live/filesystem.squashfs"): logger.info("MainStartupTools(): check_for_live_disk(): " + "Running on live disk...") SYSTEM_INFO["IsLiveDisk"] = True SYSTEM_INFO["OnPartedMagic"] = False #Try to detect if we're not running on a live disk (on HDD/NVME). elif "/dev/sd" in CoreTools.get_partition_mounted_at("/") \ or "/dev/nvme" in CoreTools.get_partition_mounted_at("/"): logger.info("MainStartupTools(): check_for_live_disk(): Not running on live disk...") SYSTEM_INFO["IsLiveDisk"] = False SYSTEM_INFO["OnPartedMagic"] = False #Try to detect if we're not running on a live disk (on LVM). elif "/dev/mapper/" in CoreTools.get_partition_mounted_at("/"): logger.info("MainStartupTools(): check_for_live_disk(): Not running on live disk...") SYSTEM_INFO["IsLiveDisk"] = False SYSTEM_INFO["OnPartedMagic"] = False #Ask the user if we're running on a live disk. else: logger.info("MainStartupTools(): check_for_live_disk(): Asking the user if we're running " + "on live media...") SYSTEM_INFO["IsLiveDisk"] = DialogTools.show_yes_no_dlg(message="Is WxFixBoot being run " + "on live media, such as an " + "Ubuntu Installer Disk?", title="WxFixBoot - Live Media?") SYSTEM_INFO["OnPartedMagic"] = False logger.info("MainStartupTools(): check_for_live_disk(): Result: " + str(SYSTEM_INFO["IsLiveDisk"])) #Get current OS architecture. logger.info("MainStartupTools(): check_for_live_disk(): Getting architecture of current OS...") SYSTEM_INFO["CurrentOSArch"] = CoreStartupTools.determine_os_architecture(mount_point="")
def test_is_mounted2(self): #Unmount it. Functions.unmount_disk(self.path) self.assertFalse(CoreTools.is_mounted(self.path))
def find_checkable_file_systems(): """ Find all checkable filesystems, and then return them to EssentialBackendTools().filesystem_check() """ logger.info("find_checkable_file_systems(): Finding and returning all filesystems/partitions " + "that can be checked...") #Do setup. do_not_check_list = [] filesystems_to_check = {} root_fs = CoreTools.get_partition_mounted_at("/") #Get a list of missing fsck modules (if any) based on the existing filesystems. missing_fsck_modules = find_missing_fsck_modules() keys = list(DISK_INFO.keys()) keys.sort() #Determine checkable partitions. for disk in keys: #Ignore all devices. if DISK_INFO[disk]["Type"] == "Device": continue #Check if the required fsck module is present, and that the partition isn't root_fs if "fsck."+DISK_INFO[disk]["FileSystem"] in missing_fsck_modules: mount_point = "None" check_this_fs = False remount_fs_after = False reason = "filesystem checker was not found." elif SYSTEM_INFO["IsLiveDisk"] is False and disk == root_fs: #If we're not running on a live disk, skip the filesystem if it's the same as root_fs #(in which case checking it may corrupt data). mount_point = "/" check_this_fs = False remount_fs_after = False reason = "disk is busy." #Extra check for LVM disks using aliases. elif DISK_INFO[disk]["Product"] == "LVM Partition" and root_fs in DISK_INFO[disk]["Aliases"]: mount_point = "/" check_this_fs = False remount_fs_after = False reason = "disk is busy." else: #If filesystem is unknown, or not applicable (extended partitions), don't check it. if DISK_INFO[disk]["FileSystem"] in ("Unknown", "N/A"): mount_point = "None" check_this_fs = False remount_fs_after = False reason = "filesystem was not recognised." else: #Check if the partition is mounted. if CoreTools.is_mounted(disk) is False: mount_point = "None" check_this_fs = True remount_fs_after = False #Extra check for LVM disks using aliases. elif DISK_INFO[disk]["Product"] == "LVM Partition" and \ CoreTools.any_mounted(DISK_INFO[disk]["Aliases"]) is False: mount_point = "None" check_this_fs = True remount_fs_after = False else: #Unmount the FS temporarily, to avoid data corruption. mount_point = CoreTools.get_mount_point_of(disk) if CoreTools.unmount(disk) != 0: logger.warning("find_checkable_file_systems(): Failed to unmount "+disk +", which is necessary for safe disk checking! Ignoring it.") check_this_fs = False remount_fs_after = False reason = "disk is busy." else: check_this_fs = True remount_fs_after = True if check_this_fs: #Add it to the dictionary for checking. filesystems_to_check[disk] = {} filesystems_to_check[disk]["Remount"] = remount_fs_after filesystems_to_check[disk]["MountPoint"] = mount_point else: #Add it to the non-checkable list do_not_check_list.append(disk+", because the "+reason) #Report uncheckable partitions. if do_not_check_list != []: #Some filesystems will not be checked. Tell the user. DialogTools.show_msg_dlg(kind="info", message="The following filesystems will not be checked:\n\n" + '\n'.join(do_not_check_list)+"\n\nThe most likely reason for " + "this is that some of the filesystems are in use, or that the " + "required filesystem checkers weren't found. WxFixBoot will " + "now continue to check the remaining filesystems.") logger.info("find_checkable_file_systems(): Done! Filesystems that won't be checked: " + '\n'.join(do_not_check_list)+"...") return filesystems_to_check
def set_new_bootloader_config(_os): """Manage setting new bootloader config.""" logger.info("set_new_bootloader_config(): Setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "'s config for " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " config for " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 79) wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "'s config for " + _os + "...###\n") #If this is the current OS, let the config functions know that we aren't using chroot. if OS_INFO[_os]["IsCurrentOS"]: logger.debug( "set_new_bootloader_config(): We're modifying the current OS...") #If so, make sure this will work for this OS too, and avoid setting mountpoint, so the #config instructions below look in the right place for the config files. use_chroot, unmount_after, mount_point = (False, False, "") else: logger.debug( "set_new_bootloader_config(): We're modifying another OS...") use_chroot = True mount_point = "/mnt/wxfixboot/mountpoints" + OS_INFO[_os]["Partition"] #Check if the partition is mounted. unmount_after = not CoreTools.is_mounted(OS_INFO[_os]["Partition"], mount_point) if unmount_after: #Mount the partition. if CoreTools.mount_partition(partition=OS_INFO[_os]["Partition"], mount_point=mount_point) != 0: #Ignore this partition. logger.warning( "set_new_bootloader_config(): Failed to mount " + OS_INFO[_os]["Partition"] + "! Giving up...") return False #Set up chroot. if CoreTools.setup_chroot(mount_point=mount_point) != 0: logger.error( "set_new_bootloader_config(): Failed to set up chroot at " + mount_point + "! Giving up...") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to set up a chroot for " + _os + "! Giving up. You will be prompted to try again if " + "you wish.") return False wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 81) #Mount a /boot partition if it exists. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.mount_partition(OS_INFO[_os]["BootPartition"], mount_point + "/boot") != 0: logger.error( "set_new_bootloader_config(): Failed to mount " + _os + "'s /boot partition! Skipping bootloader config setting for this OS." ) if not OS_INFO[_os]["IsCurrentOS"]: CoreTools.teardown_chroot(mount_point) CoreTools.unmount(mount_point) return False #If there's a seperate EFI partition for this OS, make sure it's mounted. if OS_INFO[_os]["EFIPartition"] != "Unknown": if CoreTools.mount_partition( partition=OS_INFO[_os]["EFIPartition"], mount_point=mount_point + "/boot/efi") != 0: logger.error("remove_old_bootloader(): Failed to mount " + OS_INFO[_os]["EFIPartition"] + "! Warn the user and skip this OS.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount the partition containing " + _os + "'s EFI partition! Giving up. You will be prompted to " + "try again if you wish.") return False #On GRUB2, get the new menuentries so we can set the default OS. logger.info( "set_new_bootloader_config(): Reading GRUB2's menu entries to set default OS..." ) if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] in ("GRUB2", "GRUB-UEFI"): #Update GRUB. logger.info( "set_new_bootloader_config(): Updating GRUB2 Configuration...") BootloaderConfigSettingTools.update_grub2( _os=_os, package_manager=OS_INFO[_os]["PackageManager"], use_chroot=use_chroot, mount_point=mount_point) BOOTLOADER_INFO[_os]["NewMenuEntries"] = \ BootloaderConfigObtainingTools.parse_grub2_menu_data(menu_data="", mount_point=mount_point)[1] #Look for the configuration file, based on which SetConfig() function we're about to run. if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] in ("GRUB2", "GRUB-UEFI"): #Check mount_point/etc/default/grub exists. if os.path.isfile(mount_point + "/etc/default/grub"): #It does, we'll run the function to set the config now. logger.info( "set_new_bootloader_config(): Setting GRUB2 Configuration...") BootloaderConfigSettingTools.set_grub2_config( _os=_os, filetoopen=mount_point + "/etc/default/grub", bootloader_timeout=BOOTLOADER_INFO[_os]["Settings"] ["NewTimeout"], kernel_options=BOOTLOADER_INFO[_os]["Settings"] ["NewKernelOptions"], package_manager=OS_INFO[_os]["PackageManager"]) if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB-UEFI": #Mount the UEFI partition at mount_point/boot/efi. if CoreTools.mount_partition( partition=OS_INFO[_os]["EFIPartition"], mount_point=mount_point + "/boot/efi") != 0: logger.error( "set_new_bootloader_config(): Couldn't mount EFI partition " + OS_INFO[_os]["EFIPartition"] + " to install bootloader! Giving up " + "and warning user...") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount " + _os + "'s EFI partition! You will now be promtped to give " + "up or try again.") return False #Now Install GRUB-UEFI to the UEFI Partition. logger.info( "set_new_bootloader_config(): Installing GRUB-UEFI to " + OS_INFO[_os]["EFIPartition"] + "...") BootloaderConfigSettingTools.install_grub2_to_efi_partition( package_manager=OS_INFO[_os]["PackageManager"], mount_point=mount_point, use_chroot=use_chroot, uefi_system_partition_mount_point="/boot/efi", arch=OS_INFO[_os]["Arch"]) else: #Now Install GRUB2 to the MBR. logger.info("set_new_bootloader_config(): Installing GRUB2 to " + DISK_INFO[OS_INFO[_os]["Partition"]]["HostDevice"] + "...") BootloaderConfigSettingTools.install_grub2_to_mbr( package_manager=OS_INFO[_os]["PackageManager"], use_chroot=use_chroot, mount_point=mount_point, device=DISK_INFO[OS_INFO[_os]["Partition"]]["HostDevice"]) #Update GRUB. logger.info( "set_new_bootloader_config(): Updating GRUB2 Configuration...") BootloaderConfigSettingTools.update_grub2( _os=_os, package_manager=OS_INFO[_os]["PackageManager"], use_chroot=use_chroot, mount_point=mount_point) if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB-UEFI": #Make an entry in fstab for the UEFI Partition, if needed. HelperBackendTools.write_fstab_entry_for_uefi_partition( _os=_os, mount_point=mount_point) #Copy and backup EFI files where needed. HelperBackendTools.backup_uefi_files(mount_point=mount_point) HelperBackendTools.manage_uefi_files(_os=_os, mount_point=mount_point) if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB-UEFI" \ and OS_INFO[_os]["PackageManager"] == "dnf": #If we're switching to GRUB-UEFI from BIOS it can mess up GRUB2 and change the boot #commands to linux and initrd instead of linuxefi and initrdefi, preventing boot. #Fix this. The next time GRUB is updated from within the OS it will fix itself. logger.info( "set_new_bootloader_config(): Fixing Fedora's GRUB2-UEFI config (when " + "booted with BIOS, it can go wrong)...") logger.info( "set_new_bootloader_config(): Finding and opening GRUB config file..." ) #Find grub.cfg. (Ubuntu). if os.path.isdir(mount_point + "/boot/grub"): grub_dir = mount_point + "/boot/grub" #(Fedora, EFI) elif os.path.isdir(mount_point + "/boot/efi/EFI/fedora"): grub_dir = mount_point + "/boot/efi/EFI/fedora" #Correct the commands if needed. config = CoreTools.read_privileged_file(grub_dir + "/grub.cfg") new_config = [] for line in config: if "linux16" in line and "/vmlinu" in line: new_config.append( line.replace("linux16", "linuxefi") + "\n") elif "linux" in line and "linuxefi" not in line and "/vmlinu" in line: new_config.append(line.replace("linux", "linuxefi") + "\n") elif "initrd16" in line and ("/initrd" in line or "/initramfs" in line): new_config.append( line.replace("initrd16", "initrdefi") + "\n") elif "initrd" in line and "initrdefi" not in line \ and ("/initrd" in line or "/initramfs" in line): new_config.append( line.replace("initrd", "initrdefi") + "\n") else: new_config.append(line + "\n") #Write the fixed config. CoreTools.write_privileged_file(grub_dir + "/grub.cfg", ''.join(new_config)) #unmount the EFI partition. if CoreTools.unmount(OS_INFO[_os]["EFIPartition"]) != 0: logger.error( "set_new_bootloader_config(): Couldn't unmount EFI partition! " + "This probably won't matter, so we'll continue anyway...") logger.info("set_new_bootloader_config(): Done!") elif BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB2" \ and OS_INFO[_os]["PackageManager"] == "dnf": #If we're switching to GRUB2 from UEFI it can mess up GRUB2 and change the boot #commands to linuxefi and initrdefi instead of linux and initrd, preventing boot. #Fix this. The next time GRUB is updated from within the OS it will fix itself. logger.info( "set_new_bootloader_config(): Fixing Fedora's GRUB2-BIOS config (when " + "booted with EFI, it can go wrong)...") logger.info( "set_new_bootloader_config(): Finding and opening GRUB config file..." ) #Find grub.cfg. (Ubuntu). if os.path.isdir(mount_point + "/boot/grub"): grub_dir = mount_point + "/boot/grub" #(Fedora, BIOS) elif os.path.isdir(mount_point + "/boot/grub2"): grub_dir = mount_point + "/boot/grub2" #Correct the commands if needed. config = CoreTools.read_privileged_file(grub_dir + "/grub.cfg") new_config = [] for line in config: new_config.append(line.replace("linuxefi", "linux")\ .replace("initrdefi", "initrd")+"\n") #Write the fixed config. CoreTools.write_privileged_file(grub_dir + "/grub.cfg", ''.join(new_config)) logger.info("set_new_bootloader_config(): Done!") #If there's a seperate EFI partition for this OS, make sure it's unmounted before #removing the chroot. if OS_INFO[_os]["EFIPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot/efi") != 0: logger.error("set_new_bootloader_config(): Failed to unmount " + mount_point + "/boot/efi! This probably doesn't matter...") #unmount a /boot partition if it exists. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot") != 0: logger.error("set_new_bootloader_config(): Failed to unmount " + _os + "'s /boot partition! Continuing anyway...") #Tear down chroot if needed. if use_chroot: if CoreTools.teardown_chroot(mount_point=mount_point) != 0: logger.error( "set_new_bootloader_config(): Failed to remove chroot at " + mount_point + "! Attempting to continue anyway...") #unmount the partition if needed. if unmount_after: if CoreTools.unmount(mount_point) != 0: logger.error("set_new_bootloader_config(): Failed to unmount " + mount_point + "! Continuing anyway...") #Attempt to clear any stuck logical volumes that may have been created by os-prober. CoreTools.start_process("dmsetup remove_all -y", privileged=True) #Make sure any LVM volume groups are active. for disk in DISK_INFO: if "VGName" in DISK_INFO[disk]: CoreTools.start_process("vgchange -a y " + DISK_INFO[disk]["VGName"], privileged=True) logger.debug("set_new_bootloader_config(): Finished setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "'s config for " + _os + "...") wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Finished setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "'s config for " + _os + "...###\n") wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Finished setting " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "'s config for " + _os + "!") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 100) return True
def install_new_bootloader(_os): """Install a new bootloader.""" logger.info("install_new_bootloader(): Preparing to install " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 52) wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Preparing to install " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...###\n") wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Preparing to install " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...") #If this is the current OS, let the installer functions know that we aren't using chroot. if OS_INFO[_os]["IsCurrentOS"]: logger.debug( "install_new_bootloader(): Modifying current OS so not using chroot..." ) use_chroot, unmount_after, mount_point = (False, False, "") #Otherwise, setup the chroot and everything else first, and tell them we are using chroot, #and pass the mountpoint to them. else: logger.debug( "install_new_bootloader(): Using chroot to modify another OS...") use_chroot = True mount_point = "/mnt/wxfixboot/mountpoints" + OS_INFO[_os]["Partition"] #Check if the partition is mounted. unmount_after = not CoreTools.is_mounted(OS_INFO[_os]["Partition"], mount_point) if unmount_after: if CoreTools.mount_partition(partition=OS_INFO[_os]["Partition"], mount_point=mount_point) != 0: logger.error("install_new_bootloader(): Failed to mount " + OS_INFO[_os]["Partition"] + "! Warn the user and skip this OS.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount the partition " + "containing " + _os + "! Bootloader installation cannot " + "continue! This may leave your system, or this OS, in " + "an unbootable state. Please close any open programs, " + "then try again when prompted.") return False #Set up chroot. if CoreTools.setup_chroot(mount_point=mount_point) != 0: logger.error( "install_new_bootloader(): Failed to set up chroot at " + mount_point + "! Warning user and giving up...") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to set up a chroot for " + _os + "! Giving up. You will be prompted to try again if " + "you wish.") return False #If there's a seperate /boot partition for this OS, make sure it's mounted. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.mount_partition(partition=OS_INFO[_os]["BootPartition"], mount_point=mount_point + "/boot") != 0: logger.error("remove_old_bootloader(): Failed to mount " + OS_INFO[_os]["BootPartition"] + "! Warn the user and skip this OS.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount the partition " + "containing " + _os + "'s /boot partition! Giving up. " + "You will be prompted to try again if you wish.") return False #Update the package lists. if OS_INFO[_os]["PackageManager"] == "apt-get": cmd = "sh -c 'DEBIAN_FRONTEND=gnome DISPLAY=:0 apt-get update'" elif OS_INFO[_os]["PackageManager"] == "dnf": cmd = "dnf check-update" if use_chroot: cmd = "chroot " + mount_point + " " + cmd if CoreTools.start_process(cmd, privileged=True) not in (0, 100): logger.error( "install_new_bootloader(): Failed to Update the Package Information! " + "Continuing anyway...") DialogTools.show_msg_dlg( kind="error", message="WxfixBoot failed to update " + _os + "'s package information! Giving up. You will be prompted " + "to try again if you wish.") return False wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Installing " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 55) wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Installing " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...###\n") #Make sure all GNOME APT frontend dependency is installed. if OS_INFO[_os]["PackageManager"] == "apt-get": #Ubuntu 16.04. cmd = "sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y libgnome2-perl'" if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) #All newer versions. cmd = "sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y libgtk3-perl'" if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) #Install the bootloader. if BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB2": logger.info("install_new_bootloader(): Installing GRUB2...") if OS_INFO[_os]["PackageManager"] == "apt-get": cmd = "sh -c 'DEBIAN_FRONTEND=gnome DISPLAY=:0 apt-get install -y grub-pc os-prober'" elif OS_INFO[_os]["PackageManager"] == "dnf": cmd = "dnf -y install grub2" elif BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] == "GRUB-UEFI": logger.info("install_new_bootloader(): Installing GRUB-UEFI...") #Mount the UEFI partition at mount_point/boot/efi. if CoreTools.mount_partition( partition=OS_INFO[_os]["EFIPartition"], mount_point=mount_point + "/boot/efi") != 0: logger.error("install_new_bootloader(): Failed to mount " + OS_INFO[_os]["EFIPartition"] + " to " + mount_point + "/boot/efi! Aborting bootloader installation and " + "warning user...") DialogTools.show_msg_dlg( kind="error", message="WxfixBoot failed to mount the partition containing " + _os + "'s EFI partition! Giving up. You will be prompted to " + "try again if you wish.") return False if OS_INFO[_os]["PackageManager"] == "apt-get": cmd = "sh -c 'DEBIAN_FRONTEND=gnome DISPLAY=:0 apt-get install -y grub-efi os-prober'" elif OS_INFO[_os]["PackageManager"] == "dnf": cmd = "dnf -y install grub2-efi-ia32 grub2-efi-x64 shim-x64 " if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) if retval != 0: logger.error( "install_new_bootloader(): Failed to install new bootloader. Warn user..." ) DialogTools.show_msg_dlg(kind="error", message="WxfixBoot failed to install " + _os + "'s new bootloader! Continuing anyway...") #If there's a seperate EFI partition for this OS, make sure it's unmounted before removing #the chroot. if OS_INFO[_os]["EFIPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot/efi") != 0: logger.error("install_new_bootloader(): Failed to unmount " + mount_point + "/boot/efi! This probably doesn't matter...") #If there's a seperate /boot partition for this OS, make sure it's unmounted before #removing the chroot. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot") != 0: logger.error("install_new_bootloader(): Failed to unmount " + mount_point + "/boot! This probably doesn't matter...") if use_chroot: logger.debug("install_new_bootloader(): Removing chroot...") #Tear down chroot. if CoreTools.teardown_chroot(mount_point=mount_point) != 0: logger.error( "install_new_bootloader(): Failed to remove chroot at " + mount_point + "! Attempting to continue anyway...") if unmount_after: if CoreTools.unmount(mount_point) != 0: logger.error("install_new_bootloader(): Failed to unmount " + mount_point + "! Continuing anyway...") if retval != 0: #Something went wrong! Log it and notify the user. logger.error( "install_new_bootloader(): Failed to install " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "! This may mean the system (or this OS) is now unbootable! " + "Warning the user and asking to try again.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to install " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "! This may leave this OS, or your system, in an unbootable " + "state. You will now be prompted to try again.") return False wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Finished installing " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...###\n") #Attempt to clear any stuck logical volumes that may have been created by os-prober. CoreTools.start_process("dmsetup remove_all -y", privileged=True) #Make sure any LVM volume groups are active. for disk in DISK_INFO: if "VGName" in DISK_INFO[disk]: CoreTools.start_process("vgchange -a y " + DISK_INFO[disk]["VGName"], privileged=True) #Log and notify the user that we're finished installing the bootloader. logger.info("install_new_bootloader(): Finished installing " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Finish installing " + BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] + " in " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 75) return True
def remove_old_bootloader(_os): """Remove the currently installed bootloader.""" logger.info("remove_old_bootloader(): Removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 27) wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "......") wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "...###\n") #If this is the current OS, let the remover function know that we aren't using chroot. if OS_INFO[_os]["IsCurrentOS"]: logger.debug( "remove_old_bootloader(): Modifying current OS so not using chroot..." ) use_chroot, unmount_after, mount_point = (False, False, "") else: logger.debug( "remove_old_bootloader(): Using chroot to modify another OS...") use_chroot = True mount_point = "/mnt/wxfixboot/mountpoints" + OS_INFO[_os]["Partition"] #Check if the partition is mounted. unmount_after = not CoreTools.is_mounted(OS_INFO[_os]["Partition"], mount_point) if unmount_after: #Mount the partition using the global mount function. if CoreTools.mount_partition(partition=OS_INFO[_os]["Partition"], mount_point=mount_point) != 0: logger.error("remove_old_bootloader(): Failed to mount " + OS_INFO[_os]["Partition"] + "! Warning the user and giving up...") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount the partition " + "containing " + _os + "! Giving up. You will be prompted " + "to try again if you wish.") return False #Set up chroot. if CoreTools.setup_chroot(mount_point) != 0: logger.error( "remove_old_bootloader(): Failed to set up chroot at " + mount_point + "! Giving up...") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to set up a chroot for " + _os + "! Giving up. You will be prompted to try again if " + "you wish.") return False #Mount a /boot partition if it exists. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.mount_partition(OS_INFO[_os]["BootPartition"], mount_point + "/boot") != 0: logger.error("remove_old_bootloader(): Failed to mount " + _os + "'s /boot partition! " + "Skipping bootloader removal for this OS.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to mount the partition containing " + _os + "'s /boot partition! Giving up. You will be prompted " + "to try again if you wish.") if not OS_INFO[_os]["IsCurrentOS"]: CoreTools.teardown_chroot(mount_point) CoreTools.unmount(mount_point) return False #Mount the UEFI partition at mount_point/boot/efi, if it exists. if OS_INFO[_os]["EFIPartition"] != "Unknown": if CoreTools.mount_partition( partition=OS_INFO[_os]["EFIPartition"], mount_point=mount_point + "/boot/efi") != 0: logger.error("remove_old_bootloader(): Failed to mount " + OS_INFO[_os]["EFIPartition"] + "! to " + mount_point + "/boot/efi! Aborting bootloader installation and " + "warning user...") DialogTools.show_msg_dlg( kind="error", message="WxfixBoot failed to mount the partition containing " + _os + "'s EFI partition! Giving up. You will be prompted to " + "try again if you wish.") return False #Wait until no other application is using APT/DNF. #Let user know what's happening. wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 27) wx.CallAfter( wx.GetApp().TopWindow.update_current_operation_text, message="Waiting until " + _os + "'s package manager is free.\nClose any open applications if this " + "message persists...") wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Waiting until " + _os + "'s package manager is free...###\n") logger.debug("remove_old_bootloader(): Waiting until " + _os + "'s package manager is free...") HelperBackendTools.wait_until_packagemanager_free(mount_point=mount_point, package_manager=\ OS_INFO[_os]["PackageManager"]) wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 27) wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "...") wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "...###\n") #Make sure the GNOME APT frontend dependency is installed. if OS_INFO[_os]["PackageManager"] == "apt-get": #Ubuntu 16.04. cmd = "sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y libgnome2-perl'" if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) #All newer versions. cmd = "sh -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y libgtk3-perl'" if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) #Remove the bootloader. if BOOTLOADER_INFO[_os]["Bootloader"] == "GRUB2": logger.info("remove_old_bootloader(): Removing GRUB2...") if OS_INFO[_os]["PackageManager"] == "apt-get": cmd = "sh -c 'DEBIAN_FRONTEND=gnome DISPLAY=:0 apt-get purge -y " \ "--allow-remove-essential grub-pc grub-pc-bin grub-common'" elif OS_INFO[_os]["PackageManager"] == "dnf": cmd = "dnf -y remove grub2" elif BOOTLOADER_INFO[_os]["Bootloader"] == "GRUB-UEFI": logger.info("remove_old_bootloader(): Removing GRUB-UEFI...") if OS_INFO[_os]["PackageManager"] == "apt-get": cmd = "sh -c 'DEBIAN_FRONTEND=gnome DISPLAY=:0 apt-get purge -y " \ "--allow-remove-essential grub-efi grub-efi-amd64 grub-efi-amd64-bin" \ " grub-efi-ia32 grub-efi-ia32-bin grub-common grub2-common'" elif OS_INFO[_os]["PackageManager"] == "dnf": cmd = "dnf -y remove grub2-efi-x64 grub2-efi-ia32 shim-x64" else: #Bootloader is unknown. Just output a warning message. logger.warning( "remove_old_bootloader(): Cannot remove unknown bootloader! " + "Continuing anyway...") cmd = "echo 'WARNING: Bootloader is " \ "unknown, cannot remove. Continuing anyway...'" if use_chroot: cmd = "chroot " + mount_point + " " + cmd retval = CoreTools.start_process(cmd, privileged=True) if retval != 0: logger.error("remove_old_bootloader(): Failed to remove " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "! Warning user...") DialogTools.show_msg_dlg(kind="error", message="WxFixBoot failed to remove " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "!") return False #If there's a seperate EFI partition for this OS, make sure it's unmounted before removing #the chroot. if OS_INFO[_os]["EFIPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot/efi") != 0: logger.error("remove_old_bootloader(): Failed to unmount " + mount_point + "/boot/efi! This probably doesn't matter...") #unmount a /boot partition if it exists. if OS_INFO[_os]["BootPartition"] != "Unknown": if CoreTools.unmount(mount_point + "/boot") != 0: logger.error("remove_old_bootloader(): Failed to unmount " + _os + "'s /boot partition! Continuing anyway...") #Tear down chroot if needed. if use_chroot: if CoreTools.teardown_chroot(mount_point=mount_point) != 0: logger.error( "remove_old_bootloader(): Failed to remove chroot at " + mount_point + "! Attempting to continue anyway...") #unmount partition if needed. if unmount_after: if CoreTools.unmount(mount_point) != 0: logger.error("remove_old_bootloader(): Couldn't unmount " + mount_point + "! Continuing anyway...") wx.CallAfter( wx.GetApp().TopWindow.update_output_box, "\n###Finished removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "...###\n") if retval != 0: #Something went wrong! Log it and notify the user. logger.error("remove_old_bootloader(): Failed to remove " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "! We'll continue anyway. Warn the user.") DialogTools.show_msg_dlg( kind="error", message="WxFixBoot failed to remove " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "! This probably doesn't matter; when we install the new " + "bootloader, it should take precedence over the old one " + "anyway. Make sure you check that " + _os + " boots correctly " + "after WxFixBoot finishes its operations. Reinstalling the " + "bootloader again afterwards is recommended.") #Attempt to clear any stuck logical volumes that may have been created by os-prober. CoreTools.start_process("dmsetup remove_all -y", privileged=True) #Make sure any LVM volume groups are active. for disk in DISK_INFO: if "VGName" in DISK_INFO[disk]: CoreTools.start_process("vgchange -a y " + DISK_INFO[disk]["VGName"], privileged=True) #Log and notify the user that we're finished removing bootloaders. logger.info("remove_old_bootloader(): Finished removing " + BOOTLOADER_INFO[_os]["Bootloader"] + "...") wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text, message="Finished removing " + BOOTLOADER_INFO[_os]["Bootloader"] + " from " + _os + "......") wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 50) return True
def get_oss(): """Get the names of all OSs on the HDDs.""" root_fs = CoreTools.get_partition_mounted_at("/") #Get Linux OSs. keys = list(DISK_INFO.keys()) keys.sort() for partition in keys: if DISK_INFO[partition]["Type"] == "Device": continue elif DISK_INFO[partition]["FileSystem"] in ("hfsplus", "hfs", "apfs"): #Look for Mac OS X. os_name = "Mac OS X ("+partition+")" #Check if we need to mount the partition. was_mounted = False if CoreTools.is_mounted(partition): #If mounted, get the mountpoint. mount_point = CoreTools.get_mount_point_of(partition) else: #Mount the partition and check if anything went wrong. mount_point = "/mnt/wxfixboot/mountpoints"+partition if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. continue was_mounted = True if os.path.exists(mount_point+"/mach_kernel") or os.path.exists(mount_point+"/System/Library/Kernels/kernel"): #Create OS_INFO entry for it. OS_INFO[os_name] = {} OS_INFO[os_name]["Name"] = os_name OS_INFO[os_name]["IsCurrentOS"] = False OS_INFO[os_name]["Arch"] = "Unknown" OS_INFO[os_name]["Partition"] = partition OS_INFO[os_name]["PackageManager"] = "Mac App Store" OS_INFO[os_name]["RawFSTabInfo"], OS_INFO[os_name]["EFIPartition"], OS_INFO[os_name]["BootPartition"] = (["Unknown"], "Unknown", "Unknown") #Unmount the filesystem if needed. if was_mounted: if CoreTools.unmount(mount_point) != 0: break #CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for" # + "operating systems on it! Please reboot your " # + "computer and try again.") elif DISK_INFO[partition]["FileSystem"] in ("vfat", "ntfs", "exfat"): #Look for Windows. NOTE: It seems NTFS volumes can't be mounted twice, which is why #we're being more careful here. #Check if we need to mount the partition. was_mounted = False if CoreTools.is_mounted(partition): #If mounted, get the mountpoint. mount_point = CoreTools.get_mount_point_of(partition) else: #Mount the partition and check if anything went wrong. mount_point = "/mnt/wxfixboot/mountpoints"+partition if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. continue was_mounted = True #Check if there's a Windows/WinNT dir. if not (os.path.isdir(mount_point+"/WinNT") or os.path.isdir(mount_point+"/Windows") or os.path.isdir(mount_point+"/WINDOWS")): #Skip this partition, and unmount if needed. pass else: #Look for lots of different Windows editions. if CoreStartupTools.has_windows_9x(mount_point): os_name = "Windows 95/98/ME" elif CoreStartupTools.has_windows_xp(mount_point): os_name = "Windows XP" elif CoreStartupTools.has_windows_vista(mount_point): os_name = "Windows Vista" elif CoreStartupTools.has_windows_7(mount_point): os_name = "Windows 7" elif CoreStartupTools.has_windows_8(mount_point): os_name = "Windows 8/8.1" elif CoreStartupTools.has_windows_10(mount_point): os_name = "Windows 10" else: #Unknown Windows. os_name = "Windows" #Create OS_INFO entry for it. os_name = os_name+" ("+partition+")" OS_INFO[os_name] = {} OS_INFO[os_name]["Name"] = os_name OS_INFO[os_name]["IsCurrentOS"] = False OS_INFO[os_name]["Arch"] = "Unknown" OS_INFO[os_name]["Partition"] = partition OS_INFO[os_name]["PackageManager"] = "Windows Installer" OS_INFO[os_name]["RawFSTabInfo"], OS_INFO[os_name]["EFIPartition"], OS_INFO[os_name]["BootPartition"] = (["Unknown"], "Unknown", "Unknown") #Unmount the filesystem if needed. if was_mounted: if CoreTools.unmount(mount_point) != 0: break #CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for" # + "operating systems on it! Please reboot your " # + "computer and try again.") else: #Look for Linux. #The python command runs on python 2 and python 3. #If there are aliases for partition, check if the root FS is one of those too. root_fs_is_alias = False if "Aliases" in DISK_INFO[partition]: root_fs_is_alias = (root_fs in DISK_INFO[partition]["Aliases"]) if partition == root_fs or root_fs_is_alias: cmd = "python -c \"from __future__ import print_function; import platform; print(' '.join(platform.linux_distribution()));\"" apt_cmd = "which apt-get" dnf_cmd = "which dnf" chroot = False is_current_os = True mount_point = "" else: mount_point = "/mnt/wxfixboot/mountpoints"+partition cmd = "chroot "+mount_point+" python -c \"from __future__ import print_function; import platform; print(' '.join(platform.linux_distribution()));\"" apt_cmd = "chroot "+mount_point+" which apt-get" dnf_cmd = "chroot "+mount_point+" which dnf" chroot = True is_current_os = False #Mount the partition and check if anything went wrong. if CoreTools.mount_partition(partition=partition, mount_point=mount_point) != 0: #Ignore the partition. continue #Look for Linux on this partition. retval, temp = CoreTools.start_process(cmd, return_output=True) os_name = temp.replace('\n', '') #Run the function to get the architechure. os_arch = CoreStartupTools.determine_os_architecture(mount_point=mount_point) #If the OS's name wasn't found, but its architecture was, there must be an OS here, #so try to use lsb_release if possible before asking the user. Catch if the name is #just whitespace too. if (retval != 0 or os_name == "" or os_name.isspace()) and os_arch != None: os_name = CoreStartupTools.get_os_name_with_lsb(partition=partition, mount_point=mount_point, is_current_os=is_current_os) #If we really have to, ask the user. if os_name is None: os_name = CoreStartupTools.ask_for_os_name(partition=partition, is_current_os=is_current_os) #Look for APT. package_manager = CoreStartupTools.determine_package_manager(apt_cmd=apt_cmd, dnf_cmd=dnf_cmd) #Also check if CoreStartupTools.ask_for_os_name was used to determine the name. #If the user skipped naming the OS, ignore it and skip the rest of this loop iteration. if os_name != None and os_arch != None and package_manager != "Unknown": #Add this information to OS_INFO. OS_INFO[os_name] = {} OS_INFO[os_name]["Name"] = os_name OS_INFO[os_name]["IsCurrentOS"] = is_current_os OS_INFO[os_name]["Arch"] = os_arch OS_INFO[os_name]["Partition"] = partition OS_INFO[os_name]["PackageManager"] = package_manager OS_INFO[os_name]["RawFSTabInfo"], OS_INFO[os_name]["EFIPartition"], OS_INFO[os_name]["BootPartition"] = CoreStartupTools.get_fstab_info(mount_point, os_name) if chroot is False: SYSTEM_INFO["CurrentOS"] = OS_INFO[os_name].copy() if chroot: #Unmount the filesystem. if CoreTools.unmount(mount_point) != 0: break #CoreTools.emergency_exit("Couldn't unmount "+partition+" after looking for" # + "operating systems on it! Please reboot your " # + "computer and try again.") #Remove the temporary mountpoint os.rmdir(mount_point) #Check that at least one OS was detected. if len(OS_INFO) >= 1: return OS_INFO, SYSTEM_INFO #Otherwise... return (False, False)