As documented in NetApp TR-3747 “Best Practices for File System Alignment in Virtual Environments”, it is necessary to align properly each layer of storage between the virtual server and the underlying storage. For anyone not familiar with why proper disk alignment is crucial for virtual environments, please review TR-3747. In the context of a Linux disk image, this means that each partition needs to start at a sector number that is cleanly divisible by 8. For contrast, a legacy partitioning tool will create a default starting at sector 63, but an aligned first partition will start at 64 or 128. As a side note, the information posted in this blog will be used to update TR-3747 in the very near future.
In truth, any of the existing legacy partitioning tools can be used to create properly aligned disk images, but specifically using the "parted" tool is perhaps the most elegant way to script the process. This is especially within the context of using Kickstart for repeatable installations. The Linux disk images that are aligned with this process can then be used within KVM and RHEV (Red Hat Enterprise Virtualization).
The first “parted” command creates a disk label on disk “/dev/sda”, and the next creates a primary partion of just over 100MB that starts at sector 64. The third command then creates a second primary partition starting at the next available “alignment friendly sector” of 208848 that takes up whatever disk space is left over. The final command simply changes the partition type to “LVM” for the second partition. Keep in mind that additional partitions can be created, provided they each start on alignment friendly sectors (those that are cleanly divisible by 8). Also, the “/dev/sda” can be edited to “/dev/hda” or “/dev/vda” depending on how the operating system sees the disk.
The other important section in the Kickstart file is where the disk layout is specified. See the difference between this (note that all options below are “--” or 2 dashes):
The first difference is that the “clearpart” line is commented out (it can also be deleted). If left in, it will simply wipe out the partitions created in the “%pre” section that were just created. The next difference is the 2 partitions don’t have size directives; the sizes were already predetermined in the “%pre”, thus we only need to specify filesystem type and partition. Keep in mind that if the “%pre” section specifies “/dev/sda” or “/dev/vda”, the disk layout in the main section will need to follow suit.
For those that don’t have easy access to a Kickstart server, this can easily be converted to a script that is not dependant on Kickstart. Here is a rudimentary Bash script called “align_me.sh” that takes a single disk image file and lays out the aligned partitions:
if [ -z "$1" ]; then echo -e "\nA disk image file needs to be specified...\n”\" echo -e "Usage; align_me.sh <disk_image_file>\n" exit 1 fi
(If the scripts above are going to be copied and pasted, be sure that single dashes (-), double-dashes (--), and parenthesis (") are copied properly, the scripts will error out.)
Qemu-img is first used to create a 10GB virtual disk image named “disk_file.img”, and then the align_me.sh script is used to layout the aligned partitions. The last step would then be to manually install the operating system. On Red Hat and Fedora systems, do things the default way with the install CD or DVD, except when the disk utility comes up. At that point, the "custom layout" option will need to be chosen so that the newly created partitions can be matched up with a mount point.
Hopefully, this sheds some light on how to properly align Linux disk images for use with NetApp storage.
the %pre section part worked fine for me up to RHEL/Centos 5.6, but I am supposed to install 5.8 now and running into trouble that the installer always complains about not enough space for /boot. Does somebody have experience with that version? The kickstart seems to have now options like --start --end which I couldn't get to work out for me