Esempio n. 1
0
    def _find_and_mount_root(self, devices):
        files = ["etc", "bin", "sbin", "boot"]
        os_root_dir = None
        os_root_device = self._find_dev_with_contents(devices, all_files=files)

        if os_root_device is None:
            raise exception.OperatingSystemNotFound(
                "Coriolis was unable to identify the root partition of the OS "
                "being migrated for mounting during OSMorphing. Please ensure "
                "that the source VM's root partition(s) are not encrypted, "
                "and that they are using a filesystem type and version which "
                "is supported by the OS images used for the OSMorphing minion "
                "machine. Also ensure that the source VM's mountpoint "
                "declarations in '/etc/fstab' are all correct, and are "
                "declared using '/dev/disk/by-uuid/' or 'UUID=' notation. "
                "If all else fails, please retry while using an OSMorphing "
                "minion machine image which is the same OS release as the VM "
                "being migrated.")

        try:
            tmp_dir = self._exec_cmd('mktemp -d').decode().splitlines()[0]
            self._exec_cmd('sudo mount %s %s' % (os_root_device, tmp_dir))
            os_root_dir = tmp_dir
        except Exception as ex:
            self._event_manager.progress_update(
                "Exception occurred while Coriolis was attempting to mount the"
                " root device (%s) of the OS being migrated for OSMorphing. "
                "Please ensure that the source VM's root partition(s) are "
                "using a filesystem type and version which is supported by the"
                " OS images used for the OSMorphing minion machine. Also "
                "ensure that the source VM's mountpoint declarations in "
                "'/etc/fstab' are all correct, and are declared using "
                "'/dev/disk/by-uuid/' or 'UUID=' notation. If all else fails, "
                "please retry while using an OSMorphing minion machine image "
                "which is the same OS release as the VM being migrated. Error "
                "was: %s" % (os_root_device, str(ex)))
            LOG.error(ex)
            LOG.warn("Failed to mount root device '%s':\n%s", os_root_device,
                     utils.get_exception_details())
            utils.ignore_exceptions(self._exec_cmd)("sudo umount %s" % tmp_dir)
            utils.ignore_exceptions(self._exec_cmd)("sudo rmdir %s" % tmp_dir)
            raise

        for directory in ['proc', 'sys', 'dev', 'run']:
            mount_dir = os.path.join(os_root_dir, directory)
            if not utils.test_ssh_path(self._ssh, mount_dir):
                LOG.info("No '%s' directory in mounted OS. Skipping mount.",
                         directory)
                continue
            self._exec_cmd('sudo mount -o bind /%(dir)s/ %(mount_dir)s' % {
                'dir': directory,
                'mount_dir': mount_dir
            })

        if os_root_device in devices:
            devices.remove(os_root_device)

        return os_root_dir, os_root_device
Esempio n. 2
0
    def mount_os(self):
        self._refresh_storage()
        self._bring_all_disks_online()
        self._set_basic_disks_rw_mode()
        self._set_foreign_disks_rw_mode()
        self._import_foreign_disks()
        self._refresh_storage()
        fs_roots = self._get_fs_roots()
        system_drive = self._get_system_drive()

        for fs_root in [r for r in fs_roots if not r[:-1] == system_drive]:
            if self._conn.test_path("%sWindows\\System32" % fs_root):
                return fs_root, None

        raise exception.OperatingSystemNotFound("root partition not found")
Esempio n. 3
0
    def _find_and_mount_root(self, devices):
        files = ["etc", "bin", "sbin", "boot"]
        os_root_dir = None
        os_root_device = self._find_dev_with_contents(
            devices, all_files=files)

        if os_root_device is None:
            raise exception.OperatingSystemNotFound(
                "root partition not found")

        try:
            tmp_dir = self._exec_cmd('mktemp -d').decode().splitlines()[0]
            self._exec_cmd('sudo mount %s %s' % (os_root_device, tmp_dir))
            os_root_dir = tmp_dir
        except Exception:
            self._event_manager.progress_update(
                "Failed to mount root device '%s'" % os_root_device)
            LOG.warn(
                "Failed to mount root device '%s':\n%s",
                os_root_device, utils.get_exception_details())
            utils.ignore_exceptions(self._exec_cmd)(
                "sudo umount %s" % tmp_dir
            )
            utils.ignore_exceptions(self._exec_cmd)(
                "sudo rmdir %s" % tmp_dir
            )
            raise

        for directory in ['proc', 'sys', 'dev', 'run']:
            mount_dir = os.path.join(os_root_dir, directory)
            if not utils.test_ssh_path(self._ssh, mount_dir):
                LOG.info(
                    "No '%s' directory in mounted OS. Skipping mount.",
                    directory)
                continue
            self._exec_cmd(
                'sudo mount -o bind /%(dir)s/ %(mount_dir)s' %
                {'dir': directory, 'mount_dir': mount_dir})

        if os_root_device in devices:
            devices.remove(os_root_device)

        return os_root_dir, os_root_device
