Speed up initial /rw setup

On first VM's boot, setup-rwdev.sh script create filesystem on
/dev/xvdb. But it does so only after checking if /dev/xvdb is really
empty, by comparing it to /dev/zero. Speed up reads from /dev/zero bu
using larger blocks (default of head - 8k, instead of explicit 512).
This speed up the check over 5 times.
This commit is contained in:
Marek Marczykowski-Górecki 2018-02-27 05:12:44 +01:00
parent ddbd24a815
commit 1781568d08
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -9,7 +9,7 @@ if [ -e "$dev" ] ; then
# check if private.img (xvdb) is empty - all zeros # check if private.img (xvdb) is empty - all zeros
private_size_512=$(blockdev --getsz "$dev") private_size_512=$(blockdev --getsz "$dev")
if dd if=/dev/zero bs=512 count="$private_size_512" 2>/dev/null | diff "$dev" - >/dev/null; then if head -c $(( private_size_512 * 512 )) /dev/zero | diff "$dev" - >/dev/null; then
# the device is empty, create filesystem # the device is empty, create filesystem
echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2 echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2
if ! content=$(mkfs.ext4 -m 0 -q "$dev" 2>&1) ; then if ! content=$(mkfs.ext4 -m 0 -q "$dev" 2>&1) ; then