Skip to content

Instantly share code, notes, and snippets.

@VerosK
Created April 26, 2020 20:20
Show Gist options
  • Save VerosK/61c9b458db2f1f18aec1a258bcbc12ec to your computer and use it in GitHub Desktop.
Save VerosK/61c9b458db2f1f18aec1a258bcbc12ec to your computer and use it in GitHub Desktop.
FInd the largest available block device
#!/usr/bin/env python3
import subprocess
import json
from pprint import pprint
res = subprocess.check_output('lsblk --json --bytes', shell=True)
d = json.loads(res)
max_size = 0
device_name = None
for device in d['blockdevices']:
if device['mountpoint'] is not None:
continue # skip mounted devices
if 'children' in device:
continue # skip master devices
if int(device['size']) > max_size:
max_size = int(device['size'])
device_name = device['name']
print(f'/dev/{device_name}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment