i have to write python script in my work. My script must print all devices which meet some conditions. One of this conditions is superblock. Device must have superblock.
other conditions:
is there anyone who has some idea how to do it? I have to confess that i dont have any. It's not necessary to manage it by python. Is there ANY way how to check it ? :)
Thank you very much.
You can grep the output of dumpe2fs device_name
for existance of "superblock at".
Here's an example on my Centos 5 linux system:
>>> import shlex, subprocess
>>> filesystems = ['/dev/mapper/VolGroup00-LogVol00', '/dev/vda1', 'tmpfs']
>>> for fs in filesystems:
... command = '/sbin/dumpe2fs ' + fs
... p = subprocess.Popen(shlex.split(command),stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
... output = p.communicate()[0]
... if 'superblock at' in output:
... print "{fs} has superblock".format(fs=fs)
... else:
... print "No superblock found for {fs}".format(fs=fs)
...
/dev/mapper/VolGroup00-LogVol00 has superblock
/dev/vda1 has superblock
No superblock found for tmpfs
More information on dumpe2fs: