I need to identify the last sector used by an ext4 filesystem so that I can move it to another device.
The filesystem has been shrunk (with resize2fs
) and is smaller than the partition that contains it, so I am not asking how to find the last sector in the partition.
I have done tune2fs -l
and identified that
Block count: 48934
First block: 0
Block size: 4096
From that I would postulate that the filesystem uses 48934 * 4096 / 512 = 391472 sectors and that I can move that many sectors with dd
starting at the first sector of the partition (as reported by gdisk
).
I am uncertain whether that block count includes any ext4 overhead or if there is additional size that needs to be considered. I read this question which implies there is additional space to be considered.
dd if=/dev/sdd2 of=/dev/sdc5 bs=512 count=395568
(It's LUKS and I also copied the LUKS header). So far, so good. – starfry Oct 05 '16 at 09:28dd
. Do the loopback mount and usecat
, it's the easiest way to ensure you're copying the right thing, and it's faster. – Gilles 'SO- stop being evil' Oct 07 '16 at 06:42cat
be faster thandd
with alo
-device? – Tom Hale Nov 07 '16 at 09:46dd
block size, and more so withdd
's default tiny block size. – Gilles 'SO- stop being evil' Nov 07 '16 at 11:02