def _partition_device(self): self._messenger.info('Partitioning "%s"...' % self._abs_target_path) cmd_mklabel = [ COMMAND_PARTED, '--script', self._abs_target_path, 'mklabel', 'msdos', ] self._executor.check_call(cmd_mklabel) # Make existing partition devices leave check_call__keep_trying(self._executor, [ COMMAND_PARTPROBE, self._abs_target_path, ]) cmd_mkpart = [ COMMAND_PARTED, '--script', '--align', 'optimal', self._abs_target_path, 'mkpart', 'primary', 'ext4', '1', '100%', ] self._executor.check_call(cmd_mkpart) cmd_boot_flag = [ COMMAND_PARTED, '--script', self._abs_target_path, 'set', '1', 'boot', 'on', ] time.sleep(1) # increase chances of first call working, e.g. with LVM volumes check_call__keep_trying(self._executor, cmd_boot_flag)
def _remove_partition_devices(self): self._messenger.info('Deactivating partition devices...') cmd = [ COMMAND_KPARTX, '-d', self._abs_target_path, ] check_call__keep_trying(self._executor, cmd)
def try_unmounting(executor, abs_path): cmd = [ COMMAND_UMOUNT, abs_path, ] check_call__keep_trying(executor, cmd)