e2image restore file system metadata

3

I'm trying to recreate file system metadata on a virtual disk. I can save this metadata using e2image, and the e2image man page tells me I can use e2image -I to restore the file system. Unfortunately, the man page doesn't provide any information on how to use this argument. I've tried the following (command results indented for easier reading):

msk $ e2image /dev/nbd1 -I test.qcow2
  e2image 1.42.5 (29-Jul-2012)
  e2image: Wrong magic number for Ext2 Image Header while trying to open test.qcow2
msk $ sudo e2image /dev/nbd1 -I test.qcow2
  e2image 1.42.5 (29-Jul-2012)
  e2image: Wrong magic number for Ext2 Image Header while trying to open test.qcow2
msk $ sudo e2image test.qcow2 -I /dev/nbd1
  e2image 1.42.5 (29-Jul-2012)
  e2image: Wrong magic number for Ext2 Image Header while trying to open /dev/nbd1

My filesystem is in fact ext4, however the man page says the following:

The e2image program will save critical ext2, ext3, or ext4

I used the following command to create the image:

sudo e2image -Q /dev/mapper/nbd0p1 test.qcow2

mkingston

Posted 2013-09-06T14:33:44.973

Reputation: 372

Answers

3

e2image supports three different formats; by default, it creates a "normal" custom e2image file format. With -r it creates a large sparse file with metadata at proper offsets, and with -Q it creates a qcow2 format file. (The -Q option was added somewhat recently to make large filesystem images more portable).

Although it's not at all clear from the manpage, the -I option is only valid for a "normal" e2image file format - i.e. an image created without -r or -Q.

Since you have a qcow2 image, you can use qemu-img to write it back out onto a block device:

# qemu-img convert -O raw test.qcow2 /dev/nbd1

However, you should be aware that your e2image-generated image contains metadata only, i.e. no file data at all. You'll be writing out metadata which points to various blocks on /dev/nbd1 for file data, and files will therefore contain whatever data was previously in those blocks on /dev/nbd1.

So I've told you how to do it, but please be sure it's actually what you want to do!

Eric Sandeen

Posted 2013-09-06T14:33:44.973

Reputation: 66

Hi, thanks a lot for your answer. I did come to this conclusion about metadata after doing some reading about file systems. And thanks for the clarification re: command-line switches. – mkingston – 2013-09-15T21:10:14.480

In fact, for the record, file metadata is something I don't really want to keep, because I wanted to replace my files in the partition without consideration for their address on the device. So in conclusion, e2image is not really the tool I want to use. Thanks again for a clear answer, anyway. – mkingston – 2013-09-15T21:12:26.647

3

It's possible to restore a QCOW2 image created using e2image -Q using e2image -r. For example:

# e2image -Q /dev/sdb1 image.qcow2
# e2image -r image.qcow2 /dev/sdb2

Note that I tested this with version 1.42.12 of e2fsprogs.

As of >= 1.42.9, e2image also supports the -a flag which allows you to include filesystem data in addition to metadata:

# e2image -Qa /dev/sdb1 image-full.qcow2
# e2image -r image-full.qcow2 /dev/sdb2

I verified that in this case e2image -r writes only the allocated blocks back to the target, whereas qemu-img convert appears to write the entire logical filesystem. That can save a lot of I/O for partially utilized filesystems.

Greg

Posted 2013-09-06T14:33:44.973

Reputation: 31