def load(self): log.debug("loading mapable drive {0}".format(self.path)) try: if not re.search(r"block special", str(sh.file(self.path).stdout, 'utf8'), flags=re.IGNORECASE): self.lodev = sh.losetup("-f").split()[0] sh.losetup(self.lodev, self.path) sh.blkid(self.lodev) try: sh.partprobe(self.lodev) except: pass else: sh.blkid(self.path) try: sh.partprobe(self.path) except: pass sh.sync("/dev/") self.process_devicemap() except Exception as e: log.exception(e) return False return True
def has_filesystem(path): try: blkid("-p", "-u", "filesystem", path) except Exception as ex: msg = (_LI('exception is : %s'), six.text_type(ex)) LOG.info(msg) if ex.stdout == '': return False return True
def make_bootable(self): """ Tworzenie dysku bootowalnego """ self.uuid = re.search("UUID=\"(\w*)\"", str(sh.blkid(self.device + "1"))).group(1) print("Device UUID:", self.uuid) # W niektórych wersjach windows katalog ten jest z drukowanej self.boot_folder = self.destination_mount + "/boot" try: sh.mv(self.destination_mount + "/BOOT", self.boot_folder) except: pass # Instalownie bootloadera # grub-install --target=i386-pc --boot-directory="/<USB_mount_folder>/boot" /dev/sdX installer = sh.Command("grub-install") installer(self.device, target="i386-pc", boot_directory=self.destination_mount + "/boot") # Tworzenie konfiguracji GRUBa with open("{}/grub/grub.cfg".format(self.boot_folder), "wt") as config: config.write(""" set menu_color_normal=white/black set menu_color_highlight=black/light-gray menuentry 'Install Windows' { ntldr /bootmgr } """)
def get_partitions(drive): """ Look for partitions belonging to an attached volume. Args: drive (str): The drive to check. Returns (list): List of file system paths that much the pattern. """ click.echo(_("Checking if drive {drive} has partitions.").format(drive=drive)) # Before we can really _get_ the partitions, we should # really check and make sure we have any at all. blkid_out = sh.blkid("-p", "-o", "export", drive) blkid_out = blkid_out.rstrip().split("\n") blkid_dict = dict(map(lambda x: x.split("=", 1), blkid_out)) click.echo( _('Block device attributes for drive "{}"\n"Output:\n" "{}"').format( drive, blkid_dict ) ) if partition_type := blkid_dict.get("PTTYPE"): click.echo( _("Device appears to have partitions, PTTYPE: {}").format(partition_type) ) partitions = sorted(glob.glob("{}*[0-9]".format(drive)))
def status(): print(f'$ config values --------------------\n') print(config) print(f'\n$ sgdisk --print {config.disk_dev} --------------------\n') sh.sgdisk('--print', config.disk_dev, _out=sys.stdout, _ok_code=[0,2]) print(f'\n$ blkid --------------------------\n') sh.blkid(_out=sys.stdout,) print('\n$ zpool list ---------------------------\n') sh.zpool('list', _out=sys.stdout) print('\n$ zfs list ---------------------------\n') sh.zfs('list', _out=sys.stdout) print('\n$ zfs mount ---------------------------\n') sh.zfs('mount', _out=sys.stdout)
def has_filesystem(path): try: if blkid("-p", "-u", "filesystem", path) == '': return False except Exception as ex: msg = (_LI('exception is : %s'), six.text_type(ex)) LOG.info(msg) if ex.stdout == '': return False return True
def distinguish_dos_from_fs(path, magic_str=None, mime_type=None, metadata=None, parent=None): ## Must have the same header than File.__init__ cmd = str(sh.blkid("-o", "export", path).stdout, 'utf8') if re.search("\nTYPE=.*\n", cmd): return FileSystem(path, magic_str, parent) else: return MapableDrive(path, magic_str, parent)
def has_filesystem(path): try: #ToDo Parse the output to get exact information, example #/dev/sdj: UUID="0cb38451-c366-46e8-a7a4-5e19bd9257f0" VERSION="1.0" TYPE="ext4" USAGE="filesystem" if blkid("-p", "-u", "filesystem", path) == '': return False except: #msg = 'Error getting filesystem existatnce' #LOG.error(msg) return False return True
def get_block_uuid(): result = {} block_info = sh.blkid().stdout.decode('utf-8') for block in block_info.splitlines(): tokens = block.split(':', 1) if len(tokens) < 2: continue if not tokens[0].startswith('/dev/'): continue device = tokens[0][5:] m = uuid_pattern.search(tokens[1]) if m: uuid = (tokens[1][m.start():m.end()].split('"')[1]) result[device] = uuid return result
def set_fsattrs(self): log.debug("Getting filesystem attributes {0}".format(self.path)) try: me = json.loads( str( sh.lsblk("-pJ", "-o", self.LSBLK_KEYS, self.path).stdout, 'utf8'))["blockdevices"][0] try: self.uuid = me["uuid"] log.debug("GOT UUID: {0}".format(self.uuid)) except KeyError: self.uuid = None try: self.fstype = me["fstype"] log.debug("GOT FSTYPE: {0}".format(self.fstype)) except KeyError: self.fstype = None try: self.label = me["label"] except KeyError: self.label = None except sh.ErrorReturnCode_32: # Not a block device falling back to blkid cmd = str(sh.blkid("-o", "export", self.path).stdout, 'utf8') try: self.uuid = re.search("UUID=(.*)", cmd).group(1) except (TypeError, AttributeError): self.uuid = None try: self.fstype = re.search("TYPE=(.*)", cmd).group(1) except (TypeError, AttributeError): self.fstype = None try: self.label = re.search("LABEL=(.*)", cmd).group(1) except (TypeError, AttributeError): self.label = None if str(self.fstype) not in self.SUPPORTED_FS: log.error("{0} is out of {1} : {2}".format(self.fstype, self.SUPPORTED_FS, self.path)) raise IncompatibleFS("Not working with {0} fstype {1}".format( self.path, self.fstype)) return True