1

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:

  1. any partitions is not mounted - DONE
  2. any partition is not in raid - DONE
  3. uuid is not in fstab - DONE
  4. arr uuid is in mdadm.conf - DONE
  5. device has superblock - ?????

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.

Johny
  • 125
  • 1
  • 1
  • 6
  • possible duplicate of [How to get the offset in a block device of an inode in a deleted partition](http://stackoverflow.com/questions/31552020/how-to-get-the-offset-in-a-block-device-of-an-inode-in-a-deleted-partition) – Luis Colorado Aug 31 '15 at 21:04

1 Answers1

1

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:

http://linux.die.net/man/8/dumpe2fs

Joe Young
  • 5,749
  • 3
  • 28
  • 27