\o/
Incompatible technology has become an increasing problem for businesses as hand-held email and phone devices are evolving into minicomputers that can do such things as download music, take pictures and surf the Web. In the past, businesses have been unwilling to support certain devices, like those with cameras, for instance, because of concerns employees could use them to document company secrets. ... A business email system can use a popular email standard known as IMAP to sync with an iPhone. While many large companies have the ability to activate IMAP, they have chosen not to because they are worried about exposing their mail servers to the public.
Incompatible technology has become an increasing problem for businesses as hand-held email and phone devices are evolving into minicomputers that can do such things as download music, take pictures and surf the Web. In the past, businesses have been unwilling to support certain devices, like those with cameras, for instance, because of concerns employees could use them to document company secrets. ... A business email system can use a popular email standard known as IMAP to sync with an iPhone. While many large companies have the ability to activate IMAP, they have chosen not to because they are worried about exposing their mail servers to the public.
set -e
dev=$1
luks=$(mktemp)
cryptdev=$(basename $dev)_crypt
pvsize=$(pvs -o pe_start,pv_size --units s --noheadings --nosuffix "$dev" awk ' print $1 + $2 ')
devsize=$(blockdev --getsz "$dev")
mchunk=8
The script takes the physical volume device to convert as an argument. Note there is no check for the validity of its value.
dd of="$luks" seek=$devsize count=0 bs=512 2> /dev/null
luksdev=$(losetup -f)
losetup "$luksdev" "$luks"
trap "losetup -d \"$luksdev\"; rm -f \"$luks\"" EXIT
Next, we create a sparse luks file the same size as the device (in case luksFormat would use the size somehow, but I believe it doesn’t), and a loopback device on this file. The trap is here to avoid leaving the loopback device and the file when an error occurs later (though during the conversion itself, it will be pointless).
cryptsetup luksFormat -q "$luksdev"
cryptsetup luksOpen "$luksdev" $ cryptdev _real
read start length crypt format key IVoff cdev offset <<EOF
$(dmsetup table $ cryptdev _real)
EOF
We create a LUKS device, so that we can get the encryption key ($key), and the size of the LUKS header ($offset). Note you need to add –showkey to the dmsetup table command on sid.
if [ $(expr $devsize - $pvsize) -lt $offset ]; then
echo Not enough free space after LVM physical volume
cryptsetup luksClose $ cryptdev _real
exit
fi
Check we have enough space after the LVM physical volume to offset everything by the size of the LUKS header. If not, you can still try again after you reduce the size of the LVM physical volume by an extent.
if [ $(expr $devsize % $offset % $mchunk) -gt 0 ]; then
echo Last
cryptsetup luksClose $ cryptdev _real
exit
fi
This is another check to avoid surprises at the end, when dealing with the last chunk. As the script is written for the moment, it doesn’t support cases where this last chunk is not a multiple of $mchunk. So we need to abort in these.
read major minor <<EOF
$(stat -t "$dev" awk ' print $10,$11 ')
EOF
maps=$(dmsetup deps awk -F: "/\($major, $minor\)/ print \$1 ")
dmsetup create $cryptdev <<EOF
0 $length linear $dev 0
EOF
dmsetup reload $ cryptdev _real <<EOF
$start $length crypt $format $key $IVoff $dev $offset
EOF
dmsetup resume $ cryptdev _real
for map in $ maps ; do
dmsetup table "$map" sed s,$major:$minor,/dev/mapper/$cryptdev, dmsetup reload "$map"
dmsetup resume "$map"
done
Here, we create the dev_crypt device mapper that is our fake LUKS device, which starts as a simple linear mapper and will end as a complete crypt mapper. This fake LUKS device is inserted as an intermediate mapper between the LVM device mapper and the real device. So, the LVM device mapper will have this fake LUKS device as backend, and, at the beginning, the fake LUKS device maps linearly to the real device.
Note we look for all device mappers using the real device as backend before creating the fake LUKS device to avoid finding the fake LUKS device in the list.
Also note dmsetup reload only loads a new table in the INACTIVE slot, and dmsetup resume makes this inactive table LIVE.
cursor=$length
chunk=$offset
while [ $cursor -gt 0 ]; do
cursor=$(expr $cursor - $chunk)
if [ $cursor -lt 0 ]; then
chunk=$(expr $chunk + $cursor)
cursor=0
fi
(
[ $cursor -ne 0 ] && echo 0 $cursor linear $dev 0
echo $cursor $chunk mirror core 1 $mchunk 2 $dev $cursor /dev/mapper/$ cryptdev _real $cursor
[ $cursor -lt $(expr $length - $chunk) ] && echo $(expr $cursor + $chunk) $(expr $length - $cursor - $chunk) crypt $format $key $(expr $IVoff + $cursor + $chunk) $dev $(expr $offset + $cursor + $chunk)
) dmsetup reload "$cryptdev"
dmsetup resume "$cryptdev"
chunks=$(expr $chunk / $mchunk)
while ! dmsetup status "$cryptdev" grep "$chunks/$chunks"; do
true
done
done
This is where the main work is done : moving the data around. We actually just let the device mapper deal with the data duplication, $offset blocks by $offset blocks ($offset being the LUKS header size), using a mirror target for the chunk being moved. So our disk looks like the following:
dmsetup status, dmsetup wait doesn’t seem to be very helpful here.
dmsetup reload "$cryptdev" <<EOF
$start $length crypt $format $key $IVoff $dev $offset
EOF
dmsetup resume "$cryptdev"
dmsetup remove "$ cryptdev _real"
dd if="$luks" of=$dev count=$offset bs=512 2> /dev/null
Final steps of the conversion : our dev_crypt device becomes a full LUKS volume, so we can remove dev_crypt_real and add the LUKS headers at the top of the device we converted.
At this moment, the LUKS volume is setup just as if it had been setup by cryptsetup. For LVM to recognize the change properly, you need to run pvscan. Once you ran it, you can do whatever you want with LVM.
Now, you may want to add the following to your /etc/crypttab file:
$cryptdev $dev none luks
i.e. hda5_crypt /dev/hda5 none luks if the device was /dev/hda5.
And if the LVM volume you converted contains your root filesystem, you should run (for Debian systems):
update-initramfs -u
I tested this successfully under qemu and will give it a shot on my laptop some time soon.
Now, because I had a hard time not finding much about the mirror target of the device mapper, here is what I could gather about it. The target syntax is as follows:
<logical_start_sector> <num_sectors> mirror [ core disk ] <num_params> <param> ... <num_mirrors> [ <destination > <start_sector> ] ...
logical_start_sector, num_sectors, destination and start_sector have the same meaning as in other targets.core and disk are two different log types (to track differences between mirrors), respectively in memory and on disk.num_params and params depend on the log type:
core, num_params can be either 1 or 2.region_size, which is the size (in blocks) of the chunks the mirror log tracks for synchronization. It can’t be less than the page size divided by 512, i.e. 8 on x86, must be a power of 2, and must not exceed num_sectors. Apparently, it is not a problem if num_sectors is not a multiple of region_size.sync or nosync, meaning of which I’m not sure. I think it determines whether the mirror should do the initial synchronization (sync) or not (nosync).disk, num_params can be either 2 or 3, with params being log_device (device where the logs are kept), region_size, as above, and an optional sync or nosync, as above too.num_mirrors is the number of mirrors and for each mirror, we have a pair destination and start_sector.
[ Update: after a quick look at the device mapper source code in Linus’s git tree, updated the mirror target description ]
People remembered that there is no scarcity in information goods except where they have created it. As evidence grew of the positive effects of free culture and the toll of information ownership, our communities decided that we were not well served by limits on the flow and development of knowledge. Accordingly, the gatekeepers and tax collectors for culture have withered away and were dismantled. We -- the consumers, creators, and re-creators -- have offered new, more ethical business models, have engaged in new methods of distribution, and have produced creative goods. Today, access to information is a simple matter of connecting someone to a network and a community: a technical problem that we know how to solve. Nobody pays for the "right" to hear music, read a book, watch a movie, or use a piece of software. Nobody is forced to choose between being a bad neighbor or friend and breaking copyright law. No artist, musician, or author sells a million copies of anything and no artist, musician, or author has a day job.Now it's your turn. Eben Moglen tell us to not stop until we're free. Let's paint a picture of what that free world looks like. Most importantly, let's challenge ourselves to find ways to make it possible.


