python 磁盘信息 格式
# blkid 查看 块设备ID信息
process = os.popen('blkid')
output = process.readlines()
process.close()
disk_info = {}
for l in output:
et = l.strip().split(':',1)
tinf = {'name':et[0]}
if len(et) < 2: continue
dev, info = et
et = info.strip().split()
for e in et:
et2 = e.split('=')
tinf[et2[0]] = et2[1].strip().strip('"')
if 'UUID' in tinf:
disk_info[tinf['UUID']] = tinf
# lsblk 查看 块设备挂载信息
process = os.popen('lsblk')
output = process.readlines()
process.close()
blk_nm = None
blk_info = {}
mount_dir = {}
for l in output:
if len(l.strip()) == 0: continue
sp_l = l.strip().split()
if not blk_nm:
blk_nm = sp_l
continue
binfo_nm = sp_l[0].strip('├─└')
binfo = {}
for i in range(1,len(sp_l)):
binfo[blk_nm[i]] = sp_l[i]
if 'MOUNTPOINT' in binfo:
mount_dir[binfo['MOUNTPOINT']] = binfo_nm
blk_info[binfo_nm] = binfo