Esempio n. 1
0
    def test_mount_partition3(self):
        #Get another device path from the user to test against.
        DialogFunctionsForTests.show_text_entry_dlg(
            "WxFixBoot needs a second (different) " +
            "partition name to test against.\nNo " +
            "data on your device will be modified. " +
            "Suggested: insert a USB disk and leave " +
            "it mounted.\nNote: Do not use your device " +
            "while these tests are running, or it may " +
            "interfere with the tests.", "WxFixBoot - Tests")

        self.path2 = DialogFunctionsForTests.TEXT_ENTRY_DLG_RESULTS[-1]

        #Unmount both partitions.
        for partition in [self.path, self.path2]:
            Functions.unmount_disk(partition)

        #Mount the 2nd one on the desired path for the 1st one.
        CoreTools.mount_partition(self.path2, self.mount_point)

        #Now try to mount the first one there.
        CoreTools.mount_partition(self.path, self.mount_point)

        #Now the 2nd should have been unmounted to get it out of the way, and the 1st
        #should be there.
        self.assertFalse(Functions.is_mounted(self.path2, self.mount_point))
        self.assertTrue(Functions.is_mounted(self.path, self.mount_point))

        Functions.unmount_disk(self.path)

        #Clean up.
        del self.path2
Esempio n. 2
0
    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))
Esempio n. 3
0
    def test_mount_partition4(self):
        #Unmount partition.
        Functions.unmount_disk(self.path)

        #Try to mount in subdir of usual mount point.
        CoreTools.mount_partition(self.path, self.mount_point + "/subdir")

        #Check is mounted.
        self.assertTrue(
            Functions.is_mounted(self.path, self.mount_point + "/subdir"))

        #Unmount.
        Functions.unmount_disk(self.path)

        #Clean up.
        if os.path.isdir(self.mount_point + "/subdir"):
            os.rmdir(self.mount_point + "/subdir")
Esempio n. 4
0
    def test_mount_partition2(self):
        #Unmount disk.
        Functions.unmount_disk(self.path)

        self.assertEqual(
            CoreTools.mount_partition(self.path, self.mount_point), 0)

        Functions.unmount_disk(self.path)
Esempio n. 5
0
    def test_mount_partition1(self):
        Functions.mount_partition(self.path, self.mount_point)

        #partition should be mounted, so we should pass this without doing anything.
        self.assertEqual(
            CoreTools.mount_partition(self.path, self.mount_point), 0)

        Functions.unmount_disk(self.path)
