diff --git a/plinth/modules/disks/__init__.py b/plinth/modules/disks/__init__.py index 02337c6fc..22aa78a4d 100644 --- a/plinth/modules/disks/__init__.py +++ b/plinth/modules/disks/__init__.py @@ -48,7 +48,23 @@ def init(): def get_disks(): - """Return the list of disks and free space available.""" + """Returns list of disks by combining information from df and lsblk.""" + disks_from_df = _get_disks_from_df() + disks_from_lsblk = _get_disks_from_lsblk() + # Combine both sources of info dicts into one dict, based on mount point; + # note this discards disks without a (current) mount point. + combined_list = [] + for disk_from_df in disks_from_df: + for disk_from_lsblk in disks_from_lsblk: + if disk_from_df['mount_point'] == disk_from_lsblk['mountpoint']: + disk_from_df.update(disk_from_lsblk) + combined_list.append(disk_from_df) + + return combined_list + + +def _get_disks_from_df(): + """Return the list of disks and free space available using 'df'.""" command = ['df', '--exclude-type=tmpfs', '--exclude-type=devtmpfs', '--output=source,target,fstype,size,used,pcent', '--human-readable'] @@ -72,9 +88,27 @@ def get_disks(): return disks +def _get_disks_from_lsblk(): + """Return the list of disks and other information from 'lsblk'.""" + command = ['lsblk', '--json', '--output', 'kname,pkname,mountpoint,type'] + try: + process = subprocess.run(command, stdout=subprocess.PIPE, check=True) + except subprocess.CalledProcessError as exception: + logger.exception('Error getting disk information: %s', exception) + return [] + + output = process.stdout.decode() + disks = json.loads(output)['blockdevices'] + for disk in disks: + disk['dev_kname'] = '/dev/{0}'.format(disk['kname']) + + return disks + + def get_root_device(disks): """Return the root partition's device from list of partitions.""" - devices = [disk['device'] for disk in disks if disk['mount_point'] == '/'] + devices = [disk['dev_kname'] for disk in disks + if disk['mountpoint'] == '/' and disk['type'] == 'part'] try: return devices[0] except IndexError: diff --git a/plinth/modules/disks/templates/disks.html b/plinth/modules/disks/templates/disks.html index 24780fb46..e4375c3e6 100644 --- a/plinth/modules/disks/templates/disks.html +++ b/plinth/modules/disks/templates/disks.html @@ -47,7 +47,7 @@ {% for disk in disks %} - {{ disk.device }} + {{ disk.dev_kname }} {{ disk.mount_point }} {{ disk.file_system_type }}