@ -186,6 +186,13 @@ let format' = format; in let
echo " $ a c c "
}
# Approximative percentage of reserved space in an ext4 fs over 512MiB.
# 0.05208587646484375
# × 1000, integer part: 52
compute_fudge ( ) {
echo $ ( ( $ 1 * 52 / 1000 ) )
}
mkdir $ out
root = " $ P W D / r o o t "
@ -252,15 +259,22 @@ let format' = format; in let
'' }
# Compute required space in filesystem blocks
requiredSpace = $ ( find . ! - type d - exec ' du' ' - - apparent-size' ' - - block-size' " ${ blockSize } " ' { } ' ' ; ' | cut - f1 | sum_lines )
# Convert to bytes
requiredSpace = $ ( ( requiredSpace * $ { blockSize } ) )
diskSize = $ ( ( requiredSpace + additionalSpace ) )
diskUsage = $ ( find . ! - type d - exec ' du' ' - - apparent-size' ' - - block-size' " ${ blockSize } " ' { } ' ' ; ' | cut - f1 | sum_lines )
# Each inode takes space!
numInodes = $ ( find . | wc - l )
# Convert to bytes, inodes take two blocks each!
diskUsage = $ ( ( ( diskUsage + 2 * numInodes ) * $ { blockSize } ) )
# Then increase the required space to account for the reserved blocks.
fudge = $ ( compute_fudge $ diskUsage )
requiredFilesystemSpace = $ ( ( diskUsage + fudge ) )
diskSize = $ ( ( requiredFilesystemSpace + additionalSpace ) )
truncate - s " $ d i s k S i z e " $ diskImage
printf " A u t o m a t i c d i s k s i z e . . . \n "
printf " S p a c e n e e d e d : % d b y t e s \n " $ requiredSpace
printf " C l o s u r e s p a c e u s e : % d b y t e s \n " $ diskUsage
printf " f u d g e : % d b y t e s \n " $ fudge
printf " F i l e s y s t e m s i z e n e e d e d : % d b y t e s \n " $ requiredFilesystemSpace
printf " A d d i t i o n a l s p a c e : % d b y t e s \n " $ additionalSpace
printf " D i s k i m a g e s i z e : % d b y t e s \n " $ diskSize
'' e l s e ''