-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDiskInfo.py
More file actions
executable file
·39 lines (30 loc) · 1.13 KB
/
getDiskInfo.py
File metadata and controls
executable file
·39 lines (30 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from glob import glob
import subprocess
import os
import sys
from os.path import basename, dirname
def physical_drives():
drive_glob = '/sys/block/*/device'
return [basename(dirname(d)) for d in glob(drive_glob)]
def partitions(disk):
if disk.startswith('.') or '/' in disk:
raise ValueError('Invalid disk name {0}'.format(disk))
partition_glob = '/sys/block/{0}/*/start'.format(disk)
return [basename(dirname(p)) for p in glob(partition_glob)]
disk = physical_drives()
disk_part = partitions(disk[0])
conv_str = ' '.join(map(str, disk))
root_device = "/dev/"+conv_str
conv_str1 = ' '.join(map(str, disk_part))
root_partition = "/dev/"+conv_str1
# Fetching mount point from main_device
df = subprocess.Popen(["df", "-hT", root_partition], stdout=subprocess.PIPE)
output = df.communicate()[0]
device, Type, size, used, available, percent, mountpoint = output.split("\n")[1].split()
if Type == 'xfs':
os.system('sudo growpart '+root_device+' 1')
os.system('sudo xfs_growfs -d '+mountpoint)
print('file system has been extended')
elif Type == 'ext3' or 'ext4':
print('Need to work on ext file systems')
sys.exit(0)