| 1 |
.\" -*- nroff -*- |
| 2 |
.\" Copyright 2001 by Theodore Ts'o. All Rights Reserved. |
| 3 |
.\" This file may be copied under the terms of the GNU Public License. |
| 4 |
.\" |
| 5 |
.TH E2IMAGE 8 "March 2025" "E2fsprogs version 1.47.4" |
| 6 |
.SH NAME |
| 7 |
e2image \- Save critical ext2/ext3/ext4 file system metadata to a file |
| 8 |
|
| 9 |
.SH SYNOPSIS |
| 10 |
.B e2image |
| 11 |
.RB [ \-r | \-Q " [" \-af ]] |
| 12 |
[ |
| 13 |
.B \-b |
| 14 |
.I superblock |
| 15 |
] |
| 16 |
[ |
| 17 |
.B \-B |
| 18 |
.I blocksize |
| 19 |
] |
| 20 |
[ |
| 21 |
.B \-cnps |
| 22 |
] |
| 23 |
[ |
| 24 |
.B \-o |
| 25 |
.I src_offset |
| 26 |
] |
| 27 |
[ |
| 28 |
.B \-O |
| 29 |
.I dest_offset |
| 30 |
] |
| 31 |
.I device |
| 32 |
.I image-file |
| 33 |
.br |
| 34 |
.B e2image |
| 35 |
.B \-I |
| 36 |
.I device |
| 37 |
.I image-file |
| 38 |
|
| 39 |
.SH DESCRIPTION |
| 40 |
The |
| 41 |
.B e2image |
| 42 |
program will save critical ext2, ext3, or ext4 file system metadata located on |
| 43 |
.I device |
| 44 |
to a file specified by |
| 45 |
.IR image-file . |
| 46 |
The image file may be examined by |
| 47 |
.B dumpe2fs |
| 48 |
and |
| 49 |
.BR debugfs , |
| 50 |
by using the |
| 51 |
.B \-i |
| 52 |
option to those programs. This can assist an expert in recovering |
| 53 |
catastrophically corrupted file systems. |
| 54 |
.PP |
| 55 |
It is a very good idea to create image files for all file systems on a |
| 56 |
system and save the partition layout (which can be generated using the |
| 57 |
.B fdisk \-l |
| 58 |
command) at regular intervals \(em at boot time, and/or every week or so. |
| 59 |
The image file should be stored on some file system other than |
| 60 |
the file system whose data it contains, to ensure that this data is |
| 61 |
accessible in the case where the file system has been badly damaged. |
| 62 |
.PP |
| 63 |
To save disk space, |
| 64 |
.B e2image |
| 65 |
creates the image file as a sparse file, or in QCOW2 format. Hence, if |
| 66 |
the sparse image file needs to be copied to another location, it should |
| 67 |
either be compressed first or copied using the |
| 68 |
.B \-\-sparse=always |
| 69 |
option to the GNU version of |
| 70 |
.BR cp (1). |
| 71 |
This does not apply to the QCOW2 image, which is not sparse. |
| 72 |
.PP |
| 73 |
The size of an ext2 image file depends primarily on the size of the |
| 74 |
file systems and how many inodes are in use. For a typical 10 Gigabyte |
| 75 |
file system, with 200,000 inodes in use out of 1.2 million inodes, the image |
| 76 |
file will be approximately 35 Megabytes; a 4 Gigabyte file system with 15,000 |
| 77 |
inodes in use out of 550,000 inodes will result in a 3 Megabyte image file. |
| 78 |
Image files tend to be quite compressible; an image file taking up 32 Megabytes |
| 79 |
of space on disk will generally compress down to 3 or 4 Megabytes. |
| 80 |
.PP |
| 81 |
If |
| 82 |
.I image-file |
| 83 |
is |
| 84 |
.BR \- , |
| 85 |
then the output of |
| 86 |
.B e2image |
| 87 |
will be sent to standard output, so that the output can be piped to |
| 88 |
another program, such as |
| 89 |
.BR gzip (1). |
| 90 |
(Note that this is currently only supported when |
| 91 |
creating a raw image file using the |
| 92 |
.B \-r |
| 93 |
option, since the process of creating a normal image file, or QCOW2 |
| 94 |
image currently |
| 95 |
requires random access to the file, which cannot be done using a |
| 96 |
pipe. |
| 97 |
|
| 98 |
.SH OPTIONS |
| 99 |
.TP |
| 100 |
.B \-a |
| 101 |
Include file data in the image file. Normally |
| 102 |
.B e2image |
| 103 |
only includes fs metadata, not regular file data. This option will |
| 104 |
produce an image that is suitable to use to clone the entire FS or |
| 105 |
for backup purposes. Note that this option only works with the |
| 106 |
raw |
| 107 |
.RI ( \-r ) |
| 108 |
or QCOW2 |
| 109 |
.RI ( \-Q ) |
| 110 |
formats. In conjunction with the |
| 111 |
.B \-r |
| 112 |
option it is possible to clone all and only the used blocks of one |
| 113 |
file system to another device/image file. |
| 114 |
.TP |
| 115 |
.BI \-b " superblock" |
| 116 |
Get image from partition with broken primary superblock by using |
| 117 |
the superblock located at file system block number |
| 118 |
.IR superblock . |
| 119 |
The partition is copied as-is including broken primary superblock. |
| 120 |
.TP |
| 121 |
.BI \-B " blocksize" |
| 122 |
Set the file system blocksize in bytes. Normally, |
| 123 |
.B e2image |
| 124 |
will search for the superblock at various different block sizes in an |
| 125 |
attempt to find the appropriate blocksize. This search can be fooled in |
| 126 |
some cases. This option forces e2fsck to only try locating the superblock |
| 127 |
with a particular blocksize. If the superblock is not found, e2image will |
| 128 |
terminate with a fatal error. |
| 129 |
.TP |
| 130 |
.B \-c |
| 131 |
Compare each block to be copied from the source |
| 132 |
.I device |
| 133 |
to the corresponding block in the target |
| 134 |
.IR image-file . |
| 135 |
If both are already the same, the write will be skipped. This is |
| 136 |
useful if the file system is being cloned to a flash-based storage device |
| 137 |
(where reads are very fast and where it is desirable to avoid unnecessary |
| 138 |
writes to reduce write wear on the device). |
| 139 |
.TP |
| 140 |
.B \-f |
| 141 |
Override the read-only requirement for the source file system when saving |
| 142 |
the image file using the |
| 143 |
.B \-r |
| 144 |
and |
| 145 |
.B \-Q |
| 146 |
options. Normally, if the source file system is in use, the resulting image |
| 147 |
file is very likely not going to be useful. In some cases where the source |
| 148 |
file system is in constant use this may be better than no image at all. |
| 149 |
.TP |
| 150 |
.B \-I |
| 151 |
install the metadata stored in the image file back to the device. |
| 152 |
It can be used to restore the file system metadata back to the device |
| 153 |
in emergency situations. |
| 154 |
.PP |
| 155 |
.B WARNING!!!! |
| 156 |
The |
| 157 |
.B \-I |
| 158 |
option should only be used as a desperation measure when other |
| 159 |
alternatives have failed. If the file system has changed since the image |
| 160 |
file was created, data |
| 161 |
.B will |
| 162 |
be lost. In general, you should make another full image backup of the |
| 163 |
file system first, in case you wish to try other recovery strategies afterward. |
| 164 |
.TP |
| 165 |
.B \-n |
| 166 |
Cause all image writes to be skipped, and instead only print the block |
| 167 |
numbers that would have been written. |
| 168 |
.TP |
| 169 |
.BI \-o " src_offset" |
| 170 |
Specify offset of the image to be read from the start of the source |
| 171 |
.I device |
| 172 |
in bytes. See |
| 173 |
.B OFFSETS |
| 174 |
for more details. |
| 175 |
.TP |
| 176 |
.BI \-O " tgt_offset" |
| 177 |
Specify offset of the image to be written from the start of the target |
| 178 |
.I image-file |
| 179 |
in bytes. See |
| 180 |
.B OFFSETS |
| 181 |
for more details. |
| 182 |
.TP |
| 183 |
.B \-p |
| 184 |
Show progress of image-file creation. |
| 185 |
.TP |
| 186 |
.B \-Q |
| 187 |
Create a QCOW2-format image file instead of a normal image file, suitable |
| 188 |
for use by virtual machine images, and other tools that can use the |
| 189 |
.B .qcow |
| 190 |
image format. See |
| 191 |
.B QCOW2 IMAGE FILES |
| 192 |
below for details. |
| 193 |
.TP |
| 194 |
.B \-r |
| 195 |
Create a raw image file instead of a normal image file. See |
| 196 |
.B RAW IMAGE FILES |
| 197 |
below for details. |
| 198 |
.TP |
| 199 |
.B \-s |
| 200 |
Scramble directory entries and zero out unused portions of the directory |
| 201 |
blocks in the written image file to avoid revealing information about |
| 202 |
the contents of the file system. However, this will prevent analysis of |
| 203 |
problems related to hash-tree indexed directories. |
| 204 |
|
| 205 |
.SH RAW IMAGE FILES |
| 206 |
The |
| 207 |
.B \-r |
| 208 |
option will create a raw image file, which differs |
| 209 |
from a normal image file in two ways. First, the file system metadata is |
| 210 |
placed in the same relative offset within |
| 211 |
.I image-file |
| 212 |
as it is in the |
| 213 |
.I device |
| 214 |
so that |
| 215 |
.BR debugfs (8), |
| 216 |
.BR dumpe2fs (8), |
| 217 |
.BR e2fsck (8), |
| 218 |
.BR losetup (8), |
| 219 |
etc. can be run directly on the raw image file. In order to minimize |
| 220 |
the amount of disk space consumed by the raw image file, it is |
| 221 |
created as a sparse file. (Beware of copying or |
| 222 |
compressing/decompressing this file with utilities that don't understand |
| 223 |
how to create sparse files; the file will become as large as the |
| 224 |
file system itself!) Secondly, the raw image file also includes indirect |
| 225 |
blocks and directory blocks, which the standard image file does not have. |
| 226 |
.PP |
| 227 |
Raw image files are sometimes used when sending file systems to the maintainer |
| 228 |
as part of bug reports to e2fsprogs. When used in this capacity, the |
| 229 |
recommended command is as follows (replace |
| 230 |
.B hda1 |
| 231 |
with the appropriate device for your system): |
| 232 |
.PP |
| 233 |
\fBe2image \-r /dev/hda1 \- | bzip2 > hda1.e2i.bz2\fR |
| 234 |
.PP |
| 235 |
This will only send the metadata information, without any data blocks. |
| 236 |
However, the filenames in the directory blocks can still reveal |
| 237 |
information about the contents of the file system that the bug reporter |
| 238 |
may wish to keep confidential. To address this concern, the |
| 239 |
.B \-s |
| 240 |
option can be specified to scramble the filenames in the image. |
| 241 |
.PP |
| 242 |
Note that this will work even if you substitute |
| 243 |
.B /dev/hda1 |
| 244 |
for another raw |
| 245 |
disk image, or QCOW2 image previously created by |
| 246 |
.BR e2image . |
| 247 |
|
| 248 |
.SH QCOW2 IMAGE FILES |
| 249 |
The |
| 250 |
.B \-Q |
| 251 |
option will create a QCOW2 image file instead of a normal, or raw image file. |
| 252 |
A QCOW2 image contains all the information the raw image does, however unlike |
| 253 |
the raw image it is not sparse. The QCOW2 image minimize the amount of space |
| 254 |
used by the image by storing it in special format which packs data closely |
| 255 |
together, hence avoiding holes while still minimizing size. |
| 256 |
.PP |
| 257 |
In order to send file system to the maintainer as a part of bug report to |
| 258 |
e2fsprogs, use following commands (replace |
| 259 |
.B hda1 |
| 260 |
with the appropriate device for your system): |
| 261 |
.PP |
| 262 |
\& \fBe2image \-Q /dev/hda1 hda1.qcow2\fR |
| 263 |
.br |
| 264 |
\& \fBbzip2 -z hda1.qcow2\fR |
| 265 |
.PP |
| 266 |
This will only send the metadata information, without any data blocks. |
| 267 |
As described for |
| 268 |
.B RAW IMAGE FILES |
| 269 |
the |
| 270 |
.B \-s |
| 271 |
option can be specified to scramble the file system names in the image. |
| 272 |
.PP |
| 273 |
Note that the QCOW2 image created by |
| 274 |
.B e2image |
| 275 |
is a regular QCOW2 image and can be processed by tools aware of QCOW2 format |
| 276 |
such as for example |
| 277 |
.BR qemu-img . |
| 278 |
.PP |
| 279 |
You can convert a .qcow2 image into a raw image with: |
| 280 |
.PP |
| 281 |
\& \fBe2image \-r hda1.qcow2 hda1.raw\fR |
| 282 |
.br |
| 283 |
.PP |
| 284 |
This can be useful to write a QCOW2 image containing all data to a |
| 285 |
sparse image file where it can be loop mounted, or to a disk partition. |
| 286 |
Note that this may not work with QCOW2 images not generated by e2image. |
| 287 |
|
| 288 |
.SH OFFSETS |
| 289 |
Normally a file system starts at the beginning of a partition, and |
| 290 |
.B e2image |
| 291 |
is run on the partition. When working with image files, you don't |
| 292 |
have the option of using the partition device, so you can specify |
| 293 |
the offset where the file system starts directly with the |
| 294 |
.B \-o |
| 295 |
option. Similarly the |
| 296 |
.B \-O |
| 297 |
option specifies the offset that should be seeked to in the destination |
| 298 |
before writing the file system. |
| 299 |
.PP |
| 300 |
For example, if you have a |
| 301 |
.B dd |
| 302 |
image of a whole hard drive that contains an ext2 fs in a partition |
| 303 |
starting at 1 MiB, you can clone that image to a block device with: |
| 304 |
.PP |
| 305 |
\& \fBe2image \-aro 1048576 img /dev/sda1\fR |
| 306 |
.br |
| 307 |
.PP |
| 308 |
Or you can clone a file system from a block device into an image file, |
| 309 |
leaving room in the first MiB for a partition table with: |
| 310 |
.PP |
| 311 |
\& \fBe2image -arO 1048576 /dev/sda1 img\fR |
| 312 |
.br |
| 313 |
.PP |
| 314 |
If you specify at least one offset, and only one file, an in-place |
| 315 |
move will be performed, allowing you to safely move the file system |
| 316 |
from one offset to another. |
| 317 |
|
| 318 |
.SH AUTHOR |
| 319 |
.B e2image |
| 320 |
was written by Theodore Ts'o ([email protected]). |
| 321 |
|
| 322 |
.SH AVAILABILITY |
| 323 |
.B e2image |
| 324 |
is part of the e2fsprogs package and is available from |
| 325 |
http://e2fsprogs.sourceforge.net. |
| 326 |
|
| 327 |
.SH SEE ALSO |
| 328 |
.BR dumpe2fs (8), |
| 329 |
.BR debugfs (8), |
| 330 |
.BR e2fsck (8) |