Batch-converting images

June 29, 2010

I had a wad of images that I needed to resize from 300dpi and high-resolution jpg to 4.5×6 (or 6×4.5) low resolution at 72 dpi.

First, I installed ImageMagick:
sudo aptitude install imagemagick

Then I opened GIMP and determined the pixel width and height of one image. (Image -> Canvas Size). In my case, it was 3264×2448.

Next, I resized the image to the size I wanted. That turned out to be 432×324.

In other words, I wanted my new images to be 0.132352941 of the original image. A quick test told me I was on the right track:

convert P4250049.JPG -resize 13.2352941% test.jpg

The first time I did this I forgot the % sign and got a 13×10 pixel image – not exactly what I wanted.

So, on to batch-converting everything in a directory:

mkdir ./resized
for i in *.JPG; do
echo $i
convert $i -resize 13.235941% -quality 20 ./resized/$i

And all my resized images were in the resized directory below the image directory. (Did I mention I wanted to reduce the quality so my images would be smaller too? Yep, that’s what the -quality line does.)

Backing up a disk with SysRescCD

June 20, 2010

The documentation for the very good SysRescCD has changed, so I can’t find the standard “here’s how to back up a disk” using sfdisk and partimage anymore.

Luckily, it got saved here:

For future reference, this is a good way to back up a disk.

  1. Boot the machine with the disk using SysRescCD.
  2. Mount a big NFS/CIFS drive.
  3. Copy the MBR:
    dd if=/dev/sda of=/cifs/sda.mbr count=1 bs=512
  4. Copy the partition table from the drive:
     sfdisk -d /dev/sda > /cifs/sda.sfdisk
  5. Run partimage on each partition on the drive
  6. Finally, for good measure,
    dd if=/dev/sda | gzip > /cifs/sda.dd.gz

You can use kill -USR1 pid on the dd process id (not the gzip process id) to see progress.

Most of the restore is straightforward. sfdisk can take its output as input; partimage has restore built in. To decompress the gzip dd image, use:

gzip -dc /cifs/sda.dd.gz | dd of=/dev/sda

Incidentally, a good site for dd information is here:

Setting disk labels in Linux

June 5, 2010

Back in December, I wrote about setting UUIDs so multiple disks could be mounted in the same place using /etc/fstab.

I’ve since decided that was dumb. Disks should have unique UUIDs – Linux may use that for more than just mounting the file system. Luckily, there is a better option: the disk label.

Mounting a disk using the disk label is very similar to mounting using UUIDs. First, you need to give the disk a label. I think you can do that when you mkfs, but it’s pretty cheap to do it after you’ve already bulit the file system using:

e2label /dev/sdb1 mylabel

(substituting whatever device you want for /dev/sdb1 and whatever label you want for mylabel. This will work for ext2, ext3 and ext4 – if you’re using another file system, it should have its own label utility.)

Then, rather than specifying UUID= in /etc/fstab, specify:


Your disk will mount automatically, but still have a unique ID. Sounds better to me.

Sun has a useful tutorial at: