Skip to main content
added 1019 characters in body
Source Link
ephemient
  • 16.4k
  • 5
  • 54
  • 39

There is a new dm target called "snapshot-merge".

If you format your USB flash memory as a LVM physical volume, and then locate your desired filesystem atop it in a logical volume, you can

  1. Activate a volume group containing your USB flash memory and another LVM physical volume on a local disk.
  2. Create a snapshot of the logical volume on the local disk.
  3. Mount the snapshot, do whatever you want with it, then umount it.
  4. Merge the snapshot back to the origin.

This should achieve close to what you've asked for, although it requires a scratch block device rather than a temporary directory.


Substitute the parts enclosed in {braces} as appropriate.


# Initial setup of the USB drive.
pvcreate /dev/{USB}
vgcreate {removable} /dev/{USB}
lvcreate -n {base} -l 100%PVS {removable} /dev/{USB}
mkfs -t {fs} {...} /dev/mapper/{removable}-{base}

# Initial setup of the scratch device.
pvcreate /dev/{SCRATCH}

# Mounting the device.
vgextend {removable} /dev/{SCRATCH}
lvcreate -s -n {snap} -l 100%ORIGIN /dev/mapper/{removable}-{base} /dev/{SCRATCH}
mount -t {fs} -o {...} /dev/mapper/{removable}-{snap} {MOUNTPOINT}

# Unmounting the device.
umount {MOUNTPOINT}
lvconvert --merge /dev/mapper/{removable}-{snap}
vgreduce {removable} /dev/{SCRATCH}
vgchange -a n {removable}

Untested, but all the LVM commands have manpages so you should be able to figure things out from here. You might need a vgscan invocation in there somewhere, if the volume group doesn't get automatically detected when you plug the USB drive in.

There is a new dm target called "snapshot-merge".

If you format your USB flash memory as a LVM physical volume, and then locate your desired filesystem atop it in a logical volume, you can

  1. Activate a volume group containing your USB flash memory and another LVM physical volume on a local disk.
  2. Create a snapshot of the logical volume on the local disk.
  3. Mount the snapshot, do whatever you want with it, then umount it.
  4. Merge the snapshot back to the origin.

This should achieve close to what you've asked for, although it requires a scratch block device rather than a temporary directory.

There is a new dm target called "snapshot-merge".

If you format your USB flash memory as a LVM physical volume, and then locate your desired filesystem atop it in a logical volume, you can

  1. Activate a volume group containing your USB flash memory and another LVM physical volume on a local disk.
  2. Create a snapshot of the logical volume on the local disk.
  3. Mount the snapshot, do whatever you want with it, then umount it.
  4. Merge the snapshot back to the origin.

This should achieve close to what you've asked for, although it requires a scratch block device rather than a temporary directory.


Substitute the parts enclosed in {braces} as appropriate.


# Initial setup of the USB drive.
pvcreate /dev/{USB}
vgcreate {removable} /dev/{USB}
lvcreate -n {base} -l 100%PVS {removable} /dev/{USB}
mkfs -t {fs} {...} /dev/mapper/{removable}-{base}

# Initial setup of the scratch device.
pvcreate /dev/{SCRATCH}

# Mounting the device.
vgextend {removable} /dev/{SCRATCH}
lvcreate -s -n {snap} -l 100%ORIGIN /dev/mapper/{removable}-{base} /dev/{SCRATCH}
mount -t {fs} -o {...} /dev/mapper/{removable}-{snap} {MOUNTPOINT}

# Unmounting the device.
umount {MOUNTPOINT}
lvconvert --merge /dev/mapper/{removable}-{snap}
vgreduce {removable} /dev/{SCRATCH}
vgchange -a n {removable}

Untested, but all the LVM commands have manpages so you should be able to figure things out from here. You might need a vgscan invocation in there somewhere, if the volume group doesn't get automatically detected when you plug the USB drive in.

Source Link
ephemient
  • 16.4k
  • 5
  • 54
  • 39

There is a new dm target called "snapshot-merge".

If you format your USB flash memory as a LVM physical volume, and then locate your desired filesystem atop it in a logical volume, you can

  1. Activate a volume group containing your USB flash memory and another LVM physical volume on a local disk.
  2. Create a snapshot of the logical volume on the local disk.
  3. Mount the snapshot, do whatever you want with it, then umount it.
  4. Merge the snapshot back to the origin.

This should achieve close to what you've asked for, although it requires a scratch block device rather than a temporary directory.