*ARGH, all of this is busted-ish. The newest efforts work fine, but Windows cannot access the Linux partitions using the ext2 driver. Boo.*
- [1] Linux - Tips, tweaks and alignment
- TO READ: [2] The first decent post...
- one guy said: Propose adding recommendation of 'mke2fs ... -E stripe-width=128' for 512kB erase page block drives (vertex) or 'mke2fs ... -E stripe-width=32' for 128kB erase page block drives. (afaik everything else)
- TO READ: [2] The first decent post...
Geometry of my 2TB drives.
- Cycles: 243201
- Heads: 255 (default for fdisk)
- Sectors: 63 (default for fdisk)
When my own Vertex drive arrives, I'll be using fdisk -u to partition it, completely ignoring the antiquated CHS confusion. Much simpler that way, especially when there'll only be one or two partitions in total.
For a scheme with lots of partitions, it might be more convenient then to actually fiddle with the CHS parameters, though I doubt it.
Steps I've taken
- cfdisk and create one large partition.
- fdisk -lu /dev/sdg
- Learned the cycles/heads/sectors.
- Learned the starting sector.
Device Boot Start End Blocks Id System /dev/sdg1 63 3907024064 1953512001 83 Linux: Find the starting sector using sudo fdisk -lu. If it starts on a value that are an even multiple of 1024. Then you're ready to proceed.
Huh?? I have "63".
: sudo mke2fs -t ext4 -E stripe-width=128 /dev/sda1
: Since the default file system sector size is 4kB, stripe-width=128 will result in 512kB alignment. The file system will now try to align each write at the start of an empty erase block.
: sda1 indicates that we want to create our file system on the first partition on /dev/sda.
I experimented with fdisk -H 32 -S 32 /dev/sdg to get 512KB alignment. I was forced to start at cylinder 3. When goofing around some more, I was able to start at cylinder 2 with fdisk -H 8 -S 16 /dev/sdg.
Cylinder size (Times 512k):
1024K (x2) -S 16 -H 128 -S 32 -H 64 512K (x1) -S 8 -H 128 -S 16 -H 64 -S 32 -H 32 256K (x0.5) -S 4 -H 128 -S 8 -H 64 -S 16 -H 32 -S 32 -H 16 128K (x0.25) -S 2 -H 128 -S 4 -H 64 -S 8 -H 32 -S 16 -H 16 -S 32 -H 8 64KB (recommended for Windows) -S 16 -H 8
fdisk -H 8 -S 16 /dev/sdg
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
c
DOS Compatibility flag is not set
n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
1
First cylinder (17-30523665, default 17):
(enter)
Last cylinder, +cylinders or +size{K,M,G} (2-30523665, default 30523665):
+8G
n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4):
2
First cylinder (131089-30523665, default 131089):
(enter)
Last cylinder, +cylinders or +size{K,M,G} (131089-30523665, default 30523665):
30523665
n
Command action
l logical (5 or over)
p primary partition (1-4)
l
+128000
First cylinder (128034-30523665, default 128034):
(enter)
Last cylinder, +cylinders or +size{K,M,G} (128034-30523665, default 30523665):
+591949
n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (720000-30523665, default 720000):
(enter)
Last cylinder, +cylinders or +size{K,M,G} (720000-30523665, default 30523665):
+96001
n
l
First cylinder (816018-30523665, default 816018):
(enter)
+128000
n
l
First cylinder (944035-30523665, default 944035):
(enter)
Last cylinder, +cylinders or +size{K,M,G} (944035-30523665, default 30523665):
+32753
+4577070
and then the rest...
w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to sectors (command 'u').Command (m for help): c DOS Compatibility flag is not set
Command (m for help): n Command action
e extended p primary partition (1-4)p Partition number (1-4): 1 First cylinder (17-30523665, default 17): Using default value 17 Last cylinder, +cylinders or +size{K,M,G} (17-30523665, default 30523665): +128000
Command (m for help): n Command action
e extended p primary partition (1-4)e Partition number (1-4): 2 First cylinder (128018-30523665, default 128018): Using default value 128018 Last cylinder, +cylinders or +size{K,M,G} (128018-30523665, default 30523665): Using default value 30523665
Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (128034-30523665, default 128034): Using default value 128034 Last cylinder, +cylinders or +size{K,M,G} (128034-30523665, default 30523665): +591949
Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (720000-30523665, default 720000): Using default value 720000 Last cylinder, +cylinders or +size{K,M,G} (720000-30523665, default 30523665): +96001
Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (816018-30523665, default 816018): Using default value 816018 Last cylinder, +cylinders or +size{K,M,G} (816018-30523665, default 30523665): +128000 Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (944035-30523665, default 944035): Using default value 944035 Last cylinder, +cylinders or +size{K,M,G} (944035-30523665, default 30523665): +32753
Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (976805-30523665, default 976805): Using default value 976805 Last cylinder, +cylinders or +size{K,M,G} (976805-30523665, default 30523665): +4577700
Command (m for help): n Command action
l logical (5 or over) p primary partition (1-4)l First cylinder (5554522-30523665, default 5554522): Using default value 5554522 Last cylinder, +cylinders or +size{K,M,G} (5554522-30523665, default 30523665): Using default value 30523665 w
[wrong] Formula for calculating cylinders. For example, I want an 8389.79MB partition, and I can mostly re-create it with:
size_wanted * 1000 / cylinder_size 8389.79*1000/64 = 131090this is too big
look at the top of cfdisk:
Heads: 255 Sectors per Track: 63 Cylinders: 7783[wrong] press 'u' to get your units to cylinders. I found 1020. Then do this math:
cylinder_size_currently * cylinders / sylinder_size_wanted 1020*7783/64 = 124041This is too small
I have no clue what I'm doing.
...
sdg1 and sdg5 will become ntfs mkfs.ext4 -I 128 /dev/sdg6 mkfs.ext4 -I 128 /dev/sdg7 mkswap /dev/sdg8 mkfs.ext4 -I 128 /dev/sdg9 mkfs.ext4 -I 128 /dev/sdg10One guy did:
mkfs.ext4 -O has_journal -O dir_index -O extents -E stripe-width=128 /dev/sda1
Checking that it's aligned
fdisk -ul /dev/sdaexample from fdisk (in Swedish):
Kommando (m för hjälp): p Disk /dev/sda: 64,0 GB, 64023257088 byte 32 huvuden, 32 sektorer/spår, 122114 cylindrar Enheter = cylindrar av 1024 · 512 = 524288 byte Diskidentifierare: 0xca7fa911Enhet Start Början Slut Block Id System/dev/sda1 2 26626 13632000 83 Linux /dev/sda2 26627 122114 48889856 83 LinuxKommando (m för hjälp): u Ändrar visnings-/inmatningsenheter till sektorer
Kommando (m för hjälp): p
Disk /dev/sda: 64,0 GB, 64023257088 byte 32 huvuden, 32 sektorer/spår, 122114 cylindrar, totalt 125045424 sektorer Enheter = sektorer av 1 · 512 = 512 byte Diskidentifierare: 0xca7fa911
Enhet Start Början Slut Block Id System/dev/sda1 1024 27265023 13632000 83 Linux /dev/sda2 27265024 125044735 48889856 83 LinuxKommando (m för hjälp):
The response was:
It's the starting sector that really matters. Doing the maths yields
1024*512/(512*1024) = 1 -> integer (Correct write block alignment) 27265024*512/(512*1024) = 26626 -> integer (Correct write block alignment)starting_sector*sector_size_in_bytes/(erase_block_size_kB*1024_bytes)
Simplified version:
1024/1024 = 1 -> integer (Correct write block alignment) 27265024/1024 = 26626 -> integer (Correct write block alignment)
fdisk -ul /dev/sdaNow check for a + next to any entry. This means that rounding has taken place.. which means it's not correctly done.
Windows Alignment with Linux
List all connected disks and partitions. [sudo fdisk -l]
If your disk is located elsewhere, use the appropriate path instead of /dev/sda.
Each command should be followed by
No changes will be made before you enter the command w.
Quit without saving. [q]
* Start fdisk. [sudo fdisk /dev/sda] * On the fdisk prompt type u and enter to change units to sectors. [u] * Create a new empty dos partition table. [o] * Create a new partition. [n] * Make it an primary partition. [p] * Make it the first partition. [1] * Select starting offset in sectors. Change this value to adjust alignment. [128] * Pressto select the maximum value or pick another one if you're going to use more than one partition. * If you're going to use this partition for Windows.
* Change partition type. [t] * Select HPFS/NTFS. [7]
* List and verify your partition table. [p] * Write your new partition table to the disk. Previous stored data will be lost. [w] * Done.The alignment "128" is invalid for me. Sigh.
mkfs.ntfs
mkfs.ntfs -I -H 255 -S 63 -c /dev/sdxyHrm, I can't remember any of this shit.. so I'm not going to fiddle around.
Scheduler
- [3] anticipatory
- Default for for kernels 2.6 - 2.6.18
- Do not use with SSDs.
- [4] CFQ
- Default for kernels 2.6.19+.
- Do not use with SSDs.
- [5] noop
- Good if you only use SSDs.
- [6] deadline
- The best choice for mixed SSDs and HDDs.
noop performs no logic, and saves CPU cycles. If you use a secondary hard drive, then don't do this. You may end up disliking some of the jerkyness if you are writing and also trying to read.. some reading may end up waiting in line behind the writing.
deadline is suitable for SSDs. Read queues are given a higher priority, because processes usually block on read operations.
Learn what scheduler you're using:
cat /sys/block/sda/queue/schedulerIt probably says (notice the one with square brackets):
noop anticipatory deadline [cfq]
su echo deadline >! /sys/block/sda/queue/scheduler cat /sys/block/sda/queue/scheduler noop anticipatory [deadline] cfqMake the change "permanent" by editing /etc/rc.local and adding the echo line.
If you use GRUB, you can edit /boot/grub/menu.lst and append elevator=deadline to the kernel line that you normally boot up with.
kernel (hd0,5)/boot/vmlinuz BOOT_IMAGE=foo root=UUID=foo => kernel (hd0,5)/boot/vmlinuz BOOT_IMAGE=foo root=UUID=foo elevator=deadline
Speed testing
hdparm:
sudo hdparm -t /dev/sda sudo hdparm -t --direct /dev/sdadd:
sudo dd if=/dev/sda1 of=/dev/null bs=4k skip=0 count=51200If you want to know how much I/O traffic you have on the SSD, you can check with iostat -m -d /dev/sda. This displays MB_read and MB_wrtn for the given drive (measured since system startup). iostat also works for individual partitions. It is provided by the sysstat package.
TODO: request it for unity linux.
TODO: Check out iozone
iozone -T -t 4 s 2g -r 256k -T -I -i0 -i1 -i2
Swap
Kernel swappiness is a controversial topic. The standard setting (60) for kernel swappiness has the effect that inactive (but started) applications will be moved to swap after some time. If the swap partition is placed on a regular HDD in order to reduce wear of the SSD, then reloading the application from swap can take several seconds. This causes annoying delays and bad responsiveness of the system when you return from a coffee break, for example. The solution is setting kernel swappiness to zero, by adding a line vm.swappiness = 0 to /etc/sysctl.conf. A temporary change for trying out the effect is possible by calling echo 0 > /proc/sys/vm/swappiness (as root) from the command line.
Rotational
cat /sys/block/sda/queue/rotationalSome SSDs don't identify themselves as being non-rotational.
su echo 0 >! /sys/block/sdb/queue/rotational
Notes
One guy said:
One last thing - lately I have started to make labels on all my partitions, and then have something like this in /etc/fstab:
LABEL=root / ext3 noatime,minixdf,commit=120,errors=remount-ro 0 1 LABEL=home /home ext3 noatime,minixdf,commit=120,errors=remount-ro 0 2and
# kopt=root=LABEL=root ro init=/sbin/preinitin /boot/grub/menu.lst (/sbin/preinit is a script that mounts /var/log as an tmpfs before the logging starts + some more.)
This makes it easier to move disks around or replace disks. I'm no longer dependent on root being on /dev/sda1 and home on /dev/sdb2 or anything like that, and not dependent on this ID thing that's default on ubuntu.
Partitionless storage drive
If you do not need several partitions on your SSD, and if you do not want to boot from it (or if you have another drive in your system to store the boot loader on), then explicit alignment can be avoided by creating a filesystem on the device as a whole. You don't need fdisk in this case. Just proceed as follows (with your preferred options to mke2fs, this is only an example):
$ sudo mke2fs -t ext2 /dev/sda mke2fs 1.41.1 (01-Sep-2008) /dev/sda is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) ... This filesystem will be automatically checked every 20 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
One suggestion is:
mkfs.ext4 -E stripe-width=128 /dev/sda
Resources
- http://en.wikipedia.org/wiki/Data_structure_alignment
- http://www.linux.org/docs/ldp/howto/Large-Disk-HOWTO-6.html
- Seems pretty old.
- [7] Partition alignment importance under Windows XP (32-bit and 64-bit)..why it helps with stuttering and increases drive working life.
- [8] Guide for Win Xp installation with Diskpar (alignment), nLite, Ramdrive, Page file Tweaks, Browser Tweaks, My Doc folder move and Print Spooler on Vertex
- [9] OCZ SSD...What you need to know in easy to understand format.
- [10] Disk Partition Alignment (Sector Alignment): Make the Case: Save Hundreds of Thousands of Dollars
- [11] Aligning Windows Partitions Without Losing Data