Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Linux with 4 hard drives that use 4k sectors. There are several layers between my filesystem and the raw devices: Disks > Linux Raid 5 > dm-crypt > LVM.

Every resource I have found has explained how to set up each layer to ensure that writes on top of that layer will be aligned to the 4k sector boundary. However, I have not found anything that explains how to verify that the writes made to the hard drives are actually happening at 4k boundaries.

I'm not interested in re-examining my set up to use logic to determine if it is aligned correctly. I want to examine what is actually happening when writes are made to the disk.

How can I log or view the addresses and size of the writes that are being made to my hard drives, so I can verify that they are correctly aligned?

share|improve this question
add comment

2 Answers 2

Asked myself the same question some time ago and simply did the following:

Wrote with the shell a couple of times a rather unusual string to a file (something like "WackaWacka") Then simply searched with a hex dump (used od) the actual content of the disk and checked wether the first occurence of the string was stored exactly on the beginning of a 4k block.

Hint: Do not use an editor - it may create temporary files you don't know of which may contain the strings, too. Do it this way:

 $ for i in 1 2 3 4 5 ...
 >  do
 >   echo "WackaWacka!"
 >  done > mytestfile

So .sh_history may contain the search string, but not 5 times in a row ;-)

And then, just search:

 # sync
 # od -c /dev/sda | grep 'W   a   c   k   a'

Well, it's best done on a rather empty disk to avoid serching through Gigabytes of data ;-)

share|improve this answer
    
Since dm-crypt is one of the layers in my stack, this solution is not sufficient, since these characters will not be written to the disk. –  Brian Pellin Sep 27 '11 at 20:54
    
That's bad. Only other solution I could think of is changing explicitely one 4k block in a file and check if only contents of one physical block on the disk has changed (or if two consecutive blocks are affected) - and this will only work if data is not compressed by the encryption layer. Nevertheless one has to know, on which disk-block the file is stored and searching for any changes may be difficult on large disks. –  ktf Sep 28 '11 at 7:50
add comment

Write a 4k block and watch how much data is read/written with iostat (The 'Blk_read' 'Blk_wrtn' columns). If the data is not aligned, a write will trigger reads first and will trigger more than 4k of writes.

You'll need to be careful to not measure any metadata updates, though... or just drown them out by making 1000s of 4k writes.... So make sure nothing else is scanning disks or holding open files (I think lsof would be sufficient?), then open a new file, wait, run iostat, write 4k to the file, sync the write (or just wait a while?) then check iostat again.

This seems to give a reasonable output for me:

iostat  -d /dev/hdb3
dd if=/dev/urandom of=/mount/path/ofhdb3/tmptest bs=4k count=10000 conv=fdatasync
iostat  -d /dev/hdb3

Note iostat's man page claims to report in 512 byte blocks, and I see just over 80000 additional blocks were written, and no blocks read. If your alignment is off, you'll see an similar number of reads (since to write a mis-aligned 4k, requires reading the two blocks impacted, mutating them, and writing them back). In fact, the only reason alignment is important is to avoid such reads (so that's really what you want to look for: does a write workload trigger reads?)

share|improve this answer
    
Do you know if iostat is reporting on the number of reads/writes that the OS makes to the block device, or is this number based on the drive reporting how many blocks it has read and written? –  Brian Pellin Oct 18 '11 at 3:07
    
I suspect its from the OS block device abstraction, not directly from the drive, but I don't know for sure. I'm also not sure if it would be "above" or "below" the dm-crypt layer, either. –  P.T. Oct 18 '11 at 5:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.