Nathan Shearer
Moving from RAW to QCOW2

Initially I created a few virtual machines as RAW images because I needed the performance advantage that RAW images had over QCOW2 images. Some of the recent performance improvements to QCOW2 have now made it worth it for me to switch from RAW to QCOW2. I have a few Windows virtual machines formatted with NTFS and I would like to take advantage of the fact that QCOW2 does not consume space to store empty sectors. But with these filesystems being relatively old the unused sectors are now mostly filled with random data. Fortunately the ntfsprogs package has a utility called ntfswipe which can wipe unused sectors! That's exactly what I need...

First I shut down the virtual machine with:

# /etc/init.d/qemu.vm-name stop

Then I create a backup of the RAW 25GB image.bin file. Always backup important data before you modify it!

# cp /home/virtual/vm-name/image.bin /home/virtual/vm-name/image.bin-backup

Now that we have a full backup I examine the partition table. I need to know where the filesystem begins:

# fdisk -lu image.bin

Disk image.bin: 26.2 GB, 26214400000 bytes
255 heads, 63 sectors/track, 3187 cylinders, total 51200000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa41da41d

    Device Boot      Start         End      Blocks   Id  System
image.bin1   *          63    51183089    25591513+   7  HPFS/NTFS/exFAT

This particular machine has only one partition and it starts on the 63rd sector. At 512 bytes per sector we can determine which byte the partition begins at 512*63 = 32256. So now I can use losetup to isolate the filesystem:

# losetup -o 32256 -f image.bin
# losetup -a
/dev/loop0: [0902]:40108049 (/home/virtual/vm-name/image.bin), offset 32256

Now I can use ntfswipe to erase the unused sectors:

# ntfswipe -uv /dev/loop0
ntfswipe is about to wipe:
        unused disk space

ntfswipe will overwrite these areas with: 0x00


ntfswipe will begin in 5 seconds, press CTRL-C to abort.

wipe_unused 0x00, 16120442880 bytes
16120442880 bytes were wiped

Delete the loopback device:

# losetup -d /dev/loop0

And convert the image from RAW to QCOW2. The QCOW2 image format will automatically ignore the sectors that were erased in the last few steps. My hard drives have 4096 byte physical sectors with 4096 byte RAID clusters with 4096 byte ext4 clusters. So I will set the QCOW cluster size to 4096 bytes too (for maximum performance).

# qemu-img convert -f raw -O qcow2 -o cluster_size=4096 image.bin image.qcow2

Now that you have a much smaller QCOW2 image all you need to do is update the /etc/conf.d/qemu.vm-name config file to use the new image and enjoy the extra features offered by the QCOW2 format. After all these steps were completed my 25GB image shrank to 8.8GB.

IPv6 on Gentoo

I successfully established IPv6 connectivity on my Gentoo system today using the tunnel broker provided by Freenet6 with their gateway6 client. I'm still experimenting with it to see how persistent my IPv6 address will be but I suspect I will be able to create a decentralized filesystem for backing up my important documents without too much effort.

The process to get it working was extremely simple (after the lengthy research was completed):

  1. Install the gateway6 client. On gentoo that's a simple "emerge gateway6" (unmask it if you need to)
  2. Start the gateway6 client. On gentoo it is located at /etc/init.d/gw6c
  3. Enjoy your 10/10 score at test-ipv6.com

I'm curious how many nodes I will need to create 1GB of satisfiably redundant storage. With that knowledge I should be able to scale it up to a few TB and benchmark the whole setup. I suspect the latency will be horrible but good enough for archival purposes.

Samsung CLP-310N on Linux with CUPS

Samsung says the printer is supported. Over one "computer eon" ago I installed it on my Dad's Ubunto machine and it was a fairly painless installation -- but I forgot all the details since then (sorry). Installing it on Gentoo in CUPS (without using Samsungs installer) was a bit more complicated.

First I assigned the printer a persistent IP on my network with dnsmasq. That step is fairly straight forward as it's the same process for any network printer. The only approach that resulted in a non-corrupted test page involved using Samsungs PPD file in their linux driver download and manually copying the files from the Samsung download that CUPS complained were missing as I printed test pages. The higher quality modes tried to work, but failed with some kind of interlacing artifact. The draft mode did work.

I will have to settle for draft mode for now. The printer claims to support 2400x600 DPI and getting that to work will probably involve hacking my own PPD file...

 

*Update

I've discovered that the foo2qpdl project has support for this printer and that it exists in portage! I emerged foo2qpdl with emerge net-print/foo2zjs and setup the printer with IPP and the PPD file provided by foo2qpdl. I set the print quality to the best I could (1200x1200) and it worked (in colour and greyscale)!

Converting a Windows Box into a RAW Print Server

If you ever find yourself needing to setup an old Windows machine as a print server (without sharing the printer using File and Printer Sharing) you can do it by downloading this little tool and installing it on the machine that the printer is connected. It works beautifully and is open source.

It listens on port 9100 and forwards the traffic to the printer just like a real print server would. It's very handy if you have some obscure printers and do not want to purchase a dedicated printer server for your network. As a quick tip: place the exe in your system32 folder before you run the install command.

Android vs. iPhone

Well it's finally happened. My old HTC TyTN II has stopped working. When I open the phone to type on the keyboard it rotates the screen but when I close the phone it does not rotate back. It's an old phone and has served me well.

I did loads of research before I decided on a replacement phone. First I thought long and hard about what I want to do with a phone and what i actually do with a phone. Turns out all I really did with my TyTN II was phone people, take pictures, and send text messages. This was good news because every phone worth anything does all three!

What I wanted in a phone was tough though. I wanted it all; I wanted a large high resolution screen, 8MP rear facing camera with some kind of flash capabilities, 1.3MP front facing camera, the ability to record 720p video and it had to be a GSM phone since all the Canadian carriers are switching to GSM. The only phone that had most of those features was the HTC EVO 4G. Unfortunately there is no GSM model, CDMA only. After comparing several phones (and considering both Android and iOS based phones) and building a nice table to help me decide I ended up going with the Google Nexus One.

Comparing spec for spec the Nexus One is significantly better or similar to the iPhone 4. It is significantly cheaper, it has a bigger screen, similar DPI, much better hardware, replaceable and expandable components and is a much more flexible device. There is no contract, no vendor lock in, and over all it is a better product.

I've never spent my own money on an Apple product. I tried hard to justify buying an iPhone 4 this time. But after considering the specs, price, and the Apple philosophy I just couldn't rationalize it. My main OS is Gentoo Linux and it runs anything (via qemu and wine) on anything. There is no reason for me to buy Mac hardware at a premium only to install a real operating system like Linux. And the iPhone 4 just didn't compare to the competition. Then all the stories of left-handed antenna issues and a software update to fix an old bug that does not improve the reception issue at all simply reinforced my decision.

Of all the 5MP GSM phones the Google Nexus One had the best community support in the xda-developers forums and it was the only one that had 720p capabilities. Before it arrived I was concerned about the screen being an AMOLED screen instead of a TFT LCD screen but after seeing it in real life I'm enjoying the deep blacks and excellent viewing angles it is capable of. This phone is an improvement in every way over my old TyTN II and since I bought it without signing any contracts I have the freedom to switch to the cheapest cellular carrier and upgrade my phone at any point in time without paying expensive penalties.

% Powered by Modulus %
© 2012 Nathan Shearer