Esempio n. 4
0
    def mount_os(self):
        dev_paths = []
        other_mounted_dirs = []

        self._exec_cmd("sudo apt-get update -y")
        self._exec_cmd("sudo apt-get install lvm2 -y")
        self._exec_cmd("sudo modprobe dm-mod")

        volume_devs = self._get_volume_block_devices()
        for volume_dev in volume_devs:
            self._exec_cmd("sudo partx -v -a %s || true" % volume_dev)
            dev_paths += self._exec_cmd("sudo ls %s*" %
                                        volume_dev).decode().split('\n')[:-1]

        for vg_name in self._get_vgnames():
            self._exec_cmd("sudo vgchange -ay %s" % vg_name)
            lvm_dev_paths = self._exec_cmd("sudo ls /dev/%s/*" %
                                           vg_name).decode().split('\n')[:-1]
            dev_paths += lvm_dev_paths

        valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs']

        dev_paths_to_mount = []
        for dev_path in dev_paths:
            fs_type = self._exec_cmd("sudo blkid -o value -s TYPE %s || true" %
                                     dev_path).decode().split('\n')[0]
            if fs_type in valid_filesystems:
                utils.check_fs(self._ssh, fs_type, dev_path)
                dev_paths_to_mount.append(dev_path)

        os_root_dir = None
        boot_dev_path = None
        for dev_path in dev_paths_to_mount:
            tmp_dir = self._exec_cmd('mktemp -d').decode().split('\n')[0]
            self._exec_cmd('sudo mount %s %s' % (dev_path, tmp_dir))
            dirs = self._exec_cmd('ls %s' % tmp_dir).decode().split('\n')

            # TODO: better ways to check for a linux root?
            if (not os_root_dir and 'etc' in dirs and 'bin' in dirs
                    and 'sbin' in dirs):
                os_root_dir = tmp_dir
                LOG.info("OS root device: %s", dev_path)
            # TODO: better ways to check for a linux boot dir?
            else:
                # TODO: better ways to check for a linux boot dir?
                if not boot_dev_path and ('grub' in dirs or 'grub2' in dirs):
                    # Needs to be remounted under os_root_dir
                    boot_dev_path = dev_path
                    LOG.info("OS boot device: %s", dev_path)

                self._exec_cmd('sudo umount %s' % tmp_dir)

            if os_root_dir and boot_dev_path:
                break

        if not os_root_dir:
            raise exception.OperatingSystemNotFound("root partition not found")

        for dir in set(dirs).intersection(['proc', 'sys', 'dev', 'run']):
            mount_dir = os.path.join(os_root_dir, dir)
            self._exec_cmd('sudo mount -o bind /%(dir)s/ %(mount_dir)s' % {
                'dir': dir,
                'mount_dir': mount_dir
            })
            other_mounted_dirs.append(mount_dir)

        if boot_dev_path:
            boot_dir = os.path.join(os_root_dir, 'boot')
            self._exec_cmd('sudo mount %s %s' % (boot_dev_path, boot_dir))
            other_mounted_dirs.append(boot_dir)

        return os_root_dir, other_mounted_dirs
