| 60 | = Compressing The Image = |
| 61 | |
| 62 | After getting everything installed on the image, it gets to be sizeable. The qcow2 image was 3+ GB. To reduce this, convert the image to a raw disk image |
| 63 | |
| 64 | {{{ |
| 65 | $ qemu-img convert -p -O raw pangolin.img pangolin.raw.img |
| 66 | }}} |
| 67 | |
| 68 | Now we need to run {{{zerofree}}} to clear out the dirty sectors. (zerofree is in the repo) |
| 69 | |
| 70 | I fooled around quite a bit with trying to boot a qemu instance from the qcow2 image and mount the raw image for zerofreeing. This failed in many ways. Attaching both disks always mounts the raw image and corrupts the qcow2. You can make teh qcow2 image a disk and boot from it, with the raw image on a USB disk, but the zerofree is too slow. |
| 71 | |
| 72 | Ultimately the easy way to do this was to mount the raw image through the loopback, using the mechanism [http://askubuntu.com/questions/69363/mount-disk-device-image here]. Basically: |
| 73 | |
| 74 | {{{ |
| 75 | $ fdisk -lu pangolin.raw.img |
| 76 | |
| 77 | Disk pangolin.raw.img: 10.7 GB, 10737418240 bytes |
| 78 | 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors |
| 79 | Units = sectors of 1 * 512 = 512 bytes |
| 80 | Sector size (logical/physical): 512 bytes / 512 bytes |
| 81 | I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 82 | Disk identifier: 0x0000b82d |
| 83 | |
| 84 | Device Boot Start End Blocks Id System |
| 85 | pangolin.raw.img1 * 2048 18874367 9436160 83 Linux |
| 86 | pangolin.raw.img2 18876414 20969471 1046529 5 Extended |
| 87 | pangolin.raw.img5 18876416 20969471 1046528 82 Linux swap / Solaris |
| 88 | $ dc |
| 89 | 512 2048 * p |
| 90 | 1048576 |
| 91 | # (sector size * start of partition) |
| 92 | $ sudo losetup -o 1048576 /dev/loop0 pangolin.raw.img |
| 93 | $ sudo mount /dev/loop0 /mnt |
| 94 | $ sudo zerofree -v /dev/loop0 |
| 95 | 247417/1655938/2359040 |
| 96 | $ sudo losetup -d /dev/loop0 |
| 97 | # Don't forget -c for compression |
| 98 | $ qemu-img convert -p -c -O qcow2 pangolin.raw.img pangolin-dev.img |
| 99 | }}} |
| 100 | |
| 101 | The resulting image is roughly 1.1 GB. A considerable savings. |