https://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&feed=atom&action=historyExt4 VM Images - Revision history2024-03-29T13:24:18ZRevision history for this page on the wikiMediaWiki 1.19.24https://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8321&oldid=prevDjwong: /* Creating a The Smallest Image You Need */2014-02-28T02:11:27Z<p><span dir="auto"><span class="autocomment">Creating a The Smallest Image You Need</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 02:11, 28 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Various ext4 users have a particular use-case for system provisioning where they create a FS image, populate it with whatever files they want, and then want to reduce the image to a minimal one to conserve network bandwidth.  At deploy time the minimal image is copied to a disk and expanded with resize2fs to fill the whole disk.  There are a number of strategies to handle this operation, each with strengths and weaknesses; this guide attempts to present some of the better known solutions that have come up over the years.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Various ext4 users have a particular use-case for system provisioning where they create a FS image, populate it with whatever files they want, and then want to reduce the image to a minimal one to conserve network bandwidth.  At deploy time the minimal image is copied to a disk and expanded with resize2fs to fill the whole disk.  There are a number of strategies to handle this operation, each with strengths and weaknesses; this guide attempts to present some of the better known solutions that have come up over the years.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>= Creating <del class="diffchange diffchange-inline">a </del>The Smallest Image You Need =</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>= Creating The Smallest Image You Need =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>The easiest way to create a petite ext4 image is to create a filesystem that is slightly larger than the amount of data to be copied and then to copy the files in.  cp writes out the files on by one, with the result that fragmentation should be fairly low.  While it is still true that ext4 becomes less efficient when it's approaching ~90% full, the kernel driver's coping strategies are still better than that of resize2fs (see below).</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>The easiest way to create a petite ext4 image is to create a filesystem that is slightly larger than the amount of data to be copied and then to copy the files in.  cp writes out the files on by one, with the result that fragmentation should be fairly low.  While it is still true that ext4 becomes less efficient when it's approaching ~90% full, the kernel driver's coping strategies are still better than that of resize2fs (see below).</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8311&oldid=prevDjwong: /* Good Tools for Making Sparse Images: zerofree/fstrim */2014-02-18T22:25:52Z<p><span dir="auto"><span class="autocomment">Good Tools for Making Sparse Images: zerofree/fstrim</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 22:25, 18 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 23:</td>
<td colspan="2" class="diff-lineno">Line 23:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>With a recent enough QEMU (1.5?) one can present virtual disks to the guest via virtio-scsi, sym53c8xx, or ahci.  If the backing for the virtual disk (file on a FS, raw block device, etc.) supports discard/trim/unmap, qemu will detect this and enable the guest to pass those requests through to the storage.  QEMU 1.4 has it off by default, but I think 1.5 has it on by default.  Thanks to Calvin Walton for pointing this out.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>With a recent enough QEMU (1.5?) one can present virtual disks to the guest via virtio-scsi, sym53c8xx, or ahci.  If the backing for the virtual disk (file on a FS, raw block device, etc.) supports discard/trim/unmap, qemu will detect this and enable the guest to pass those requests through to the storage.  QEMU 1.4 has it off by default, but I think 1.5 has it on by default.  Thanks to Calvin Walton for pointing this out.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>== Good Tools for Making Sparse Images: <del class="diffchange diffchange-inline">zerofree/</del>fstrim ==</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>== Good Tools for Making Sparse Images: fstrim<ins class="diffchange diffchange-inline">/e2fsck/zerofree </ins>==</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>fstrim is a tool that instructs online filesystems to issue a discard/trim/unmap command for all unused blocks in the filesystem.  If the underlying storage supports it, this will result in the unused blocks being detached from the image or disk.  fstrim should work on raw devices; support for loopback-mounted file images was added to the kernel in 2013.  Note, however, that as of kernel 3.13 fstrim will not fall back to writing zeroes if the storage does not support discard/trim/unmap.  This may change in the near future. <del class="diffchange diffchange-inline"> </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>fstrim is a tool that instructs online filesystems to issue a discard/trim/unmap command for all unused blocks in the filesystem.  If the underlying storage supports it, this will result in the unused blocks being detached from the image or disk.  fstrim should work on raw devices; support for loopback-mounted file images was added to the kernel in 2013.  Note, however, that as of kernel 3.13 fstrim will not fall back to writing zeroes if the storage does not support discard/trim/unmap.  This may change in the near future.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>[http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/util/zerofree.c zerofree] is an offline tool for ext4 that reads the block bitmaps and writes zeroes to unused blocks.  Note that it does not (yet) support issuing discard/trim/unmap commands to the underlying storage the way that fstrim can<del class="diffchange diffchange-inline">.  djwong has a mutant zerofree that does, but hasn't submitted it to e2fsprogs as of early 2014</del>.  Ted T'so says that he uses [http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/compress-rootfs compress-rootfs] to maintains the VM root filesystem that he uses to test upstream ext4 changes. After updating to the latest Debian unstable package updates and installing the latest updates from the xfstests and e2fsprogs git repositories, he runs compress-rootfs which uses the zerofree.c program to compress the qcow2 root file system image that he use with kvm.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Recent versions of e2fsck have been taught to discard unused blocks after a full filesystem check.  The discard operation is performed during pass 5, and only if the filesystem doesn't contain recognizable errors.  Keep in mind that discarding the device may prevent further recovery if the filesystem has errors that are not known to the version of e2fsck.  To use this method, run <code>e2fsck -E discard</code>.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>[http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/util/zerofree.c zerofree] is an offline tool for ext4 that reads the block bitmaps and writes zeroes to unused blocks.  Note that it does not (yet) support issuing discard/trim/unmap commands to the underlying storage the way that fstrim can.  Ted T'so says that he uses [http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/compress-rootfs compress-rootfs] to maintains the VM root filesystem that he uses to test upstream ext4 changes. After updating to the latest Debian unstable package updates and installing the latest updates from the xfstests and e2fsprogs git repositories, he runs compress-rootfs which uses the zerofree.c program to compress the qcow2 root file system image that he use with kvm.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile ==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile ==</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8281&oldid=prevDjwong: /* Sparse Images */2014-02-16T00:33:47Z<p><span dir="auto"><span class="autocomment">Sparse Images</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:33, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 15:</td>
<td colspan="2" class="diff-lineno">Line 15:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Sparse Images =</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Sparse Images =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>In general, there are large parts of a filesystem that are unused and need not be copied around when transmitting filesystem images.  There are several ways in which a filesystem image can be said to be sparse: (1) the unused blocks have had zeroes written to them; (2) the underlying storage has been instructed not to map physical storage to the unused blocks and therefore returns zeroes (hopefully) for a disk read; or (3) the image lives on a filesystem and the underlying filesystem does not map a physical block to the logical block in the file.  Ideally, we'd be able to detect runs of unmapped blocks and runs of zeroed blocks <del class="diffchange diffchange-inline">and </del>avoid transmitting <del class="diffchange diffchange-inline">them wastefully</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>In general, there are large parts of a filesystem that are unused and need not be copied around when transmitting filesystem images.  There are several ways in which a filesystem image can be said to be sparse: (1) the unused blocks have had zeroes written to them; (2) the underlying storage has been instructed not to map physical storage to the unused blocks and therefore returns zeroes (hopefully) for a disk read; or (3) the image lives on a filesystem and the underlying filesystem does not map a physical block to the logical block in the file.  Ideally, we'd be able to detect runs of unmapped blocks and runs of <ins class="diffchange diffchange-inline">mapped but </ins>zeroed blocks <ins class="diffchange diffchange-inline">to </ins>avoid transmitting <ins class="diffchange diffchange-inline">data unnecessarily</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Underlying Storage ==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Underlying Storage ==</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8271&oldid=prevDjwong: /* Copying Sparse Images Around */2014-02-16T00:32:05Z<p><span dir="auto"><span class="autocomment">Copying Sparse Images Around</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:32, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 41:</td>
<td colspan="2" class="diff-lineno">Line 41:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>To copy a sparse FS image from one storage device to another, one can use <code>e2image -rap src_dev dest_dev</code> to copy only the blocks that are in use from src_dev to dest_dev.  Ted T'so also points out that the -c option compares blocks between src_dev and dest_dev, and copies the block if there's a discrepancy; apparently he was using this to keep two root FSes in sync with each other on his laptop.  This only works with newer versions of e2fsprogs, alas (1.42.9?).</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>To copy a sparse FS image from one storage device to another, one can use <code>e2image -rap src_dev dest_dev</code> to copy only the blocks that are in use from src_dev to dest_dev.  Ted T'so also points out that the -c option compares blocks between src_dev and dest_dev, and copies the block if there's a discrepancy; apparently he was using this to keep two root FSes in sync with each other on his laptop.  This only works with newer versions of e2fsprogs, alas (1.42.9?).</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>A neat way to copy a sparse FS image hosted atop a file is to use <code>rsync -S</code>.  The -S option tells rsync to look for runs of zeroes in the source file, and not to copy them to the destination file, regardless of whether or not the source <del class="diffchange diffchange-inline">file is sparse</del>.  If you know the source file is maximally sparse, you can also use <code>cp --sparse=always</code> to copy the file.  The --sparse option tells cp to read the extent map of the file to determine which data needn't be copied, though it only seems to query the <del class="diffchange diffchange-inline">extent </del>map <del class="diffchange diffchange-inline">functionality </del>if there's a large enough discrepancy between the source file's size and blocks allocated. <del class="diffchange diffchange-inline"> </del>For those wishing to send a compressed <del class="diffchange diffchange-inline">image</del>, <code>tar -S</code> <del class="diffchange diffchange-inline">can create </del>a sparse <del class="diffchange diffchange-inline">archive</del>.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>A neat way to copy a sparse FS image hosted atop a file <ins class="diffchange diffchange-inline">or device </ins>is to use <code>rsync -S</code>.  The -S option tells rsync to look for runs of zeroes in the source file, and not to copy them to the destination file, regardless of whether or not the source <ins class="diffchange diffchange-inline">has had its unused blocks unmapped</ins>.  <ins class="diffchange diffchange-inline">This is a little inefficient, since it doesn't query the file's logical block map.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>If you know the source <ins class="diffchange diffchange-inline">is a </ins>file <ins class="diffchange diffchange-inline">that </ins>is <ins class="diffchange diffchange-inline">also </ins>maximally <ins class="diffchange diffchange-inline">(or satisfactorily) </ins>sparse, you can also use <code>cp --sparse=always</code> to copy the file.  The --sparse option tells cp to read the extent map of the file to determine which data needn't be copied, though it only seems to query the <ins class="diffchange diffchange-inline">file's logical block </ins>map if there's a large enough discrepancy between the source file's size and blocks allocated.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>For those wishing to send a compressed <ins class="diffchange diffchange-inline">tarball</ins>, <code>tar -S</code> <ins class="diffchange diffchange-inline">creates </ins>a <ins class="diffchange diffchange-inline">tarball with </ins>sparse <ins class="diffchange diffchange-inline">files inside.  Like rsync, it looks for runs of zeroes to skip and doesn't query the file's logical block map</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Shrinking an FS to Minimal Size =</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Shrinking an FS to Minimal Size =</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8261&oldid=prevDjwong: /* Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile */2014-02-16T00:25:55Z<p><span dir="auto"><span class="autocomment">Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:25, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 34:</td>
<td colspan="2" class="diff-lineno">Line 34:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>While it is possible to zero out unused disk blocks by writing a lot of zeroes to a file and then deleting it, this is not a recommended way to do this!  First of all, building such a huge file requires the construction of an extent tree, which means that the filesystem ends up allocating disk blocks in order to zero unused disk blocks.  This is not efficient, and if you've not mounted with <code>-o discard</code>, the extent tree blocks are never zeroed.  This problem gets much worse on any filesystem that doesn't use extents (ext2/3).  The second problem is that ext4 remembers which block groups have never had blocks allocated, which enables e2fsck to skip checking whether the block group's free block count corresponds to the block bitmap.  This slows down e2fsck.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>While it is possible to zero out unused disk blocks by writing a lot of zeroes to a file and then deleting it, this is not a recommended way to do this!  First of all, building such a huge file requires the construction of an extent tree, which means that the filesystem ends up allocating disk blocks in order to zero unused disk blocks.  This is not efficient, and if you've not mounted with <code>-o discard</code>, the extent tree blocks are never zeroed.  This problem gets much worse on any filesystem that doesn't use extents (ext2/3).  The second problem is that ext4 remembers which block groups have never had blocks allocated, which enables e2fsck to skip checking whether the block group's free block count corresponds to the block bitmap.  This slows down e2fsck.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins style="color: red; font-weight: bold; text-decoration: none;">Kristian Hermansen mentioned this method in a G+ thread.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Copying Sparse Images Around ==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Copying Sparse Images Around ==</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8251&oldid=prevDjwong at 00:23, 16 February 20142014-02-16T00:23:27Z<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:23, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del style="color: red; font-weight: bold; text-decoration: none;">(djwong is still cleaning this up; readers beware)</del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del style="color: red; font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Overview =</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Overview =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8241&oldid=prevDjwong: /* Overview */2014-02-16T00:23:07Z<p><span dir="auto"><span class="autocomment">Overview</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:23, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Overview =</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Overview =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Warious </del>ext4 users have a particular use-case for system provisioning where they create a FS image, populate it with whatever files they want, and then want to reduce the image to a minimal one to conserve network bandwidth.  At deploy time the minimal image is copied to a disk and expanded with resize2fs to fill the whole disk.  There are a number of strategies to handle this operation, each with strengths and weaknesses.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">Various </ins>ext4 users have a particular use-case for system provisioning where they create a FS image, populate it with whatever files they want, and then want to reduce the image to a minimal one to conserve network bandwidth.  At deploy time the minimal image is copied to a disk and expanded with resize2fs to fill the whole disk.  There are a number of strategies to handle this operation, each with strengths and weaknesses<ins class="diffchange diffchange-inline">; this guide attempts to present some of the better known solutions that have come up over the years</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Creating a The Smallest Image You Need =</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>= Creating a The Smallest Image You Need =</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8231&oldid=prevDjwong: /* Other */2014-02-16T00:22:16Z<p><span dir="auto"><span class="autocomment">Other</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:22, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 57:</td>
<td colspan="2" class="diff-lineno">Line 57:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>The original discussion got started when Jon Bernard asked about OpenStack's interaction with ext4 resize2fs:</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>The original discussion got started when Jon Bernard asked about OpenStack's interaction with ext4 resize2fs:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>In order to support very large partitions, the filesystem is created with an abnormally large inode table so that large resizes would be possible.  I traced it to this <del class="diffchange diffchange-inline">commit</del>[<del class="diffchange diffchange-inline">1</del>] as best I can tell.  I assumed that additional inodes would be allocated along with block groups during an online resize, but that commit contradicts my current understanding.  </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>In order to support very large partitions, the filesystem is created with an abnormally large inode table so that large resizes would be possible.  I traced it to this [<ins class="diffchange diffchange-inline">https://github.com/openstack/diskimage-builder/commit/fb246a02eb2ed330d3cc37f5795b3ed026aabe07 commit</ins>] as best I can tell.  I assumed that additional inodes would be allocated along with block groups during an online resize, but that commit contradicts my current understanding.  </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Ted T'so replied (and djwong has cleaned up),</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Ted T'so replied (and djwong has cleaned up),</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Additional inodes *are* allocated as the file system is grown.  Whoever thought otherwise was wrong.  What happens is that there is a fixed number of inodes per block group.  When the file system is resized, either by growing or shrinking file system, as block groups are added or removed from the file system, the inodes are added or removed along with the block groups.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Additional inodes *are* allocated as the file system is grown.  Whoever thought otherwise was wrong.  What happens is that there is a fixed number of inodes per block group.  When the file system is resized, either by growing or shrinking file system, as block groups are added or removed from the file system, the inodes are added or removed along with the block groups.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del style="color: red; font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del style="color: red; font-weight: bold; text-decoration: none;">[1] https://github.com/openstack/diskimage-builder/commit/fb246a02eb2ed330d3cc37f5795b3ed026aabe07</del></div></td><td colspan="2"> </td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8221&oldid=prevDjwong: /* Good Tools for Making Sparse Images: zerofree/fstrim */2014-02-16T00:21:41Z<p><span dir="auto"><span class="autocomment">Good Tools for Making Sparse Images: zerofree/fstrim</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:21, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 29:</td>
<td colspan="2" class="diff-lineno">Line 29:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>fstrim is a tool that instructs online filesystems to issue a discard/trim/unmap command for all unused blocks in the filesystem.  If the underlying storage supports it, this will result in the unused blocks being detached from the image or disk.  fstrim should work on raw devices; support for loopback-mounted file images was added to the kernel in 2013.  Note, however, that as of kernel 3.13 fstrim will not fall back to writing zeroes if the storage does not support discard/trim/unmap.  This may change in the near future.   </div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>fstrim is a tool that instructs online filesystems to issue a discard/trim/unmap command for all unused blocks in the filesystem.  If the underlying storage supports it, this will result in the unused blocks being detached from the image or disk.  fstrim should work on raw devices; support for loopback-mounted file images was added to the kernel in 2013.  Note, however, that as of kernel 3.13 fstrim will not fall back to writing zeroes if the storage does not support discard/trim/unmap.  This may change in the near future.   </div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">zerofree</del>[<del class="diffchange diffchange-inline">1</del>] is an offline tool for ext4 that reads the block bitmaps and writes zeroes to unused blocks.  Note that it does not (yet) support issuing discard/trim/unmap commands to the underlying storage the way that fstrim can.  djwong has a mutant zerofree that does, but hasn't submitted it to e2fsprogs as of early 2014.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>[<ins class="diffchange diffchange-inline">http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/util/zerofree.c zerofree</ins>] is an offline tool for ext4 that reads the block bitmaps and writes zeroes to unused blocks.  Note that it does not (yet) support issuing discard/trim/unmap commands to the underlying storage the way that fstrim can.  djwong has a mutant zerofree that does, but hasn't submitted it to e2fsprogs as of early 2014<ins class="diffchange diffchange-inline">.  Ted T'so says that he uses [http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/compress-rootfs compress-rootfs] to maintains the VM root filesystem that he uses to test upstream ext4 changes. After updating to the latest Debian unstable package updates and installing the latest updates from the xfstests and e2fsprogs git repositories, he runs compress-rootfs which uses the zerofree.c program to compress the qcow2 root file system image that he use with kvm</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile ==</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>== Bad Tool for Making Sparse Images: cat /dev/zero > /mnt/bigfile ==</div></td></tr>
</table>Djwonghttps://ext4.wiki.kernel.org/index.php?title=Ext4_VM_Images&diff=8211&oldid=prevDjwong: /* Other Discussion */2014-02-16T00:18:25Z<p><span dir="auto"><span class="autocomment">Other Discussion</span></span></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 00:18, 16 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 53:</td>
<td colspan="2" class="diff-lineno">Line 53:</td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Ted T'so adds that the only time you should try to do an off-line resize2fs shrink is if you are shrinking the file system by a handful of blocks as part of converting a file system in place to use LVM or LUKS encryption, and you need to make room for some metadata blocks at the end of the partition.</div></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"><div>Ted T'so adds that the only time you should try to do an off-line resize2fs shrink is if you are shrinking the file system by a handful of blocks as part of converting a file system in place to use LVM or LUKS encryption, and you need to make room for some metadata blocks at the end of the partition.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>= Other <del class="diffchange diffchange-inline">Discussion </del>=</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>= Other =</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>Jon Bernard <del class="diffchange diffchange-inline">wrote,</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div><ins class="diffchange diffchange-inline">The original discussion got started when </ins>Jon Bernard <ins class="diffchange diffchange-inline">asked about OpenStack's interaction with ext4 resize2fs:</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del>In order to support very large partitions, the filesystem is created</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>In order to support very large partitions, the filesystem is created with an abnormally large inode table so that large resizes would be possible.  I traced it to this commit<ins class="diffchange diffchange-inline">[1] </ins>as best I can tell.  I assumed that additional inodes would be allocated along with block groups during an online resize, but that commit contradicts my current understanding.  </div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del>with an abnormally large inode table so that large resizes would be</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del>possible.  I traced it to this commit as best I can tell<del class="diffchange diffchange-inline">:</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">    https://github</del>.<del class="diffchange diffchange-inline">com/openstack/diskimage-builder/commit/fb246a02eb2ed330d3cc37f5795b3ed026aabe07</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>  I assumed that additional inodes would be allocated along with block</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del>groups during an online resize, but that commit contradicts my current</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline"> </del>understanding.  </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>Ted T'so replied (and djwong has cleaned up <del class="diffchange diffchange-inline">somewhat</del>),</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>Ted T'so replied (and djwong has cleaned up),</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>Additional inodes *are* allocated as the file system is grown.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>Additional inodes *are* allocated as the file system is grown. <ins class="diffchange diffchange-inline"> </ins>Whoever thought otherwise was wrong.  What happens is that there is a fixed number of inodes per block group.  When the file system is resized, either by growing or shrinking file system, as block groups are added or removed from the file system, the inodes are added or removed along with the block groups.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>Whoever thought otherwise was wrong.  What happens is that there is a</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>fixed number of inodes per block group.  When the file system is</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>resized, either by growing or shrinking file system, as block groups</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>are added or removed from the file system, the inodes are added or removed along with the block groups.</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'> </td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">What causes the least optimal data block layout is copying files into a large file system and then shrinking the file system to its minimum size with resize2fs -M.  resize2fs' block migration algorithm is pretty stupid -- all blocks that require moving are moved, one by one to the lowest available block, without any regards to file fragmentation.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>[1] <ins class="diffchange diffchange-inline">https</ins>://<ins class="diffchange diffchange-inline">github</ins>.<ins class="diffchange diffchange-inline">com</ins>/<ins class="diffchange diffchange-inline">openstack</ins>/<ins class="diffchange diffchange-inline">diskimage</ins>-<ins class="diffchange diffchange-inline">builder</ins>/<ins class="diffchange diffchange-inline">commit</ins>/<ins class="diffchange diffchange-inline">fb246a02eb2ed330d3cc37f5795b3ed026aabe07</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">From a fragmentation standpoint it is better to create a file system that is slightly larger than the data you're trying to copy into it.  There is so some non-optimality that occurs as the file system gets filled beyond about 90% full, but it's not nearly as bad as shrinking the file system -- which you should avoid at all costs.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">From a performance point of view, the only time you should try to do</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">an off-line resize2fs shrink is if you are shrinking the file system</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">by a handful of blocks as part of converting a file system in place to</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">use LVM or LUKS encryption, and you need to make room for some</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">metadata blocks at the end of the partition.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">The other thing thing to note is that if you are using a format such</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">as qcow2, or something like the device-mapper's thin-provisining</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">(thinp) scheme, or if you are willing to deal with sparse files, one</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">approach is to not resize the file system at all.  You could just use</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">a tool like zerofree</del>[1] <del class="diffchange diffchange-inline">to zero out all of the unused blocks in the</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">file system, and then use "/bin/cp --sparse=always" to cause all zero</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">blocks to be treated as sparse blocks on the destination file.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">[1] http</del>://<del class="diffchange diffchange-inline">git</del>.<del class="diffchange diffchange-inline">kernel.org</del>/<del class="diffchange diffchange-inline">cgit</del>/<del class="diffchange diffchange-inline">fs/ext2/xfstests</del>-<del class="diffchange diffchange-inline">bld.git</del>/<del class="diffchange diffchange-inline">tree</del>/<del class="diffchange diffchange-inline">kvm-xfstests/util/zerofree.c</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">This is part of how Ted maintains his root filesystem that he uses in a VM</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">for testing ext4 changes upstream.  After updating to the latest</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Debian unstable package updates and installing the latest updates from the</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">xfstests and e2fsprogs git repositories, he runs the following</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">script which uses the zerofree.c program to compress the qcow2 root</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">file system image that he use with kvm:</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">http://git.kernel.org/cgit/fs/ext2/xfstests-bld.git/tree/kvm-xfstests/compress-rootfs</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Also, starting with e2fsprogs 1.42.10, there's another way you can</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">efficiently deploy a large file system image by only copying the</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">blocks which are in use, by using a command like this:</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">      e2image -rap src_fs dest_fs</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">(See also the -c flag as described in e2image's man page if you want</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">to use this technique to do incremental image-based backups onto a</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">flash-based backup medium; Ted was using this for a while to keep two</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">laptop SSD's root filesystems in sync with one another.)</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">So there are lots of ways that you can do what you need, all without</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">playing games with resize2fs.  Perhaps some of them would actually be</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">better for your use case.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">Calvin Walton notes that with a sufficiently recent QEMU profile (qemu 1.5+), if one configures an FS image as a virtual SCSI disk, it is possible to use fstrim inside the VM to make the backing file sparse.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div> </div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div><del class="diffchange diffchange-inline">NOTE: It is not a good idea to "zero" the filesystem image by "cat /dev/zero > /mnt/zerofile; rm -rf /mnt/zerofile"!  While this does have the effect of filling most of the filesystem's free blocks with zeroes, it will be necessary to populate a block map or an extent tree; these blocks will not be zeroed.  It is much more efficient to zero unused blocks offline or discard/trim unused blocks online, since there's no need to waste time invoking the block allocator on a huge temporary file.</del></div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div></div></td></tr>
</table>Djwong