How to create aligned partitions in Linux for use with NetApp LUNs, VMDKs, VHDs and other virtual disk containers
Description
As a best practice, NetApp LUNs should always be partitioned with a single primary partition. The partition serves two purposes. It functions as a label for the LUN or virtual disk which helps the operating system identify the contents of the LUN or virtual disk. The partition is also used to align the host's file system with the LUN or virtual disk. Aligning the host file system is necessary to achieve optimal performance of read and write I/Os.
Procedure
Creating an aligned partition involves specifying the correct starting sector or logical block address (LBA) for the partition. The correct starting LBA is one which is evenly divisible by eight. This article will provide guidelines for using the GNU Parted (parted) and fdisk partitioning programs to create aligned partitions on NetApp LUNs.
The fdisk
program is used to manage MBR style partitions which can address a maximum of 2TB. LUNs larger than 2TB must be partitioned using parted
.
Using Fdisk to Partition a LUN less than 2TB
A partition is aligned when the value in the Start column is evenly divisible by 8. Other partitioning programs such as cfdisk, sfdisk can be used, however they are beyond the scope of this article.
- Begin by creating and mapping a LUN to the Linux host. The LUN must be created with the Linux OS type. If the LUN was created with a different LUN type, then it should not be used and a new LUN should be created.
- Use the
fdisk
command to create a primary partition that spans the entire LUN. The LUN in the following example has never been partitioned, so the warning from fdisk can be ignored.
# fdisk /dev/mapper/mpath1
The number of cylinders for this disk is set to 3917.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/mapper/mpath1: 32.2 GB, 32218421760 bytes
255 heads, 63 sectors/track, 3917 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3917, default 1): 1
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-3917, default 3917): 3917
Using default value 3917
Command (m for help):
- Enter expert mode in fdisk and change the starting LBA of the partition to a value that is evenly divisible by eight. In the following example, the default starting sector is 63 and it is changed to 64 because 64 is evenly divisible by eight. The default starting sector chosen by fdisk is based on the size of the LUN. The LUN size is used by fdisk to calculate a pseudo geometry which can vary between different versions of fdisk.
Command (m for help): x
Expert command (m for help): b
Partition number (1-4): 1
New beginning of data (63-62926604, default 63): 64
Expert command (m for help): p
Disk /dev/mapper/mpath1: 255 heads, 63 sectors, 3917 cylinders
Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID
1 00 1 1 0 254 63 1023 64 62926541 83
2 00 0 0 0 0 0 0 0 0 00
3 00 0 0 0 0 0 0 0 0 00
4 00 0 0 0 0 0 0 0 0 00
(Fdisk may print a warning similar to the following as a result of the new offset, this warning may be ignored.)
Partition 1 has different physical/logical beginnings (non-Linux?):
phys=(0, 1, 1) logical=(0, 1, 2)
- Write the partition table and create the new device files for the partition. The
kpartx
command is used to create the device node for the new partition automatically.
# kpartx -a /dev/mapper/mpath1
# ls -al /dev/mapper/mpath1*
brw-rw---- 1 root disk 253, 5 Mar 25 14:12 /dev/mapper/mpath1
brw-rw---- 1 root disk 253, 6 Mar 25 14:17 /dev/mapper/mpath1p1
- Optionally, create a file system or LVM physical volume using the partition. File systems should be configured to use a 4kB block or a larger block size that is a multiple of 4kB.
# mkfs.ext3 -b 4096 /dev/mapper/mpath1p1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
3933120 inodes, 7865817 blocks
393290 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
241 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Adding an entry to/etc/fstab
will allow the new file system to be automatically mounted during future system boots.
Using Parted to Partition a LUN
- You may use
parted
to create aligned partitions to align the filesystem on a LUN.parted
creates GUID Partition tables (GPT) and may be used for any size LUN including those larger than 2TB. This example shows how to create an aligned partition on a LUN.
# parted /dev/sdb
GNU Parted 1.9.0
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
- Change the default unit to sectors to assist with aligning the filesystem, and then create a primary partition starting at 64 using 100% of the remaining space. Print the partition table to verify the partition starts on an aligned sector.
(parted) unit s
(parted) mkpart primary 64 100%
(parted) print
Model: NETAPP LUN (scsi)
Disk /dev/sdb: 8589934592s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 64s 8589934558s 8589934495s primary