I would like to move a partition to a new drive. The old drive has a sector size of 512 bytes while the new one has a sector size of 4096 bytes. I tried doing a dd of the full disk, but that failed because the partition on the old drive was not aligned to 4K boundaries. So instead I created a partition from scratch on the new drive using fdisk, then copied that partition between disks using dd. Finally, I expanded the filesystem on the new drive using resize2fs. This appears to have worked, as I can mount the new partition (read-only so far) and view files, and fsck says it is clean.
But I still have lingering doubts about whether this is a safe thing to do. For example, does the FS care about the sector size in a way that would break things by doing this, or is it shielded from that by the VFS layer or HD itself?
Best Answer
You haven't told us what was the dd command that you tried initially which failed. However, I spent a bit of time checking the source code of dd command (from coreutils package) and looks like we had a problem here.
If you give the error message, I can do a further search. But to me, this is where we got hit. That is aligning 512 byte page boundary with a 4 KiB page boundary doesn't seem right.
Now, coming to the second part, did you create the partition of the second drive (with fdisk) as 512 byte size. However, the sector size advertised by most modern disks to OS is 1 MiB that is 4096 KiB.
In the function update_sector_offset of fdisk.c you will see
*cxt is the descriptor to the fdisk struct.
So, this part is not clear to me. That is, if your new disk advertised the sector size as 4096 KiB or 512 bytes.
Now, coming to the last part.
No, filesystems don't actually care about sector size. And as long as the block size is 4 KiB, things should be fine, because, since virtual page size (in mm context) is 4 KiB, the mmaped IO needs to be aligned with that. In my laptop, the block size and physical sector size is the same.
IO happens in context of block size, not sector size. If due to physical sector size FS encounters any problem, I would be very surprised. However, VFS doesn't come that far. VFS is between application issuing IO and the actual filesystem. What we are discussing is below VFS layer.