I am trying to automatically determine the size of a ext2 ramdisk filesystem that a directory will make. What I am currently doing is:
BLOCK_COUNT=`du $RAMDISK_FS_DIR| tail -1 |awk '{print $1}'
dd if=/dev/zero of=ramdisk.img bs=1024 count=$BLOCK_COUNT
mke2fs -F ramdisk.img -L "ramdisk" -b 1024 -m 0
tune2fs ramdisk.img -i 0
But when I mount and cp -r
$RAMDISK_FS_DIR
into ramdisk.img
i get messages like these
cp: cannot create directory `ramdisk/var/www': No space left on device
I determined that in my this specific case increasing BLOCK_COUNT by 48 blocks is exactly how much I need for the operation to succeed. I need a way to find this number for arbitrary directory sizes.
Note that my host filesystem is ext4.