Esempio n. 5
0
    def mount_os(self):
        dev_paths = []
        mounted_devs = self._get_mounted_devices()

        volume_devs = self._get_volume_block_devices()
        for volume_dev in volume_devs:
            self._exec_cmd("sudo partx -v -a %s || true" % volume_dev)
            dev_paths += self._exec_cmd("sudo ls %s*" %
                                        volume_dev).decode().split('\n')[:-1]

        pvs = self._get_pvs()
        for vg_name in self._get_vgnames():
            found = False
            for pv in pvs[vg_name]:
                if pv in dev_paths:
                    found = True
                    break
            if not found:
                continue
            self._exec_cmd("sudo vgchange -ay %s" % vg_name)
            lvm_dev_paths = self._exec_cmd("sudo ls /dev/%s/*" %
                                           vg_name).decode().split('\n')[:-1]
            dev_paths += lvm_dev_paths

        valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs']

        dev_paths_to_mount = []
        for dev_path in dev_paths:
            if dev_path in mounted_devs:
                # this device is already mounted. Skip it, as it most likely
                # means this device belongs to the worker VM.
                continue
            fs_type = self._exec_cmd("sudo blkid -o value -s TYPE %s || true" %
                                     dev_path).decode().split('\n')[0]
            if fs_type in valid_filesystems:
                if fs_type == "xfs":
                    utils.run_xfs_repair(self._ssh, dev_path)
                else:
                    utils.check_fs(self._ssh, fs_type, dev_path)
                dev_paths_to_mount.append(dev_path)

        os_boot_device = None
        os_root_device = None
        os_root_dir = None
        for dev_path in dev_paths_to_mount:
            dirs = None
            tmp_dir = self._exec_cmd('mktemp -d').decode().split('\n')[0]
            try:
                self._exec_cmd('sudo mount %s %s' % (dev_path, tmp_dir))
                # NOTE: it's possible that the device was mounted successfully
                # but an I/O error occurs later along the line:
                dirs = self._exec_cmd('ls %s' % tmp_dir).decode().split('\n')
            except Exception:
                self._event_manager.progress_update(
                    "Failed to mount and scan device '%s'" % dev_path)
                LOG.warn("Failed to mount and scan device '%s':\n%s", dev_path,
                         utils.get_exception_details())
                continue

            LOG.debug("Contents of device %s:\n%s", dev_path, dirs)

            # TODO(alexpilotti): better ways to check for a linux root?
            if (not os_root_dir and 'etc' in dirs and 'bin' in dirs
                    and 'sbin' in dirs):
                os_root_dir = tmp_dir
                os_root_device = dev_path
                LOG.info("OS root device: %s", dev_path)
                continue
            elif (not os_boot_device and ('grub' in dirs or 'grub2' in dirs)):
                os_boot_device = dev_path
                LOG.info("OS boot device: %s", dev_path)
                self._exec_cmd('sudo umount %s' % tmp_dir)
            else:
                self._exec_cmd('sudo umount %s' % tmp_dir)

        if not os_root_dir:
            raise exception.OperatingSystemNotFound("root partition not found")

        if os_boot_device:
            LOG.debug("Mounting boot device '%s'", os_boot_device)
            self._exec_cmd('sudo mount %s "%s/boot"' %
                           (os_boot_device, os_root_dir))

        lvm_devs = list(set(self._get_lv_paths()) - set(mounted_devs))
        self._check_mount_fstab_partitions(os_root_dir,
                                           mountable_lvm_devs=lvm_devs)

        for dir in set(dirs).intersection(['proc', 'sys', 'dev', 'run']):
            mount_dir = os.path.join(os_root_dir, dir)
            if not utils.test_ssh_path(self._ssh, mount_dir):
                LOG.info("No '%s' directory in mounted OS. Skipping mount.",
                         dir)
                continue
            self._exec_cmd('sudo mount -o bind /%(dir)s/ %(mount_dir)s' % {
                'dir': dir,
                'mount_dir': mount_dir
            })
        return os_root_dir, os_root_device
Esempio n. 6
0
    def mount_os(self):
        dev_paths = []
        other_mounted_dirs = []

        volume_devs = self._get_volume_block_devices()
        for volume_dev in volume_devs:
            self._exec_cmd("sudo partx -v -a %s || true" % volume_dev)
            dev_paths += self._exec_cmd("sudo ls %s*" %
                                        volume_dev).decode().split('\n')[:-1]

        pvs = self._get_pvs()
        for vg_name in self._get_vgnames():
            found = False
            for pv in pvs[vg_name]:
                if pv in dev_paths:
                    found = True
                    break
            if not found:
                continue
            self._exec_cmd("sudo vgchange -ay %s" % vg_name)
            lvm_dev_paths = self._exec_cmd("sudo ls /dev/%s/*" %
                                           vg_name).decode().split('\n')[:-1]
            dev_paths += lvm_dev_paths

        valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs']

        dev_paths_to_mount = []
        for dev_path in dev_paths:
            fs_type = self._exec_cmd("sudo blkid -o value -s TYPE %s || true" %
                                     dev_path).decode().split('\n')[0]
            if fs_type in valid_filesystems:
                if fs_type == "xfs":
                    utils.run_xfs_repair(self._ssh, dev_path)
                else:
                    utils.check_fs(self._ssh, fs_type, dev_path)
                dev_paths_to_mount.append(dev_path)

        os_root_device = None
        os_root_dir = None
        for dev_path in dev_paths_to_mount:
            tmp_dir = self._exec_cmd('mktemp -d').decode().split('\n')[0]
            self._exec_cmd('sudo mount %s %s' % (dev_path, tmp_dir))
            dirs = self._exec_cmd('ls %s' % tmp_dir).decode().split('\n')

            # TODO(alexpilotti): better ways to check for a linux root?
            if (not os_root_dir and 'etc' in dirs and 'bin' in dirs
                    and 'sbin' in dirs):
                os_root_dir = tmp_dir
                os_root_device = dev_path
                LOG.info("OS root device: %s", dev_path)
                break
            else:
                self._exec_cmd('sudo umount %s' % tmp_dir)

        if not os_root_dir:
            raise exception.OperatingSystemNotFound("root partition not found")

        other_mounted_dirs.extend(
            self._check_mount_fstab_partitions(os_root_dir))

        for dir in set(dirs).intersection(['proc', 'sys', 'dev', 'run']):
            mount_dir = os.path.join(os_root_dir, dir)
            if not utils.test_ssh_path(self._ssh, mount_dir):
                LOG.info("No '%s' directory in mounted OS. Skipping mount.",
                         dir)
                continue
            self._exec_cmd('sudo mount -o bind /%(dir)s/ %(mount_dir)s' % {
                'dir': dir,
                'mount_dir': mount_dir
            })
            other_mounted_dirs.append(mount_dir)

        return os_root_dir, other_mounted_dirs, os_root_device