Gute Software warnt ohne zu bevormunden.
Schlechte Software bevormundet ohne zu warnen.

Even though I like ZFS, I am using Linux which has not yet good ZFS-Support, and LUKS. Using LUKS with an encrypted swap I want to be able to use for suspending, still the easiest possibility to achieve this is using an LVM [yes, this sentence is gramatically correct ...].

However, so far I only used this on one partition, which is already very flexible. Today I tried to use LVM on three USB-Sticks that I found occasionally. As they have different sizes, there is no point in creating a Raid, so I just used them directly.

So, I have three USB-Sticks, of different size, /dev/sdb, /dev/sdc, /dev/sdd. Firstly, I create the physical volumes on them:

root@thinkpad:/# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
root@thinkpad:/# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created
root@thinkpad:/# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created

Then I create the volume group:

root@thinkpad:/# vgcreate vgusb1 /dev/sdb /dev/sdc /dev/sdd
  Volume group "vgusb1" successfully created

(Actually, a lot of rw-errors are emitted, but they are pointless, and I left them out, and I will leave them out in the further commands.)

Then I create a logical volume, with 40% of the size of the whole volume group:

# lvcreate -l 40%FREE -n test vgusb1
  Logical volume "test" created

Let us make an ext4 filesystem on it:

root@thinkpad:/# mkfs.ext4 /dev/vgusb1/test
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
64512 inodes, 258048 blocks
12902 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
8064 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

root@thinkpad:/# mount /dev/vgusb1/test /mnt

So, now I have the filesystem. Lets create a file with random content:

# dd if=/dev/urandom of=/mnt/rand bs=4K

Let us check the md5sum quickly

root@thinkpad:/# md5sum /mnt/rand
251e865156f990e10711f5ac3e10d0bd  /mnt/rand

Verilyyyyyyyyyyy... So now we will create a snapshot and assure ourselves that it has the same content:

root@thinkpad:/# lvcreate --snapshot /dev/vgusb1/test -n snap -l 40%VG
  Logical volume "snap" created
root@thinkpad:/# mount /dev/vgusb1/snap /mnt2/
root@thinkpad:/# md5sum /mnt2/rand
251e865156f990e10711f5ac3e10d0bd  /mnt2/rand

Ok. Now we have a snapshot. Let us unmount the original and extend it to the maximum size, and resize the ext4 filesystem.

root@thinkpad:/# umount /mnt
root@thinkpad:/# umount /mnt2
root@thinkpad:/# lvchange -a n /dev/vgusb1/test       
root@thinkpad:/# lvextend -l +100%FREE /dev/vgusb1/test
  Extending logical volume test to 1.48 GiB
  Logical volume test successfully resized
root@thinkpad:/# e2fsck -f /dev/vgusb1/test
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgusb1/test: 12/64512 files (0.0% non-contiguous), 258045/258048 blocks
root@thinkpad:/# resize2fs /dev/vgusb1/test
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vgusb1/test to 387072 (4k) blocks.
The filesystem on /dev/vgusb1/test is now 387072 blocks long.
root@thinkpad:/# mount /dev/vgusb1/test /mnt
root@thinkpad:/# mount /dev/vgusb1/snap /mnt2

And now, let us fill /mnt/rand with new random information

# dd if=/dev/urandom of=/mnt/rand bs=4k

And check the checksums again

root@thinkpad:/# md5sum /mnt2/rand
251e865156f990e10711f5ac3e10d0bd  /mnt2/rand
root@thinkpad:/# md5sum /mnt/rand
55ee3477277947183c60d7190536f5c5  /mnt/rand

Snapshotting apparently worked. Apparently, it still works, when I unplug the sticks and plug them in again in a different order, and they get different devicenames.

LVM is nice.