挂载 LVM 覆盖/快照?

发布于 2024-07-18 03:23:16 字数 1552 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柒七 2024-07-25 03:23:16

LVM 的卷概念不可跨系统移植,就像您可以将一些 md 驱动器拼凑在一起一样,它们仍然可以工作。 每个 LVM vg 都有一个唯一的标识符,您需要让系统的 LVM 接受它。 换句话说,LVM 无法“看到”卷组,直到您“告诉”它它的存在。 一旦你这样做了,接下来的事情应该会很顺利。

快照由记录的扇区增量组成。 您是对的,您应该能够通过同时显示原始文件和快照来显示您的快照。 快照本身是行不通的。

我假设您正在考虑一起编写脚本,因为您只需要 lvm 工具集来实现这一点。

一份小小的临别礼物,可以帮助你前行。 保存为/usr/sbin/lvms,设置所有者为root/root,chmod 755,用它来保存指尖。


#!/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

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
农村范ル 2024-07-25 03:23:16

Fedora LiveCD 或 LiveUSB 中的操作系统映像可以在暴露嵌入式根文件系统后挂载。 Fedora 的 livecd-tools 软件包提供了一个实用程序 liveimage-mount使用 Python 来完成此操作。

Fedora LiveOS 映像(Live CD/USB 操作系统)技术使用设备映射器快照目标来创建根文件系统的压缩只读副本,可在启动时进行读写安装,其中文件系统写入进入临时或持久的写时复制覆盖。 一切都是通过 dmsetup 命令完成的。 LVM不涉及(尽管它也使用Device-mapper技术)。

安装了 LiveOS 的设备的基本文件系统中将有一个 /LiveOS/ 目录。 /LiveOS/squashfs.img 文件包含一个压缩(且只读)的 ext4 文件系统,该文件系统本身包含一个 /LiveOS/ 目录,并且在该目录中名为 ext3fs.img 的文件中包含分布式根文件系统。 因此,squashfs.img 文件包含一个目录和文件 /LiveOS/ext3fs.img,它本身包含根文件系统(包含 /bin、/boot、/dev、/etc、/home,...)。

如果设备上安装了持久覆盖文件,它将另存为
       /LiveOS/overlay-

可以通过编程方式

  1. 循环挂载 squashfs.img 文件,然后
  2. 为 ext3fs 设置循环设备。在挂载 1 中找到 img 文件。
  3. 如果没有持久覆盖,您可以简单地挂载 ext3fs.img 文件或循环设备
    步骤 2(只读基础映像)。
  4. 如果存在持久覆盖文件,请为其设置循环设备。
  5. 确定根文件系统的大小(以 512 字节扇区为单位),

    blockdev --getsz

  6. 然后使用此通用命令设置设备映射器快照目标,

    dmsetup create <目标名称> --table "0snapshotP 8"

  7. 最后,将设备映射器目标挂载到所需的挂载点上,

    挂载 /dev/mapper/; <挂载点>

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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文