Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
12 replies Latest Post - ‏2010-11-19T21:17:58Z by JLockard
SystemAdmin
SystemAdmin
13339 Posts
ACCEPTED ANSWER

Pinned topic 485892

‏2010-04-30T06:44:18Z |
485892
Updated on 2010-11-19T21:17:58Z at 2010-11-19T21:17:58Z by JLockard
  • kzak
    kzak
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-04-30T06:44:19Z  in response to SystemAdmin
    All (include subsequent) partitions are aligned. You have to follow
    the default values suggested by fdisk.

    # fdisk -v
    fdisk (util-linux-ng 2.17.2)

    # fdisk -uc /dev/sdb

    The device presents a logical sector size that is smaller than
    the physical sector size. Aligning to a physical sector (or optimal
    I/O) size boundary is recommended, or performance may be impacted.

    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (2048-5119999, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-5119999, default 5119999): +200M

    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 2
    First sector (411648-5119999, default 411648):
    Using default value 411648
    Last sector, +sectors or +size{K,M,G} (411648-5119999, default 5119999): +500M

    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 3
    First sector (1435648-5119999, default 1435648):
    Using default value 1435648
    Last sector, +sectors or +size{K,M,G} (1435648-5119999, default 5119999):
    Using default value 5119999

    Command (m for help): p

    Disk /dev/sdb: 2621 MB, 2621440000 bytes
    255 heads, 63 sectors/track, 318 cylinders, total 5120000 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 32768 bytes
    Disk identifier: 0x819c79b5

    Device Boot Start End Blocks Id System
    /dev/sdb1 2048 411647 204800 83 Linux
    /dev/sdb2 411648 1435647 512000 83 Linux
    /dev/sdb3 1435648 5119999 1842176 83 Linux
    If you create an unaligned partition then fdisk prints warning:

    /dev/sdb3 1435650 5119999 1842175 83 Linux
    Partition 3 does not start on physical sector boundary.

    Unaligned partitions have non-zero alignment_offset:

    # cat /sys/block/sdb/sdb3/alignment_offset
    3072
  • kzak
    kzak
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-04-30T06:58:04Z  in response to SystemAdmin
    I forgot ... the best way how specify the "Last sector" is to use +{M,G} (e.g. +10G to create 10GiB partition) convention then fdisk aligns the size to the sector boundary. The fdisk command always follows your wishes if you explicitly define first/last sector number -- it means you can create unaligned partition in such a case.

    In non-DOS mode fdisk (since 2.17.1) uses 1MiB offset for the first partition and 1MiB grain for all others partitions.
  • Jiaoliu
    Jiaoliu
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-05-04T04:26:06Z  in response to SystemAdmin
    Will the fdisk method in comment 2 work for extended partition?
  • srs5694
    srs5694
    7 Posts
    ACCEPTED ANSWER

    test

    ‏2010-05-10T22:05:07Z  in response to SystemAdmin
    kzak,

    I suspect there may be some kernel version effects going on here, or perhaps a difference depending on the disk model. Certainly I don't see the warning about the logical vs. physical sector size that your session shows, nor do I see a warning about a partition with an unaligned start point not starting on a physical sector boundary. This is with fdisk from util-linux-ng 2.17.2 running on a 2.6.31.5 kernel with a WD-10EARS drive. (Since writing this article, I've moved my Advanced Format disk to a production system on which it's awkward to upgrade the kernel, so I can't easily test with the very latest kernel.) In any event, even if fdisk detects the disk's physical/logical size correctly, fdisk doesn't seem to guarantee proper alignment; it just warns you if you create a misaligned partition, so caution is still in order.

    Jiaoliu,

    Using the non-DOS/sector mode (whether via "-uc" on the command line or using "u" and "c" within fdisk) and entering partition sizes in 4KB multiples (+10G, +200M, etc.) does seem to produce properly-aligned logical partitions in my tests; however, I still recommend double-checking all partition start points with a calculator to ensure that they're multiples of 8, since a single mistake in entering the start point or partition length will produce errors on all subsequent partitions.
  • kzak
    kzak
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-05-12T08:07:18Z  in response to SystemAdmin
    srs5694,

    be very very careful with WD-10EARS disks. These disks use 4K sectors, but reports 512-byte sector size to the operation system. It's recommended to check the disk by "hdparm -I" and check /sys/block/sda/queue/physical_block_size. The problem should be fixed on recent disks from WD. For more details see:

    http://community.wdc.com/t5/Desktop/Problem-with-WD-Advanced-Format-drive-in-LINUX-WD15EARS/td-p/6395
    http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/2926/focus=2955

    The I/O topology support should be a available since kernel 2.6.31 (reported in /sys) and 2.6.32 (reported also by ioctls). For more information see

    http://people.redhat.com/msnitzer/docs/io-limits.txt
    http://ata.wiki.kernel.org/index.php/ATA_4_KiB_sector_issue
  • xenoterracide
    xenoterracide
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-05-14T02:57:25Z  in response to SystemAdmin
    why can't we just use fdisk -b 4096?
  • xenoterracide
    xenoterracide
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-05-14T03:23:30Z  in response to SystemAdmin
    also why fdisk -H 224 -S 56 /dev/sda ? why those numbers?
  • srs5694
    srs5694
    7 Posts
    ACCEPTED ANSWER

    test

    ‏2010-05-14T05:43:49Z  in response to SystemAdmin
    kzak,

    At the time I wrote this article, only three Advanced Format disks were available: The WD-10EARS, WD-15EARS, and WD-20EARS. I commented on the fact that the Linux kernel SHOULD be reporting topology information, but DID NOT report accurate information, in the "Determining physical sector size" section of the article. If newer drives are doing better, then that is of course good. As a practical matter, though, the technologies, system calls, and Advanced Format-aware utilities are all so new that the chances of a failure to detect an Advanced Format drive are very high. I therefore stand by my advice: Check alignment manually. Period. It takes a few seconds to check that a sector number is divisible by 8. Using the wrong partition start point could cost orders of magnitude more in wasted time due to degraded performance.

    xenoterracide,

    The -b option to fdisk sets the logical block size, not the physical block size, used by the program. Therefore it will, at best, do no good, and it could do harm. Although I've not tried it on an Advanced Format drive, I just did a test on a USB flash drive, and using "-b 4096" resulted in the seven sectors after the MBR being overwritten. This space may contain GRUB stage 1.5 code, so using this option could render a computer unbootable. There could conceivably be damage to logical partitions under some circumstances, as well.

    As to -H 224 -S 56, the key point is that if the number of sectors per track (set via -S) is a multiple of 8, then partitions will be aligned on 8-sector boundaries. The maximum legal value is 63, and the largest multiple of 8 that's less than 63 is 56. Setting -H 224 is not really critical by this analysis, at least not for Advanced Format drives; however, it does ensure that all but the first partition will be aligned to 128KiB boundaries, which helps with some types of RAID arrays and flash storage devices.
  • xenoterracide
    xenoterracide
    3 Posts
    ACCEPTED ANSWER

    test

    ‏2010-06-01T01:00:25Z  in response to SystemAdmin
    are there any actual timings anywhere? it's useful to know that it's ~10x longer but that only helps if you know the bad if you're trying to check a timing... for kernel extraction on ext4 ( time tar -xvf /mnt/linux-2.6.34.tar -C /mnt/ ) I'm getting

    real 0m2.231s
    user 0m0.203s
    sys 0m1.760s

    for reiserfs it's

    real 0m8.453s
    user 0m0.223s
    sys 0m3.820s

    that seems like a small amount of time and they are aligned as directed so prolly fs differences.
  • srs5694
    srs5694
    7 Posts
    ACCEPTED ANSWER

    test

    ‏2010-06-01T01:45:15Z  in response to SystemAdmin
    I didn't include raw times in the article because I wanted to focus on the alignment issue without dragging filesystem differences into the picture, and because large numbers of other factors (CPU performance, disk controller chipset, or the specific disk model, for instance) can play a role in it. My own times for ext4fs and ReiserFS on kernel extraction are about 40% greater than yours (3.22s for ext4fs and 11.65s for ReiserFS, both on aligned partitions). The difference between the filesystems is almost certainly an effect of the filesystems themselves (and it's much smaller on most of my other measures). The 40% difference between your and my figures could reflect any of a number of between-system differences.
  • CurtisGedak
    CurtisGedak
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-06-02T01:48:56Z  in response to SystemAdmin
    Recently enhancements to support devices with sector sizes > 512 bytes, and a new align to MiB option have been added to the GParted git repository.

    A forum post for testing the new gparted-0.6.0-beta1 release has been posted at:
    Need Help Testing "Align to MiB", and sector sizes > 512 bytes
    http://gparted-forum.surf4.info/viewtopic.php?id=14135

    This upcoming 0.6.0 release of GParted should make it easier to ensure that partitions are aligned for better performance on RAID, Solid State Drives, and devices with sector sizes > 512 bytes.
  • JLockard
    JLockard
    1 Post
    ACCEPTED ANSWER

    test

    ‏2010-11-19T21:17:58Z  in response to SystemAdmin
    Things may have changed since you posted the article, but now it works quite simply using these...

    <pre>
    1. parted -a opt /dev/sda
    (parted) u MiB
    (parted) mkpart primary 1 100%
    (parted) p
    Model: ATA WDC WD15EADS-00P (scsi)
    Disk /dev/sdf: 1430799MiB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt

    Number Start End Size File system Name Flags
    1 1.00MiB 1430799MiB 1430798MiB ext4 primary
    </pre>

    And for fdisk:
    <pre>
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (2048-2930277167, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-2930277167, default 2930277167):
    Using default value 2930277167

    </pre>