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 -1 %s*" % volume_dev).decode().splitlines() 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 -1 /dev/%s/*" % vg_name).decode().splitlines() dev_paths += lvm_dev_paths valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs'] dev_paths_to_mount = [] for dev_path in dev_paths: if self._get_symlink_target(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().splitlines() if fs_type and fs_type[0] 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_dir, os_root_device = self._find_and_mount_root( dev_paths_to_mount) grub_dirs = ["grub", "grub2"] os_boot_device = self._find_dev_with_contents( dev_paths_to_mount, one_of_files=grub_dirs) 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) return os_root_dir, os_root_device
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 -1 %s*" % volume_dev).decode().splitlines() LOG.debug("All simple devices to scan: %s", dev_paths) lvm_dev_paths = [] self._check_vgs() 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) dev_paths_for_group = self._exec_cmd( "sudo ls -1 /dev/%s/*" % vg_name).decode().splitlines() lvm_dev_paths.extend(dev_paths_for_group) LOG.debug("All LVM vols to scan: %s", lvm_dev_paths) valid_filesystems = ['ext2', 'ext3', 'ext4', 'xfs', 'btrfs'] dev_paths_to_mount = [] for dev_path in itertools.chain(dev_paths, lvm_dev_paths): LOG.debug("Checking device: '%s'", dev_path) dev_target = self._get_symlink_target(dev_path) if dev_target in mounted_devs: # this device is already mounted. Skip it, as it most likely # means this device belongs to the worker VM. LOG.debug( "Device '%s' (target '%s') is already mounted, assuming it" "belongs to the worker VM so it will be skipped", dev_path, dev_target) continue fs_type = self._exec_cmd("sudo blkid -o value -s TYPE %s || true" % dev_path).decode().splitlines() if fs_type and fs_type[0] in valid_filesystems: if fs_type[0] == "xfs": utils.run_xfs_repair(self._ssh, dev_path) else: try: utils.check_fs(self._ssh, fs_type, dev_path) except Exception as err: self._event_manager.progress_update( "Coriolis failed to check one of the migrated VM's" " filesystems. This could have been caused by " "FS corruption during the last disk sync. If " "the migration fails, please ensure that any " "source-side FS integrity mechanisms (e.g. " "filesystem quiescing, crash-consistent backups, " "etc.) are enabled and available for the source " "machine. If none are available, please try " "migrating/replicating the source machine while it" " is powered off. Error was: %s" % str(err)) LOG.error(err) dev_paths_to_mount.append(dev_path) os_root_dir, os_root_device = self._find_and_mount_root( dev_paths_to_mount) grub_dirs = ["grub", "grub2"] os_boot_device = self._find_dev_with_contents(dev_paths_to_mount, one_of_files=grub_dirs) 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) return os_root_dir, os_root_device
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
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