From 1781568d088e96c2e3c9ba223140ca3fcaef6d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 27 Feb 2018 05:12:44 +0100 Subject: [PATCH] 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. --- init/setup-rwdev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/setup-rwdev.sh b/init/setup-rwdev.sh index 21dc839..3796be5 100755 --- a/init/setup-rwdev.sh +++ b/init/setup-rwdev.sh @@ -9,7 +9,7 @@ if [ -e "$dev" ] ; then # check if private.img (xvdb) is empty - all zeros 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 echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2 if ! content=$(mkfs.ext4 -m 0 -q "$dev" 2>&1) ; then