Tag Archives: virt-rescue

Maximum qcow2 disk size

I don’t see this documented anywhere obvious, so I examined the source of qemu and performed some tests.

qemu stores the size in a 64 bit unsigned integer. However the qemu-img command line parsing code refuses to parse any number larger than 263-513 (9223372036854774784), and therefore that appears to be the largest disk size you can create:

$ qemu-img create -f qcow2 test1.img $((2**63-513))
Formatting 'test1.img', fmt=qcow2 size=9223372036854774784 encryption=off cluster_size=65536 
$ ll -h test1.img
-rw-r--r--. 1 rjones rjones 192K Oct  3 17:27 test1.img
$ guestfish -a test1.img run : blockdev-getsize64 /dev/sda

Interestingly things go horribly wrong as soon as you try to partition this:

$ virt-rescue test1.img
><rescue> parted /dev/vda print
Error: /dev/vda: unrecognised disk label                                  
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 9223372TB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
><rescue> parted /dev/vda mklabel gpt
$ # bang! back to the prompt!



Leave a comment

Filed under Uncategorized

virt-rescue — it works on blank files too

virt-rescue fires up a temporary virtual machine. You can attach any file as a virtual disk. That might be an existing virtual machine that you need to rescue. It also works on empty files, so you can partition those files as disk images:

$ truncate -s 10G test.img
$ virt-rescue -a test.img
[boot messages omitted]
Welcome to virt-rescue, the libguestfs rescue shell.

Note: The contents of / are the rescue appliance.
You have to mount the guest's partitions under /sysroot
before you can examine them.

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
><rescue> fdisk /dev/vda

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519

Command (m for help): p

Disk /dev/vda: 10.7 GB, 10737418240 bytes
16 heads, 63 sectors/track, 20805 cylinders, total 20971520 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: 0xfc153d75

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048    20971519    10484736   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
[   79.089501]  vda: vda1
Syncing disks.

><rescue> pvcreate /dev/vda1
  Writing physical volume data to disk "/dev/vda1"
  Physical volume "/dev/vda1" successfully created

><rescue> exit

$ file test.img
test.img: x86 boot sector; partition 1: ID=0x83, 
starthead 0, startsector 2048, 20969472 sectors,
extended partition table (last)11, code offset 0x0

If you want to automate all of this, it’s much better to use guestfish.

Leave a comment

Filed under Uncategorized

Quick tip: Display default libguestfs appliance memory size

$ guestfish get-memsize

(size shown in megabytes). This is useful for example when using the virt-rescue –memsize option.

Leave a comment

Filed under Uncategorized

Tip: Get Ctrl-C working in virt-rescue

We need to fix virt-rescue so that ^C works. It needs some Perl hacking though.

In the meantime, Ray Strode just pointed out that this works:

><rescue> setsid bash < /dev/ttyS0 

Leave a comment

Filed under Uncategorized

Freezing filesystems

Ric Wheeler and Christoph Hellwig were quick to point out I was wrong about something: Linux now has a standard API for freezing or “quiescing” filesystems.

Quiescing a filesystem lets you take a consistent snapshot or backup at the block device level. If your server uses SAN storage, then probably your SAN lets you take snapshots of the SCSI LUNs at any time. But if you try doing this while the server is under load you’ll (at best) get a “crash consistent” snapshot, where the journal has to be replayed when the copy of the filesystem is mounted, and at worst you’ll get data corruption, particularly with ext3 defaults.

Quiescing tells the filesystem to make things consistent at the disk / block device level. The journal won’t need to be replayed, and the superblock is marked as if you’d unmounted the device. A snapshot taken at this stage will be consistent, at least at the filesystem level (applications don’t know what is happening, so you could still see things like half-written transactions in databases).

The downside to quiescing a filesystem is that it generally causes writes to be blocked, eventually bringing the whole system to a grinding halt. SAN snapshots can be done very quickly though, so the time between a “freeze” and “thaw” operation is usually brief.

Very recent versions of util-linux-ng have an fsfreeze command that lets you freeze or thaw filesystems at the command line. Use with care!

Freezing filesystems also has an application for virtual machines. Our new guest agent will support freezing filesystems so that you can coordinate a consistent backup or snapshot from outside the guest.

If you have Rawhide and the most recent virt-rescue you can play with freezing filesystems without breaking anything:

$ rm -f test.img
$ truncate -s 1G test.img
$ virt-rescue test.img
><rescue> mkfs.ext4 /dev/vda
><rescue> mount /dev/vda /sysroot

From another window you can see that the image is not consistent. If you were to snapshot the image now the filesystem would at least require journal recovery when mounted:

$ file test.img
test.img: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (large files) (huge files)

But by issuing fsfreeze in the guest we can make it consistent:

><rescue> fsfreeze -f /sysroot
$ file test.img
test.img: Linux rev 1.0 ext4 filesystem data (extents) (large files) (huge files)

.. allowing us to take a snapshot or copy of the block device (test.img) in a consistent state.

Leave a comment

Filed under Uncategorized

virt-rescue doc refresh

virt-rescue is like a Rescue CD, but for virtual machines, and without the need for a CD. I refreshed the virt-rescue documentation yesterday to make it clearer and provide more examples.

I also added the -m option, --append option and --selinux option. The first allows you to provide more memory to the virtual appliance. The second lets you specify extra Linux boot arguments. The third enables SELinux support.

Leave a comment

Filed under Uncategorized

guestfish kicks ass .. maybe

Glauber “glommer” Costa says guestfish is “the most kicking ass software ever”. Cheers Glauber. I wrote virt-rescue for glommer because he wanted to “fsck” interactively to fix his broken virtual machine. Libguestfs wasn’t designed for making ad-hoc interactive changes, but glommer gave me the idea that we could reuse the libguestfs appliance quite easily to make an interactive rescue shell for virtual machines, analogous to the rescue CDs that are common for physical machines. And so virt-rescue came about.

Another couple of articles have appeared about libguestfs recently. This article [pdf] is the better one written by Red Hat’s Sadique Puthen for Linux For You magazine.

The not so good one appeared in SearchEnterpriseLinux.com and is little more than blogspam, and I speak as someone who used to write similar trash (it’s very attractive to Google, and before Red Hat I used to work in SEO). I don’t think the author actually tried guestfish or libguestfs, it seems he just copied stuff out from our manpages. I doubt SearchEnterpriseLinux care since it is my opinion that they exist to make widely syndicated spam articles just to attract page views by misleading users of search engines.


Filed under Uncategorized