Agua para todos...
During the walk, we witnessed what the people from the Delta have been
warning about for decades: the Delta is disappearing. The progressive overuse
of the river's flow, excessive irrigation, damm construction and degradation
is killing this unique place. The waters are slowly claiming what once was
theirs. An electricity line, at the beginning of our trip being at the end
of the beach starts approaching the sea, or viceversa, as you move southward,
to end up many metres inside the water. The old people in the Delta still
remember the 200m tall lighthouse in the Illa de Buda, which the sea
managed to devour.

Sunset at the salines del Delta
When we reached the Punta we could watch a beautiful sunset
over the mountains of Els Ports, and when it got dark and cold we
headed to Tortosa, the area's capital, which I had recently visited for the
first time for one of Softcatal 's
meetings. There, we had dinner at a bar and met Jordi and Anna for a while,
before going back to Ampolla, going to bed relatively early due to everyone
being very tired.

On Saturday, we decided to have a look at the Delta... from above. So we
drove to the top of the Cim del Caro, where we could admire a great
view over the flat farmlands of the Delta, and then found a nice trail which
took us to a nice forest, where we had lunch. After a visit to Alfara de
Carles, we went back to the house, had a great dinner and played fun games at
the table.
Unfortunately, Sunday morning was dedicated to cleaning up the mess in the
appartment and packing, as part of the group, the Jordis from Alcoi and the
twins, had to leave early. The remaining four Valencians decided to go to
Deltebre to have a local paella. It was quite good, although the bar
tender laughed at our request to eat directly from the paella, rejecting
dishes. Small cultural clash. ;)
I remember downloading and viewing the pictures of the trip a few days
after getting back in Val ncia, and then losing track of them. Last week,
while testing an EPIA board with some random hard drive, I suddenly realised
there was a big chance the pictures would be on that drive, and after some
search, I found them; I had been close to mkfs the disk a few minutes
before. I hadn't stopped blaming myself for misplacing these pictures, as they
remind me of this wonderful weekend. Luckily, they are back!
Going back to the state of the Delta, experts say it will be mostly gone
in 200 years. All of the Terres de l'Ebre have fought against the previous
government's "PHN" plan to divert part of the river's flow to the North and
South, to supply Barcelona, and specially the South of Val ncia, where the
developing of the coastal areas is out of control. I fear that whenever PP
regains power in Madrid, they will retake this idea. There is a lot of money
involved in building a 700 km long scar in our land. The Delta de
l'Ebre is a fantastic place which doesn't deserve a terrible fate like
this, only for the benefit of the usual suspects. As the good people of this
land would say...
Lo riu s vida. No al transvasament!

Next.