Ejemplo n.º 1
0
def find_live_backing_device(devicetree):
    """Find the backing device for the live image.

    Note that this is a little bit of a hack since we're assuming
    that /run/initramfs/live will exist

    :param devicetree: a device tree
    :return: a device or None
    """
    for mnt in open("/proc/mounts").readlines():
        if " /run/initramfs/live " not in mnt:
            continue

        # Return the device mounted at /run/initramfs/live.
        device_path = mnt.split()[0]
        device_name = device_path.split("/")[-1]
        device = devicetree.get_device_by_name(device_name, hidden=True)

        if device:
            return device

        # Or return the disk of this device.
        info = udev.get_device(device_node=device_path)
        disk_name = udev.device_get_partition_disk(info) if info else ""
        disk = devicetree.get_device_by_name(disk_name, hidden=True)

        if disk:
            return disk

    return None
Ejemplo n.º 2
0
def find_live_backing_device():
    """Find the backing device for the live image.

    Note that this is a little bit of a hack since we're assuming
    that /run/initramfs/live will exist

    :return: a device name or None
    """
    for mnt in open("/proc/mounts").readlines():
        if " /run/initramfs/live " not in mnt:
            continue

        live_device_path = mnt.split()[0]
        udev_device = udev.get_device(device_node=live_device_path)

        if udev_device and udev.device_is_partition(udev_device):
            live_device_name = udev.device_get_partition_disk(udev_device)
        else:
            live_device_name = live_device_path.split("/")[-1]

        return live_device_name or None

    return None
Ejemplo n.º 3
0
def find_live_backing_device():
    """Find the backing device for the live image.

    Note that this is a little bit of a hack since we're assuming
    that /run/initramfs/live will exist

    :return: a device name or None
    """
    for mnt in open("/proc/mounts").readlines():
        if " /run/initramfs/live " not in mnt:
            continue

        live_device_path = mnt.split()[0]
        udev_device = udev.get_device(device_node=live_device_path)

        if udev_device and udev.device_is_partition(udev_device):
            live_device_name = udev.device_get_partition_disk(udev_device)
        else:
            live_device_name = live_device_path.split("/")[-1]

        return live_device_name or None

    return None