def image_mount(self, image_fullname, diff_path, mount_path): layers = self.get_image_layers(image_fullname) branches = [ layer + '=ro+wh' for layer in layers ] branches.insert(0, diff_path + '=rw') if len(branches) > AUFS_BR_LIMIT: raise Exception('Cannot mount image: too many filesystem layers.') else: # we can mount up to AUFS_BR_MOUNT_LIMIT branches at once branches_opt = 'br=' + ':'.join(branches[:AUFS_BR_MOUNT_LIMIT]) mount('-t', 'aufs', '-o', branches_opt, 'none', mount_path) # append others one by one for branch in branches[AUFS_BR_MOUNT_LIMIT:]: mount('-o', 'remount,append=' + branch, mount_path)
def mount_fs(volume): device = volume.attachments[0]['Device'] container_device = '/host_root%s' % device fs_type = sh('-c', "file -sL %s" % container_device) if 'ext4' in fs_type: pass elif 'data' in fs_type: logger.info("Creating file system") sh('-c', 'mkfs.ext4 %s' % container_device) sh('-c', 'mkdir -p /tmp/mounted') mount(container_device, '/tmp/mounted') touch('/tmp/mounted/.mounted') umount('/tmp/mounted') if not device in mount(): logger.info("Deferring mount via cron") mount_via_cron('%s' % device, volume.id)
def image_mount(self, image_fullname, diff_path, mount_path): while True: try: layers = self.get_image_layers(image_fullname) branches = [layer + '=ro+wh' for layer in layers] break # OK except FileNotFoundError: print('missing docker layer... updating the cache') self.update_layer_id_cache() branches.insert(0, diff_path + '=rw') if len(branches) > AUFS_BR_LIMIT: raise Exception('Cannot mount image: too many filesystem layers.') else: # we can mount up to AUFS_BR_MOUNT_LIMIT branches at once branches_opt = 'br=' + ':'.join(branches[:AUFS_BR_MOUNT_LIMIT]) mount('-t', 'aufs', '-o', branches_opt, 'none', mount_path) # append others one by one for branch in branches[AUFS_BR_MOUNT_LIMIT:]: mount('-o', 'remount,append=' + branch, mount_path)
def mount_table(): """returns the system's current mount table (a list of :class:`MountEntry <plumbum.unixutils.MountEntry>` objects)""" table = [] for line in mount().splitlines(): m = MOUNT_PATTERN.match(line) if not m: continue table.append(MountEntry(*m.groups())) return table
def handleSystemExt4Image(self, systemImageFilename): logger.debug('Searching for files which match pattern "%s"' % self.broadcomPattern) directory = './mounted-image' mkdir(directory) mount(systemImageFilename, directory) firmwares = find(directory, '-iname', self.broadcomPattern).splitlines() for firmware in firmwares: print 'Found firmware: %s (Size: %d)' % (firmware, os.path.getsize(firmware)) versionCommand = strings[firmware] | tail['-1'] print versionCommand() if not firmwares: print 'No firmwares found.' umount(directory) rm('-rf', directory)
from collections import defaultdict from plumbum.cmd import mount from plumbum.colors import green, red, magenta blacklist = { 'fs': ['cgroup'], 'point': [ '/boot/efi', '/sys', '/sys/kernel/security', '/sys/fs/pstore', '/proc', '/dev/mqueue', '/sys/fs/cgroup', '/run/user/1000', '/run', '/dev/shm', '/dev/hugepages', '/sys/firmware/efi/efivars', '/dev', '/dev/pts', '/sys/kernel/debug', '/sys/kernel/config', '/proc/sys/fs/binfmt_misc' ], 'device': [] } filesystems = defaultdict(list) for line in mount().strip().splitlines(): device, _on, mount_point, _type, filesystem, options = line.split() if filesystem not in blacklist['fs'] and \ mount_point not in blacklist['point'] and \ device not in blacklist['device']: options = options.strip('()').split(',') filesystems[filesystem].append('{}: {} [{}]'.format( red | mount_point, green | device, magenta | ', '.join(options))) print() for filesystem in sorted(filesystems): print(green | '{}'.format(filesystem), '-' * len(filesystem), sep='\n') print('\n'.join(sorted(filesystems[filesystem])), '\n') # print((column['-t'] < '\n'.join(sorted(filesystems[filesystem])))())
def __enter__(self): if not path.isdir(self.mount_point): os.makedirs(self.mount_point) mount(*self.args)