Question

I'm trying to programmatically mount a disk image created with the Fedora LiveUSB creator, and I'm encountering some issues.

From what I've been told, it's very difficult to mount LVM snapshots outside of the host system. I have both the "pristine" image and the persistent snapshot, so I thought that it should be technically possible.

Any ideas?

Was it helpful?

Solution

LVM's concept of volumes is not portable across systems in the same sense that you can slap some md drives together and they'll still work. Each LVM vg has a unique identifier and you need to get your system's LVM to accept it. In other words, LVM can't "see" the volume group until you "tell" it about its presence. Once you do that, it should be smooth sailing from there.

The snapshot consists of recorded sector deltas. You are correct, you should be able to get your snapshot to show up by having both the original and the snapshot present. A snapshot by itself will not work.

I'm assuming that you're looking at scripting this together, because you just need the lvm toolset to make this happen.

A little parting gift to help you on your way. Save it as /usr/sbin/lvms, set owner as root/root, chmod 755, and use it to save your fingertips.


#!/bin/sh
#lvms command - consolidates all LVM views into a single command
pvscan 1>/dev/null 2>/dev/null
vgscan 1>/dev/null 2>/dev/null
lvscan 1>/dev/null 2>/dev/null
echo "Available Physical Volumes - - - - - - -"
pvs
echo
echo "Active Volume Groups - - - - - - - - - -"
vgs
echo
echo "Active Logical Volumes - - - - - - - - -"
lvs

OTHER TIPS

The operating system image in a Fedora LiveCD or LiveUSB can be mounted after exposing the embedded root filesystem. Fedora's livecd-tools package provides a utility liveimage-mount that does this using Python.

The Fedora LiveOS image (Live CD/USB operating system) technology uses the Device-mapper snapshot target to make a compressed, read-only copy of the root filesystem available for read-write mounting at boot time, where filesystem writes go into a temporary or persistent copy-on-write overlay. Everything is accomplished with the dmsetup command. LVM is not involved (although it also uses Device-mapper technology).

A LiveOS installed device will have a /LiveOS/ directory in it's base filesystem. The /LiveOS/squashfs.img file contains a compressed (and read-only) ext4 filesystem that itself contains a /LiveOS/ directory and within that the distributed root filesystem in a file named ext3fs.img. So, the squashfs.img file contains a directory and file, /LiveOS/ext3fs.img, that itself contains the root filesystem (with /bin, /boot, /dev, /etc, /home, ...).

If there is a persistent overlay file installed on the device, it will be saved as
        /LiveOS/overlay-<LABEL>-<UUID>
where LABEL and UUID are the device partition label and UUID as reported by the following command,
        lsblk -o LABEL,UUID

One can programmatically

  1. loop mount the squashfs.img file, then
  2. set up a loop device for the ext3fs.img file found in mount 1.
  3. If there is no persistent overlay, you may simply mount the ext3fs.img file or loop device from
    step 2 (the read-only, base image).
  4. If there is a persistent overlay file, set up a loop device for it.
  5. Determine the size of the root filesystem in units of 512-byte sectors,

    blockdev --getsz <basefs_loop>

  6. Then setup a Device-mapper snapshot target with this general command,

    dmsetup create <target_name> --table "0 <size> snapshot <basefs_loop> <overlay_loop> P 8"

  7. Finally, mount the Device-mapper target on a desired mount point,

    mount /dev/mapper/<target_name> <mount point>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top