5 virt-alignment-scan - Check alignment of virtual machine partitions
9 virt-alignment-scan [--options] -d domname
11 virt-alignment-scan [--options] -a disk.img [-a disk.img ...]
15 When older operating systems install themselves, the partitioning
16 tools place partitions at a sector misaligned with the underlying
17 storage (commonly the first partition starts on sector C<63>).
18 Misaligned partitions can result in an operating system issuing more
19 I/O than should be necessary.
21 The virt-alignment-scan tool checks the alignment of partitions in
22 virtual machines and disk images and warns you if there are alignment
25 Currently there is no virt tool for fixing alignment problems. You
26 can only reinstall the guest operating system. The following NetApp
27 document summarises the problem and possible solutions:
28 L<http://media.netapp.com/documents/tr-3747.pdf>
32 To run this tool on a disk image directly, use the I<-a> option:
34 $ virt-alignment-scan -a winxp.img
35 /dev/sda1 32256 512 bad (alignment < 4K)
37 $ virt-alignment-scan -a fedora16.img
38 /dev/sda1 1048576 1024K ok
39 /dev/sda2 2097152 2048K ok
40 /dev/sda3 526385152 2048K ok
42 To run the tool on a guest known to libvirt, use the I<-d> option and
43 possibly the I<-c> option:
45 # virt-alignment-scan -d RHEL5
46 /dev/sda1 32256 512 bad (alignment < 4K)
47 /dev/sda2 106928640 512 bad (alignment < 4K)
49 $ virt-alignment-scan -c qemu:///system -d Win7TwoDisks
50 /dev/sda1 1048576 1024K ok
51 /dev/sda2 105906176 1024K ok
52 /dev/sdb1 65536 64K ok
54 The output consists of 4 or more whitespace-separated columns. Only
55 the first 4 columns are signficant if you want to parse this from a
56 program. The columns are:
62 the device and partition name (eg. C</dev/sda1> meaning the
63 first partition on the first block device)
67 the start of the partition in bytes
71 the alignment in bytes or Kbytes (eg. C<512> or C<4K>)
75 C<ok> if the alignment is best for performance, or C<bad> if the
76 alignment can cause performance problems
80 optional free-text explanation.
84 The exit code from the program changes depending on whether poorly
85 aligned partitions were found. See L</EXIT STATUS> below.
87 If you just want the exit code with no output, use the I<-q> option.
101 Add I<file> which should be a disk image from a virtual machine.
103 The format of the disk image is auto-detected. To override this and
104 force a particular format use the I<--format=..> option.
108 =item B<--connect> URI
110 If using libvirt, connect to the given I<URI>. If omitted, then we
111 connect to the default libvirt hypervisor.
113 If you specify guest block devices directly (I<-a>), then libvirt is
118 =item B<--domain> guest
120 Add all the disks from the named libvirt guest. Domain UUIDs can be
121 used instead of names.
123 =item B<--format=raw|qcow2|..>
127 The default for the I<-a> option is to auto-detect the format of the
128 disk image. Using this forces the disk format for I<-a> options which
129 follow on the command line. Using I<--format> with no argument
130 switches back to auto-detection for subsequent I<-a> options.
134 virt-alignment-scan --format=raw -a disk.img
136 forces raw format (no auto-detection) for C<disk.img>.
138 virt-alignment-scan --format=raw -a disk.img --format -a another.img
140 forces raw format (no auto-detection) for C<disk.img> and reverts to
141 auto-detection for C<another.img>.
143 If you have untrusted raw-format guest disk images, you should use
144 this option to specify the disk format. This avoids a possible
145 security problem with malicious guests (CVE-2010-3851).
151 Don't produce any output. Just set the exit code
152 (see L</EXIT STATUS> below).
158 Enable verbose messages for debugging.
164 Display version number and exit.
168 Enable tracing of libguestfs API calls.
172 =head1 RECOMMENDED ALIGNMENT
174 Operating systems older than Windows 2008 and Linux before ca.2010
175 place the first sector of the first partition at sector 63, with a 512
176 byte sector size. This happens because of a historical accident.
177 Drives have to report a cylinder / head / sector (CHS) geometry to the
178 BIOS. The geometry is completely meaningless on modern drives, but it
179 happens that the geometry reported always has 63 sectors per track.
180 The operating system therefore places the first partition at the start
181 of the second "track", at sector 63.
183 When the guest OS is virtualized, the host operating system and
184 hypervisor may prefer accesses aligned to one of:
190 if the host OS uses local storage directly on hard drive partitions,
191 and the hard drive has 512 byte physical sectors.
195 for local storage on new hard drives with 4Kbyte physical sectors; for
196 file-backed storage on filesystems with 4Kbyte block size; or for some
197 types of network-attached storage.
201 for high-end network-attached storage. This is the optimal block size
202 for some NetApp hardware.
206 see L</1 MB PARTITION ALIGNMENT> below.
210 Partitions which are not aligned correctly to the underlying
211 storage cause extra I/O. For example:
214 +--------------------------+------
217 ---+------------------+------+-------------------+-----+---
218 | host block | host block |
220 ---+-------------------------+-------------------------+---
222 In this example, each time a 4K guest block is read, two blocks on the
223 host must be accessed (so twice as much I/O is done). When a 4K guest
224 block is written, two host blocks must first be read, the old and new
225 data combined, and the two blocks written back (4x I/O).
227 =head2 LINUX HOST BLOCK AND I/O SIZE
229 New versions of the Linux kernel expose the physical and logical block
230 size, and minimum and recommended I/O size.
232 For a typical consumer hard drive with 512 byte sectors:
234 $ cat /sys/block/sda/queue/hw_sector_size
236 $ cat /sys/block/sda/queue/physical_block_size
238 $ cat /sys/block/sda/queue/logical_block_size
240 $ cat /sys/block/sda/queue/minimum_io_size
242 $ cat /sys/block/sda/queue/optimal_io_size
245 For a new consumer hard drive with 4Kbyte sectors:
247 $ cat /sys/block/sda/queue/hw_sector_size
249 $ cat /sys/block/sda/queue/physical_block_size
251 $ cat /sys/block/sda/queue/logical_block_size
253 $ cat /sys/block/sda/queue/minimum_io_size
255 $ cat /sys/block/sda/queue/optimal_io_size
260 $ cat /sys/block/sdc/queue/logical_block_size
262 $ cat /sys/block/sdc/queue/physical_block_size
264 $ cat /sys/block/sdc/queue/minimum_io_size
266 $ cat /sys/block/sdc/queue/optimal_io_size
269 The NetApp allows 512 byte accesses (but they will be very
270 inefficient), prefers a minimum 4K I/O size, but the optimal I/O size
273 For detailed information about what these numbers mean, see
274 L<http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/newstorage-iolimits.html>
276 [Thanks to Matt Booth for providing 4K drive data. Thanks to Mike
277 Snitzer for providing NetApp data and additional information.]
279 =head2 1 MB PARTITION ALIGNMENT
281 Microsoft picked 1 MB as the default alignment for all partitions
282 starting with Windows 2008 Server, and Linux has followed this.
284 Assuming 512 byte sectors in the guest, you will now see the first
285 partition starting at sector 2048, and subsequent partitions (if any)
286 will start at a multiple of 2048 sectors.
288 1 MB alignment is compatible with all current alignment requirements
289 (4K, 64K) and provides room for future growth in physical block sizes.
291 =head2 SETTING ALIGNMENT
293 L<virt-resize(1)> can change the alignment of the partitions of some
294 guests. Currently it can fully align all the partitions of all
295 Windows guests, and it will fix the bootloader where necessary. For
296 Linux guests, it can align the second and subsequent partitions, so
297 the majority of OS accesses except at boot will be aligned.
299 Another way to correct partition alignment problems is to reinstall
300 your guest operating systems. If you install operating systems from
301 templates, ensure these have correct partition alignment too.
303 For older versions of Windows, the following NetApp document contains
304 useful information: L<http://media.netapp.com/documents/tr-3747.pdf>
306 For Red Hat Enterprise Linux E<le> 5, use a Kickstart script that
307 contains an explicit C<%pre> section that creates aligned partitions
308 using L<parted(8)>. Do not use the Kickstart C<part> command. The
309 NetApp document above contains an example.
313 Libvirt guest names can contain arbitrary characters, some of which
314 have meaning to the shell such as C<#> and space. You may need to
315 quote or escape these characters on the command line. See the shell
316 manual page L<sh(1)> for details.
320 This program returns:
328 successful exit, all partitions are aligned E<ge> 64K for best performance
334 an error scanning the disk image or guest
340 successful exit, some partitions have alignment E<lt> 64K which can result
341 in poor performance on high end network storage
347 successful exit, some partitions have alignment E<lt> 4K which can result
348 in poor performance on most hypervisors
356 L<virt-filesystems(1)>,
359 L<http://libguestfs.org/>.
363 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
367 Copyright (C) 2011 Red Hat Inc.
369 This program is free software; you can redistribute it and/or modify
370 it under the terms of the GNU General Public License as published by
371 the Free Software Foundation; either version 2 of the License, or
372 (at your option) any later version.
374 This program is distributed in the hope that it will be useful,
375 but WITHOUT ANY WARRANTY; without even the implied warranty of
376 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
377 GNU General Public License for more details.
379 You should have received a copy of the GNU General Public License
380 along with this program; if not, write to the Free Software
381 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.