.\" Automatically generated by Podwrapper::Man 1.44.2 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "virt-alignment-scan 1" .TH virt-alignment-scan 1 "2021-09-07" "libguestfs-1.44.2" "Virtualization Support" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" virt\-alignment\-scan \- Check alignment of virtual machine partitions .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& virt\-alignment\-scan [\-\-options] \-d domname \& \& virt\-alignment\-scan [\-\-options] \-a disk.img [\-a disk.img ...] \& \& virt\-alignment\-scan [\-\-options] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" When older operating systems install themselves, the partitioning tools place partitions at a sector misaligned with the underlying storage (commonly the first partition starts on sector \f(CW63\fR). Misaligned partitions can result in an operating system issuing more I/O than should be necessary. .PP The virt-alignment-scan tool checks the alignment of partitions in virtual machines and disk images and warns you if there are alignment problems. .PP Currently there is no virt tool for fixing alignment problems. You can only reinstall the guest operating system. The following NetApp document summarises the problem and possible solutions: http://media.netapp.com/documents/tr\-3747.pdf .SH "OUTPUT" .IX Header "OUTPUT" To run this tool on a disk image directly, use the \fI\-a\fR option: .PP .Vb 2 \& $ virt\-alignment\-scan \-a winxp.img \& /dev/sda1 32256 512 bad (alignment < 4K) \& \& $ virt\-alignment\-scan \-a fedora16.img \& /dev/sda1 1048576 1024K ok \& /dev/sda2 2097152 2048K ok \& /dev/sda3 526385152 2048K ok .Ve .PP To run the tool on a guest known to libvirt, use the \fI\-d\fR option and possibly the \fI\-c\fR option: .PP .Vb 3 \& # virt\-alignment\-scan \-d RHEL5 \& /dev/sda1 32256 512 bad (alignment < 4K) \& /dev/sda2 106928640 512 bad (alignment < 4K) \& \& $ virt\-alignment\-scan \-c qemu:///system \-d Win7TwoDisks \& /dev/sda1 1048576 1024K ok \& /dev/sda2 105906176 1024K ok \& /dev/sdb1 65536 64K ok .Ve .PP Run virt-alignment-scan without any \fI\-a\fR or \fI\-d\fR options to scan all libvirt domains. .PP .Vb 4 \& # virt\-alignment\-scan \& F16x64:/dev/sda1 1048576 1024K ok \& F16x64:/dev/sda2 2097152 2048K ok \& F16x64:/dev/sda3 526385152 2048K ok .Ve .PP The output consists of 4 or more whitespace-separated columns. Only the first 4 columns are significant if you want to parse this from a program. The columns are: .IP "col 1" 4 .IX Item "col 1" The device and partition name (eg. \fI/dev/sda1\fR meaning the first partition on the first block device). .Sp When listing all libvirt domains (no \fI\-a\fR or \fI\-d\fR option given) this column is prefixed by the libvirt name or \s-1UUID\s0 (if \fI\-\-uuid\fR is given). eg: \f(CW\*(C`WinXP:/dev/sda1\*(C'\fR .IP "col 2" 4 .IX Item "col 2" the start of the partition in bytes .IP "col 3" 4 .IX Item "col 3" the alignment in bytes or Kbytes (eg. \f(CW512\fR or \f(CW\*(C`4K\*(C'\fR) .IP "col 4" 4 .IX Item "col 4" \&\f(CW\*(C`ok\*(C'\fR if the alignment is best for performance, or \f(CW\*(C`bad\*(C'\fR if the alignment can cause performance problems .IP "cols 5+" 4 .IX Item "cols 5+" optional free-text explanation. .PP The exit code from the program changes depending on whether poorly aligned partitions were found. See \*(L"\s-1EXIT STATUS\*(R"\s0 below. .PP If you just want the exit code with no output, use the \fI\-q\fR option. .SH "OPTIONS" .IX Header "OPTIONS" .IP "\fB\-\-help\fR" 4 .IX Item "--help" Display brief help. .IP "\fB\-a\fR file" 4 .IX Item "-a file" .PD 0 .IP "\fB\-\-add\fR file" 4 .IX Item "--add file" .PD Add \fIfile\fR which should be a disk image from a virtual machine. .Sp The format of the disk image is auto-detected. To override this and force a particular format use the \fI\-\-format=..\fR option. .IP "\fB\-a \s-1URI\s0\fR" 4 .IX Item "-a URI" .PD 0 .IP "\fB\-\-add \s-1URI\s0\fR" 4 .IX Item "--add URI" .PD Add a remote disk. See \*(L"\s-1ADDING REMOTE STORAGE\*(R"\s0 in \fBguestfish\fR\|(1). .IP "\fB\-\-blocksize=512\fR" 4 .IX Item "--blocksize=512" .PD 0 .IP "\fB\-\-blocksize=4096\fR" 4 .IX Item "--blocksize=4096" .IP "\fB\-\-blocksize\fR" 4 .IX Item "--blocksize" .PD This parameter sets the sector size of the disk image. It affects all explicitly added subsequent disks after this parameter. Using \&\fI\-\-blocksize\fR with no argument switches the disk sector size to the default value which is usually 512 bytes. See also \&\*(L"guestfs_add_drive_opts\*(R" in \fBguestfs\fR\|(3). .IP "\fB\-c\fR \s-1URI\s0" 4 .IX Item "-c URI" .PD 0 .IP "\fB\-\-connect\fR \s-1URI\s0" 4 .IX Item "--connect URI" .PD If using libvirt, connect to the given \fI\s-1URI\s0\fR. If omitted, then we connect to the default libvirt hypervisor. .Sp If you specify guest block devices directly (\fI\-a\fR), then libvirt is not used at all. .IP "\fB\-d\fR guest" 4 .IX Item "-d guest" .PD 0 .IP "\fB\-\-domain\fR guest" 4 .IX Item "--domain guest" .PD Add all the disks from the named libvirt guest. Domain UUIDs can be used instead of names. .IP "\fB\-\-format=raw|qcow2|..\fR" 4 .IX Item "--format=raw|qcow2|.." .PD 0 .IP "\fB\-\-format\fR" 4 .IX Item "--format" .PD The default for the \fI\-a\fR option is to auto-detect the format of the disk image. Using this forces the disk format for \fI\-a\fR options which follow on the command line. Using \fI\-\-format\fR with no argument switches back to auto-detection for subsequent \fI\-a\fR options. .Sp For example: .Sp .Vb 1 \& virt\-alignment\-scan \-\-format=raw \-a disk.img .Ve .Sp forces raw format (no auto-detection) for \fIdisk.img\fR. .Sp .Vb 1 \& virt\-alignment\-scan \-\-format=raw \-a disk.img \-\-format \-a another.img .Ve .Sp forces raw format (no auto-detection) for \fIdisk.img\fR and reverts to auto-detection for \fIanother.img\fR. .Sp If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (\s-1CVE\-2010\-3851\s0). .IP "\fB\-P\fR nr_threads" 4 .IX Item "-P nr_threads" Since libguestfs 1.22, virt-alignment-scan is multithreaded and examines guests in parallel. By default the number of threads to use is chosen based on the amount of free memory available at the time that virt-alignment-scan is started. You can force virt-alignment-scan to use at most \f(CW\*(C`nr_threads\*(C'\fR by using the \fI\-P\fR option. .Sp Note that \fI\-P 0\fR means to autodetect, and \fI\-P 1\fR means to use a single thread. .IP "\fB\-q\fR" 4 .IX Item "-q" .PD 0 .IP "\fB\-\-quiet\fR" 4 .IX Item "--quiet" .PD Don’t produce any output. Just set the exit code (see \*(L"\s-1EXIT STATUS\*(R"\s0 below). .IP "\fB\-\-uuid\fR" 4 .IX Item "--uuid" Print UUIDs instead of names. This is useful for following a guest even when the guest is migrated or renamed, or when two guests happen to have the same name. .Sp This option only applies when listing all libvirt domains (when no \&\fI\-a\fR or \fI\-d\fR options are specified). .IP "\fB\-v\fR" 4 .IX Item "-v" .PD 0 .IP "\fB\-\-verbose\fR" 4 .IX Item "--verbose" .PD Enable verbose messages for debugging. .IP "\fB\-V\fR" 4 .IX Item "-V" .PD 0 .IP "\fB\-\-version\fR" 4 .IX Item "--version" .PD Display version number and exit. .IP "\fB\-x\fR" 4 .IX Item "-x" Enable tracing of libguestfs \s-1API\s0 calls. .SH "RECOMMENDED ALIGNMENT" .IX Header "RECOMMENDED ALIGNMENT" Operating systems older than Windows 2008 and Linux before ca.2010 place the first sector of the first partition at sector 63, with a 512 byte sector size. This happens because of a historical accident. Drives have to report a cylinder / head / sector (\s-1CHS\s0) geometry to the \&\s-1BIOS.\s0 The geometry is completely meaningless on modern drives, but it happens that the geometry reported always has 63 sectors per track. The operating system therefore places the first partition at the start of the second \*(L"track\*(R", at sector 63. .PP When the guest \s-1OS\s0 is virtualized, the host operating system and hypervisor may prefer accesses aligned to one of: .IP "\(bu" 4 512 bytes .Sp if the host \s-1OS\s0 uses local storage directly on hard drive partitions, and the hard drive has 512 byte physical sectors. .IP "\(bu" 4 4 Kbytes .Sp for local storage on new hard drives with 4Kbyte physical sectors; for file-backed storage on filesystems with 4Kbyte block size; or for some types of network-attached storage. .IP "\(bu" 4 64 Kbytes .Sp for high-end network-attached storage. This is the optimal block size for some NetApp hardware. .IP "\(bu" 4 1 Mbyte .Sp see \*(L"1 \s-1MB PARTITION ALIGNMENT\*(R"\s0 below. .PP Partitions which are not aligned correctly to the underlying storage cause extra I/O. For example: .PP .Vb 8 \& sect#63 \& ┌──────────────────────────┬ ─ ─ ─ ─ \& │ guest │ \& │ filesystem block │ \& ─ ┬──────────────────┴──────┬───────────────────┴─────┬ ─ ─ \& │ host block │ host block │ \& │ │ │ \& ─ ┴─────────────────────────┴─────────────────────────┴ ─ ─ .Ve .PP In this example, each time a 4K guest block is read, two blocks on the host must be accessed (so twice as much I/O is done). When a 4K guest block is written, two host blocks must first be read, the old and new data combined, and the two blocks written back (4x I/O). .SS "\s-1LINUX HOST BLOCK AND I/O SIZE\s0" .IX Subsection "LINUX HOST BLOCK AND I/O SIZE" New versions of the Linux kernel expose the physical and logical block size, and minimum and recommended I/O size. .PP For a typical consumer hard drive with 512 byte sectors: .PP .Vb 10 \& $ cat /sys/block/sda/queue/hw_sector_size \& 512 \& $ cat /sys/block/sda/queue/physical_block_size \& 512 \& $ cat /sys/block/sda/queue/logical_block_size \& 512 \& $ cat /sys/block/sda/queue/minimum_io_size \& 512 \& $ cat /sys/block/sda/queue/optimal_io_size \& 0 .Ve .PP For a new consumer hard drive with 4Kbyte sectors: .PP .Vb 10 \& $ cat /sys/block/sda/queue/hw_sector_size \& 4096 \& $ cat /sys/block/sda/queue/physical_block_size \& 4096 \& $ cat /sys/block/sda/queue/logical_block_size \& 4096 \& $ cat /sys/block/sda/queue/minimum_io_size \& 4096 \& $ cat /sys/block/sda/queue/optimal_io_size \& 0 .Ve .PP For a NetApp \s-1LUN:\s0 .PP .Vb 8 \& $ cat /sys/block/sdc/queue/logical_block_size \& 512 \& $ cat /sys/block/sdc/queue/physical_block_size \& 512 \& $ cat /sys/block/sdc/queue/minimum_io_size \& 4096 \& $ cat /sys/block/sdc/queue/optimal_io_size \& 65536 .Ve .PP The NetApp allows 512 byte accesses (but they will be very inefficient), prefers a minimum 4K I/O size, but the optimal I/O size is 64K. .PP For detailed information about what these numbers mean, see http://docs.redhat.com/docs/en\-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/newstorage\-iolimits.html .PP [Thanks to Matt Booth for providing 4K drive data. Thanks to Mike Snitzer for providing NetApp data and additional information.] .SS "1 \s-1MB PARTITION ALIGNMENT\s0" .IX Subsection "1 MB PARTITION ALIGNMENT" Microsoft picked 1 \s-1MB\s0 as the default alignment for all partitions starting with Windows 2008 Server, and Linux has followed this. .PP Assuming 512 byte sectors in the guest, you will now see the first partition starting at sector 2048, and subsequent partitions (if any) will start at a multiple of 2048 sectors. .PP 1 \s-1MB\s0 alignment is compatible with all current alignment requirements (4K, 64K) and provides room for future growth in physical block sizes. .SS "\s-1SETTING ALIGNMENT\s0" .IX Subsection "SETTING ALIGNMENT" \&\fBvirt\-resize\fR\|(1) can change the alignment of the partitions of some guests. Currently it can fully align all the partitions of all Windows guests, and it will fix the bootloader where necessary. For Linux guests, it can align the second and subsequent partitions, so the majority of \s-1OS\s0 accesses except at boot will be aligned. .PP Another way to correct partition alignment problems is to reinstall your guest operating systems. If you install operating systems from templates, ensure these have correct partition alignment too. .PP For older versions of Windows, the following NetApp document contains useful information: http://media.netapp.com/documents/tr\-3747.pdf .PP For Red Hat Enterprise Linux ≤ 5, use a Kickstart script that contains an explicit \f(CW%pre\fR section that creates aligned partitions using \fBparted\fR\|(8). Do not use the Kickstart \f(CW\*(C`part\*(C'\fR command. The NetApp document above contains an example. .SH "EXIT STATUS" .IX Header "EXIT STATUS" This program returns: .IP "\(bu" 4 0 .Sp successful exit, all partitions are aligned ≥ 64K for best performance .IP "\(bu" 4 1 .Sp an error scanning the disk image or guest .IP "\(bu" 4 2 .Sp successful exit, some partitions have alignment < 64K which can result in poor performance on high end network storage .IP "\(bu" 4 3 .Sp successful exit, some partitions have alignment < 4K which can result in poor performance on most hypervisors .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBguestfs\fR\|(3), \&\fBguestfish\fR\|(1), \&\fBvirt\-filesystems\fR\|(1), \&\fBvirt\-rescue\fR\|(1), \&\fBvirt\-resize\fR\|(1), http://libguestfs.org/. .SH "AUTHOR" .IX Header "AUTHOR" Richard W.M. Jones http://people.redhat.com/~rjones/ .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2011 Red Hat Inc. .SH "LICENSE" .IX Header "LICENSE" This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, \s-1MA 02110\-1301 USA.\s0 .SH "BUGS" .IX Header "BUGS" To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools .PP To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools .PP When reporting a bug, please supply: .IP "\(bu" 4 The version of libguestfs. .IP "\(bu" 4 Where you got libguestfs (eg. which Linux distro, compiled from source, etc) .IP "\(bu" 4 Describe the bug accurately and give a way to reproduce it. .IP "\(bu" 4 Run \fBlibguestfs\-test\-tool\fR\|(1) and paste the \fBcomplete, unedited\fR output into the bug report.