Added method is_debian_live() to identify Debian Live media and loop devices

This commit is contained in:
frisco 2009-06-22 03:08:59 +00:00
parent 2c740c6c6d
commit bf7e8cd156
1 changed files with 42 additions and 0 deletions

View File

@ -248,6 +248,48 @@ class Blockdevice:
else:
return False
def is_debian_live(self):
"""is the device part of the Debian Live runtime
"""
##Debian Live ("iso" or "usb-hdd" versions) uses two block
##devices as part of its runtime system. The raw boot media
##(such as a usb key or cdrom) is mounted at /live_media,
##and the root filesystem is mounted off of the live media
##using /dev/loop0.
deb_live_devs = []
for line in file("/proc/mounts"):
try:
fields = line.split(" ")
##We are looking for, for example:
##/dev/hdc /live_media iso9660 ro 0 0
##and
##/dev/loop0 /filesystem.squashfs squashfs ro 0 0
if (fields[1] == "/live_media" and
fields[3] == "ro"):
deb_live_devs.append(fields[0])
elif (fields[1] == "/filesystem.squashfs" and
fields[3] == "ro"):
deb_live_devs.append(fields[0])
except IndexError:
pass
##TODO:
##Since the lines in /proc/mounts that affect deb_live_devs
##don't change after startup, deb_live_devs could be cached here.
##
##Check whether any Debian Live devices refer to the
##block device we were passed
matched = False
for dev in deb_live_devs:
for node in self.__get_device_nodes():
if (node == dev):
matched = True
##If no nodes of the block device match the Debian Live
##devices, return False
return matched
def is_lvm_pv(self):
"""return if the device is a physical volume of a LVM