python - Find the superblock on disk -


i have write python script in work. script must print devices meet conditions. 1 of conditions superblock. device must have superblock.

other conditions:

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

is there has idea how it? have confess dont have any. it's not necessary manage python. there way how check ? :)

thank much.

you can grep output of dumpe2fs device_name existance of "superblock at".

here's example on centos 5 linux system:

>>> import shlex, subprocess >>> filesystems = ['/dev/mapper/volgroup00-logvol00', '/dev/vda1', 'tmpfs'] >>> 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 {fs}".format(fs=fs) ... /dev/mapper/volgroup00-logvol00 has superblock /dev/vda1 has superblock no superblock found tmpfs 

more information on dumpe2fs:

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


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -