Archive for February, 2009

Linux – Burn DL DVD+R media with custom layer break

Thursday, February 12th, 2009

To burn Dual-Layer (or Double-Layer, of you stick to the official name for DVD+R) medias, I use growisofs.

The syntax is as follow:

growisofs -dvd-compat -use-the-force-luke=break:1913760 -Z /dev/scd0=file.iso

Change the break blocks to match your own values, and replace the file.iso with the actual name of your ISO file.

If you do not set layer break manually, it will be automatically selected, so if you don’t know why you want one, you probably don’t, and have nothing to fear.

I use growisofs version 7.0.1 with genisoimage version 1.1.9

Ubuntu Hardy 8.04 USB performance issues

Monday, February 9th, 2009

As the owner of a nice laptop running Hardy, I had a huge performance degradation when accessing USB storage devices. Speed could reach 1MB/s at most, and usually, half that speed.

The trick that solved my problem was suggested in this post, and after I have tested it, I was happy with the results.

The trick is to backup the old ehci_hcd.ko module aside, and to replace it with the one from kernel 2.6.24-19-generic. Following that action, you need to make sure this module can force load, else version mismatch whill prevent it from loading.

To do so, I have added the following line to /etc/modprobe.d/options:

install ehci_hcd /sbin/modprobe –ignore-install –force ehci_hcd

This solves the force load issues.

Relocating LVs with snapshots

Monday, February 2nd, 2009

Linux LVM is a wonderful thing. It is scalable, flexible, and truly, almost enterprise-class in every details. It lacks, of course, at IO performance for LVM snapshots, but this can be worked-around in several creative ways (if I haven’t shown here before, I will sometime).

What it can’t do is dealing with a mixture of Stripes, Mirrors and Snapshots in a single logical volume. It cannot allow you to mirror a stripped LV (even if you can follow the requirementes), it cannot allow you to snapshot a mirrored or a stripped volume. You get the idea. A volume you can protect, you cannot snapshot. A volume with snapshots cannot be mirrored or altered.

For the normal user, what you get is usually enough. For storage management per-se, this is just not enough. When I wanted to reduce a VG – remove a disk from an existing volume group,  I had to evacuate it from any existing logical volume. The command to perform this actions is ‘pvmove‘ which is capable of relocating data from within a PV to other PVs. This is done through mirroring each logical volume and then removing the origin.

Mirroring, however, cannot be performed on LVs with snapshots, or on an already mirrored LV, so these require different handling.

We can detect which LVs reside on our physical volume by issuing the following command

pvdisplay -m /dev/sdf1

/dev/sdf1 was only an example. You will see the contents of this PV. So next, performing

pvmove /dev/sdf1

would attempt to relocate every existing LV from this specific PV to any other available PV. We can use this command to change the disk balance and allocations on multi-disk volume groups. This will be discussed on a later post.

Following a ‘pvmove‘ command, all linear volumes are relocated, if space permits, to another PVs. The remaining LVs are either mirrored or LVs with snapshots.

To relocate a mirrored LV, you need to un-mirror it first. To do so, first detect using ‘pvdisplay‘ which LV is belongs to (the name should be easy to follow) and then change it to non-mirrored.

lvconvert -m0 /dev/VolGroup00/test-mirror

This will convert it to be a linear volume instead of a mirror, so you could move it, if it still resides on the PV you are to remove.

Snapshot volumes are more complicated, due to their nature. Since all my snapshots are of a filesystem, I could allow myself to use tar to perform the action.

The steps are as follow:

  1. tar the contents of the snapshot source to nowhere, but save an incremental file
  2. Copy the source incremental file to a new name, and tar the contents of a snapshot according to this copy.
  3. Repeat the previous step for each snapshot.
  4. Remove all snapshots
  5. Relocate the snapshot source using ‘pvmove
  6. Build the snapshots and then recover the data into them

This is a script to do steps 1 to 3. It will not remove LVs, for obvious reasons. This script was not tested, but should work, of course 🙂

None of the LVs should be mounted for it to function. It’s better to have harder requirements than to destroy data by double-mounting it, or accessing it while it is being changed.

# Get: VG Base-LV, snapshot name, snapshot name, snapshot name...
# Example:
# ./backup VolGroup00 base snap1 snap2 snap3
# Written by Ez-Aton

if [ "[email protected]" -le 3 ]
   echo "Parameters: $0 VG base snap snap snap snap"
   exit 1
shift 2

function check_not_mounted () {
   # Check if partition is mounted
   if mount | grep /dev/mapper/${VG}-${1}
      return 0
      return 1

function create_base_diff () {
   # This function will create the diff file for the base
   mount /dev/${VG}/${BASE} $MNT
   if [ $? -ne 0 ]
      echo "Failed to mount base"
      exit 1
   cd $MNT
   tar -g $TARGET/${BASE}.tar.gz.diff -czf - . > /dev/null
   cd -
   umount $MNT

function create_snap_diff () {
   mount /dev/${VG}/${1} $MNT
   if [ $? -ne 0 ]
      echo "Failed to mount base"
      exit 1
   cp $TARGET/${BASE}.tar.gz.diff $TARGET/$1.tar.gz.diff
   cd $MNT
   tar -g $TARGET/${1}.tar.gz.diff -czf $TARGET/${1}.tar.gz .
   cd -
   umount $MNT

function create_mount () {
   # Creates a temporary mount point
   if [ ! -d /mnt/$$ ]
      mkdir /mnt/$$

if check_not_mounted $BASE
   echo "$BASE is mounted. Exiting now"
   exit 1
for i in [email protected]
   if check_not_mounted $i
      create_snap_diff $i
      echo "$i is mounted! I will not touch it!"

The remaining steps should be rather easy – just mount the newly created snapshots and restore the tar file on them.