Created
April 26, 2020 20:20
-
-
Save VerosK/61c9b458db2f1f18aec1a258bcbc12ec to your computer and use it in GitHub Desktop.
FInd the largest available block device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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