Esempio n. 6
0
def get_bootloaders():
    """
    Find all bootloaders (for each OS), and gather some information about them
    """

    SYSTEM_INFO["ModifyableOSs"] = []

    keys = list(OS_INFO.keys())
    keys.sort()

    for _os in keys:
        #If this is a windows OS, create a standard entry.
        if "Windows" in _os:
            CoreStartupTools.make_bootloaderinfo_entry_for_windows(_os)
            continue

        #Same for macOS.
        elif "macOS" in _os:
            CoreStartupTools.make_bootloaderinfo_entry_for_macos(_os)
            continue

        #If this isn't the current OS, do some preparation.
        if not OS_INFO[_os]["IsCurrentOS"]:
            #Mount the OS's partition.
            mount_point = "/mnt/wxfixboot/mountpoints"+OS_INFO[_os]["Partition"]

            if CoreTools.mount_partition(OS_INFO[_os]["Partition"], mount_point) != 0:
                logger.error("get_bootloaders(): Failed to mount "+_os+"'s partition! Skipping "
                             + "bootloader detection for this OS.")

                continue

            #Set up chroot.
            if CoreTools.setup_chroot(mount_point) != 0:
                logger.error("get_bootloaders(): Couldn't set up chroot on "+mount_point
                             + "! Attempting to remove it in case it's partially set up, "
                             + "and then skipping this OS...")

                CoreTools.teardown_chroot(mount_point)
                continue

        else:
            mount_point = ""

        #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("get_bootloaders(): Failed to mount "+_os+"'s /boot partition! "
                             + "Skipping bootloader detection for this OS.")

                if not OS_INFO[_os]["IsCurrentOS"]:
                    CoreTools.teardown_chroot(mount_point)
                    CoreTools.unmount(mount_point)

                continue

        #Mount a /boot/efi partition if it exists.
        if OS_INFO[_os]["EFIPartition"] != "Unknown":
            if CoreTools.mount_partition(OS_INFO[_os]["EFIPartition"],
                                         mount_point+"/boot/efi") != 0:

                logger.error("get_bootloaders(): Failed to mount "+_os+"'s /boot/efi partition! "
                             + "Skipping bootloader detection for this OS.")

                if not OS_INFO[_os]["IsCurrentOS"]:
                    CoreTools.teardown_chroot(mount_point)
                    CoreTools.unmount(mount_point)

                continue

        #Look for bootloaders.
        BOOTLOADER_INFO[_os] = {}
        BOOTLOADER_INFO[_os]["OSName"] = _os
        BOOTLOADER_INFO[_os]["Bootloader"], BOOTLOADER_INFO[_os]["AvailableBootloaders"] = \
        CoreStartupTools.look_for_bootloaders_on_partition(_os, OS_INFO[_os]["PackageManager"],
                                                           mount_point,
                                                           not OS_INFO[_os]["IsCurrentOS"])

        BOOTLOADER_INFO[_os]["Timeout"], BOOTLOADER_INFO[_os]["GlobalKernelOptions"], \
        BOOTLOADER_INFO[_os]["BootDisk"], BOOTLOADER_INFO[_os]["BLSpecificDefaultOS"], \
        BOOTLOADER_INFO[_os]["DefaultOS"] = (10, "Unknown", "Unknown", "Unknown", "Unknown")

        BOOTLOADER_INFO[_os]["MenuEntries"] = {_os: {}}

        #For EFI bootloaders, set the boot disk to the OS's EFI Partition.
        if BOOTLOADER_INFO[_os]["Bootloader"] == "GRUB-UEFI":
            BOOTLOADER_INFO[_os]["BootDisk"] = OS_INFO[_os]["EFIPartition"]

        if BOOTLOADER_INFO[_os]["Bootloader"] in ("GRUB-UEFI", "GRUB2") \
            and os.path.isfile(mount_point+"/etc/default/grub"):

            grub_dir, BOOTLOADER_INFO[_os]["MenuEntries"] = \
            BootloaderConfigObtainingTools.parse_grub2_menu_data(menu_data="",
                                                                 mount_point=mount_point)[0:2]

            #Get GRUB2's config.
            #If we're using fedora, always look for grubenv in the EFI partition (the grubenv
            #symlink is in /boot/grub2 but it doesn't work when we're chrooting).
            if OS_INFO[_os]["PackageManager"] == "dnf":
                grub_dir = mount_point+"/boot/efi/EFI/fedora"

            BOOTLOADER_INFO[_os]["Timeout"], BOOTLOADER_INFO[_os]["GlobalKernelOptions"], \
            BOOTLOADER_INFO[_os]["BLSpecificDefaultOS"] = \
            BootloaderConfigObtainingTools.get_grub2_config(mount_point+"/etc/default/grub",
                                                            grub_dir+"/grubenv",
                                                            BOOTLOADER_INFO[_os]["MenuEntries"])

            #Try to find GRUB's location if this is GRUB2.
            if BOOTLOADER_INFO[_os]["Bootloader"] == "GRUB2":
                BOOTLOADER_INFO[_os]["BootDisk"] = \
                BootloaderConfigObtainingTools.find_grub(OS_INFO[_os]["Partition"], "GRUB2")

        #If we didn't find the kernel options, set some defaults here, and warn the user.
        if BOOTLOADER_INFO[_os]["GlobalKernelOptions"] == "Unknown":
            BOOTLOADER_INFO[_os]["GlobalKernelOptions"] = "quiet splash nomodeset"
            logger.warning("get_bootloaders(): Couldn't find "+_os+"'s global kernel options! "
                           + "Assuming 'quiet splash nomodeset'...")

            DialogTools.show_msg_dlg(message="Couldn't find "+_os+"'s default kernel options! "
                                     + "Loading safe defaults instead. Click okay to continue.",
                                     kind="warning")

        #If we didn't find the timeout, set it to 10 seconds here, and warn the user.
        if BOOTLOADER_INFO[_os]["Timeout"] == "Unknown":
            BOOTLOADER_INFO[_os]["Timeout"] = 10
            logger.warning("get_bootloaders(): Couldn't find "+_os+"'s bootloader timeout! "
                           + "Assuming 10 seconds...")

            DialogTools.show_msg_dlg(message="Couldn't find "+_os+"'s bootloader timeout! "
                                     + "Loading safe defaults instead. Click okay to continue.",
                                     kind="warning")

        #Determine if we can modify this OS from our current one.
        if OS_INFO[_os]["Arch"] == SYSTEM_INFO["CurrentOSArch"] \
            or (OS_INFO[_os]["Arch"] == "i386" and SYSTEM_INFO["CurrentOSArch"] == "x86_64"):

            BOOTLOADER_INFO[_os]["IsModifyable"] = True
            BOOTLOADER_INFO[_os]["Comments"] = "Architecture is "+OS_INFO[_os]["Arch"]+"."
            SYSTEM_INFO["ModifyableOSs"].append(_os)

        else:
            BOOTLOADER_INFO[_os]["IsModifyable"] = False
            BOOTLOADER_INFO[_os]["Comments"] = "Architecture is "+OS_INFO[_os]["Arch"] \
                                               + ". Not modifyable because current OS is " \
                                               + SYSTEM_INFO["CurrentOSArch"]+"."

        #Initialise some default no-action settings.
        BOOTLOADER_INFO[_os]["Settings"] = {}
        BOOTLOADER_INFO[_os]["Settings"]["Reinstall"] = False
        BOOTLOADER_INFO[_os]["Settings"]["Update"] = False
        BOOTLOADER_INFO[_os]["Settings"]["KeepExistingTimeout"] = False
        BOOTLOADER_INFO[_os]["Settings"]["KeepExistingKernelOptions"] = False
        BOOTLOADER_INFO[_os]["Settings"]["NewKernelOptions"] = \
        BOOTLOADER_INFO[_os]["GlobalKernelOptions"]

        BOOTLOADER_INFO[_os]["Settings"]["NewTimeout"] = BOOTLOADER_INFO[_os]["Timeout"]
        BOOTLOADER_INFO[_os]["Settings"]["DefaultOS"] = BOOTLOADER_INFO[_os]["DefaultOS"]
        BOOTLOADER_INFO[_os]["Settings"]["InstallNewBootloader"] = False
        BOOTLOADER_INFO[_os]["Settings"]["NewBootloader"] = "-- Please Select --"
        BOOTLOADER_INFO[_os]["Settings"]["BackupBootloader"] = False
        BOOTLOADER_INFO[_os]["Settings"]["BootloaderBackupTarget"] = "-- Please Select --"
        BOOTLOADER_INFO[_os]["Settings"]["RestoreBootloader"] = False
        BOOTLOADER_INFO[_os]["Settings"]["BootloaderRestoreSource"] = "-- Please Select --"
        BOOTLOADER_INFO[_os]["Settings"]["ChangeThisOS"] = False

        #Initialise GUI state for this OS (True = Enabled, False = Disabled).
        BOOTLOADER_INFO[_os]["GUIState"] = {}
        BOOTLOADER_INFO[_os]["GUIState"]["ReinstallCheckBoxState"] = True
        BOOTLOADER_INFO[_os]["GUIState"]["UpdateCheckBoxState"] = True
        BOOTLOADER_INFO[_os]["GUIState"]["KeepExistingTimeoutCheckBoxState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["NewTimeoutSpinnerState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["KeepExistingKernelOptionsCheckBoxState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["NewKernelOptionsTextCtrlState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["DefaultOSChoiceState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["InstallNewBootloaderCheckBoxState"] = True
        BOOTLOADER_INFO[_os]["GUIState"]["NewBootloaderChoiceState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["BackupBootloaderCheckBoxState"] = True
        BOOTLOADER_INFO[_os]["GUIState"]["BackupBootloaderChoiceState"] = False
        BOOTLOADER_INFO[_os]["GUIState"]["RestoreBootloaderCheckBoxState"] = True
        BOOTLOADER_INFO[_os]["GUIState"]["RestoreBootloaderChoiceState"] = 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("MainBackendTools: get_bootloaders(): 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("get_bootloaders(): Failed to unmount "+_os+"'s /boot partition! "
                             + "Continuing anyway...")

        #Clean up if needed.
        if not OS_INFO[_os]["IsCurrentOS"]:
            #Remove chroot.
            if CoreTools.teardown_chroot(mount_point) != 0:
                logger.error("get_bootloaders(): Failed to remove chroot from "+mount_point
                             + "! Attempting to continue anyway...")

            #unmount the OS's partition.
            if CoreTools.unmount(mount_point) != 0:
                logger.error("get_bootloaders(): Failed to unmount "+_os+"'s partition! This "
                             + "could indicate that chroot wasn't removed correctly. Continuing "
                             + "anyway...")

    #Get default OSs.
    for _os in OS_INFO:
        #Set sensible defaults for Windows.
        if "Windows" in _os:
            BOOTLOADER_INFO[_os]["DefaultBootDevice"] = OS_INFO[_os]["Partition"]
            BOOTLOADER_INFO[_os]["DefaultOS"] = _os
            continue

        #Same for macOS.
        elif "macOS" in _os:
            BOOTLOADER_INFO[_os]["DefaultBootDevice"] = OS_INFO[_os]["Partition"]
            BOOTLOADER_INFO[_os]["DefaultOS"] = _os
            continue

        #Match the bootloader-specific default OS to WxFixBoot's OSs by partition.
        logger.info("get_bootloaders(): Attempting to match "+_os+"'s default OS to any OS that "
                    + "WxFixBoot detected...")

        BOOTLOADER_INFO[_os]["DefaultBootDevice"] = "Unknown"

        if "MenuEntries" in BOOTLOADER_INFO[_os].keys():
            CoreStartupTools.get_defaultoss_partition(_os)

        else:
            #Bootloader's configuration is missing.
            logger.error("get_bootloaders(): "+_os+"'s bootloader configuration is missing. A "
                         + "reinstall will be required for that bootloader...")

        #We have the partition, so now find the OS that resides on that partition.
        CoreStartupTools.match_partition_to_os(_os)

        #Log if we couldn't match them.
        if BOOTLOADER_INFO[_os]["DefaultOS"] == "Unknown":
            logger.warning("get_bootloaders(): Couldn't match! We will instead use the first OS "
                           + "in the list as the default OS, which is "
                           + SYSTEM_INFO["ModifyableOSs"][0]+"...")

            BOOTLOADER_INFO[_os]["DefaultOS"] = SYSTEM_INFO["ModifyableOSs"][0]

        #Set this.
        BOOTLOADER_INFO[_os]["Settings"]["DefaultOS"] = BOOTLOADER_INFO[_os]["DefaultOS"]
Esempio n. 7
0
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
Esempio n. 8
0
def filesystem_check(_type, manage_bootloader_function):
    """Quickly check all filesystems."""
    logger.debug("filesystem_check(): Starting...")

    #Update Current Operation Text.
    wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text,
                 message="Preparing for Filesystem Check...")

    wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 10)
    wx.CallAfter(wx.GetApp().TopWindow.update_output_box,
                 "\n###Preparing to do the Filesystem Check...###\n")

    #Determine which Disks are to be checked.
    filesystems_to_check = HelperBackendTools.find_checkable_file_systems()
    wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 30)

    #Find the length of the list (this is needed to update the progressbars).
    filesystems_to_check_length = len(filesystems_to_check)
    checked = 0

    DialogTools.show_msg_dlg(
        kind="info",
        message="WxFixBoot will now perform the disk checks. " +
        "You may wish to open the terminal output box to view the " +
        "progress information.")

    #Run the check on the checkable Disks
    for disk in filesystems_to_check:
        #Gather info.
        logger.info("filesystem_check():: Checking " + disk + "...")
        wx.CallAfter(wx.GetApp().TopWindow.update_output_box,
                     "\n###Checking Disk: " + disk + "###\n")
        wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text,
                     message="Checking Disk: " + disk)
        wx.CallAfter(
            wx.GetApp().TopWindow.update_current_progress,
            30 + ((50 // filesystems_to_check_length) * (checked + 1)))

        run_badblocks = False

        #Create a command list that will work based on the fstype of this Disk and the type of
        #check we're performing. If there aren't any use cases for the fstype, display a message
        #to the user and skip it.
        if _type == "Quick":
            if DISK_INFO[disk]["FileSystem"] == "jfs":
                exec_cmds = "fsck.jfs -vf " + disk

            elif DISK_INFO[disk]["FileSystem"] == "minix":
                exec_cmds = "fsck.minix -avf " + disk

            elif DISK_INFO[disk]["FileSystem"] == "reiserfs":
                exec_cmds = "fsck.reiserfs -apf " + disk

            elif DISK_INFO[disk]["FileSystem"] == "xfs":
                exec_cmds = "xfs_repair -Pvd " + disk

            elif DISK_INFO[disk]["FileSystem"] in ("hfs", "hfsplus"):
                exec_cmds = "fsck.hfsplus -fy " + disk

            elif DISK_INFO[disk]["FileSystem"] == "vfat":
                exec_cmds = "fsck.vfat -yv " + disk

            elif DISK_INFO[disk]["FileSystem"] in ('ext2', 'ext3', 'ext4',
                                                   'ext4dev'):
                exec_cmds = "fsck." + DISK_INFO[disk][
                    "FileSystem"] + " -yvf " + disk

            else:
                exec_cmds = ""
                logger.warning(
                    "filesystem_check(): Skipping Disk: " + disk +
                    ", as WxFixBoot doesn't support checking it yet...")

                DialogTools.show_msg_dlg(
                    kind="error",
                    message="The filesystem on Disk: " + disk +
                    " could not be checked, as WxFixBoot doesn't support " +
                    "checking it yet. " + disk + " will now be skipped.")

        else:
            #For disks that doesn't do bad sector checks with the normal FS checker,
            #run badblocks manually on them.
            if DISK_INFO[disk]["FileSystem"] == "jfs":
                exec_cmds = "fsck.jfs -vf " + disk
                run_badblocks = True

            elif DISK_INFO[disk]["FileSystem"] == "minix":
                exec_cmds = "fsck.minix -avf " + disk
                run_badblocks = True

            elif DISK_INFO[disk]["FileSystem"] == "reiserfs":
                exec_cmds = "fsck.reiserfs -apf " + disk
                run_badblocks = True

            elif DISK_INFO[disk]["FileSystem"] == "xfs":
                exec_cmds = "xfs_repair -Pvd " + disk
                run_badblocks = True

            elif DISK_INFO[disk]["FileSystem"] in ("hfs", "hfsplus"):
                exec_cmds = "fsck.hfsplus -fy " + disk
                run_badblocks = True

            elif DISK_INFO[disk]["FileSystem"] == "vfat":
                exec_cmds = "fsck.vfat -yvt " + disk

            elif DISK_INFO[disk]["FileSystem"] in ('ext2', 'ext3', 'ext4',
                                                   'ext4dev'):
                exec_cmds = "fsck." + DISK_INFO[disk][
                    "FileSystem"] + " -yvcf " + disk

            else:
                exec_cmds = ""
                DialogTools.show_msg_dlg(
                    kind="info",
                    message="The filesystem on Disk: " + disk +
                    " could not be checked, as WxFixBoot doesn't support " +
                    "checking it yet. " + disk + " will now be skipped.")

        #Run the command, and remount the Disk if needed.
        if exec_cmds != "":
            retval = CoreTools.start_process(exec_cmds, privileged=True)

            #Check the return values, and run the handler if needed.
            if retval == 0:
                #Success.
                logger.info("filesystem_check(): Checked Disk: " + disk +
                            ". No Errors Found!")

            else:
                handle_filesystem_check_return_values(
                    exec_cmds=exec_cmds,
                    retval=retval,
                    partition=disk,
                    manage_bootloader_function=manage_bootloader_function)

        #Run bad blocks if requested.
        if run_badblocks:
            retval = CoreTools.start_process("badblocks -sv " + disk,
                                             privileged=True)

            #Check the return values, and run the handler if needed.
            if retval == 0:
                #Success.
                logger.info("filesystem_check(): Checked Disk: " + disk +
                            " for bad sectors. " + "No Errors Found!")

            else:
                handle_filesystem_check_return_values(
                    exec_cmds="badblocks -sv " + disk,
                    retval=retval,
                    partition=disk,
                    manage_bootloader_function=manage_bootloader_function)

        if filesystems_to_check[disk]["Remount"]:
            logger.debug("filesystem_check(): Remounting Disk: " + disk +
                         " Read-Write...")
            retval = CoreTools.mount_partition(
                partition=disk,
                mount_point=filesystems_to_check[disk]["MountPoint"])

            if retval != 0:
                logger.warning(
                    "filesystem_check(): Failed to remount " + disk +
                    " after check. We probably need to reboot first. Never mind..."
                )

        checked += 1

    #Update Current Operation Text.
    wx.CallAfter(wx.GetApp().TopWindow.update_current_operation_text,
                 message="Finished Filesystem Check!")
    wx.CallAfter(wx.GetApp().TopWindow.update_current_progress, 100)
    wx.CallAfter(wx.GetApp().TopWindow.update_output_box,
                 "\n###Finished Filesystem Check!###\n")
Esempio n. 9
0
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
Esempio n. 10
0
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
Esempio n. 11
0
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)