1781568d08
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.
37 lines
1.2 KiB
Bash
Executable File
37 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
dev=/dev/xvdb
|
|
|
|
if [ -e "$dev" ] ; then
|
|
# The private /dev/xvdb device is present.
|
|
|
|
# check if private.img (xvdb) is empty - all zeros
|
|
private_size_512=$(blockdev --getsz "$dev")
|
|
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
|
|
echo "Virgin boot of the VM: creation of private.img on $dev failed:" >&2
|
|
echo "$content" >&2
|
|
echo "Virgin boot of the VM: aborting" >&2
|
|
exit 1
|
|
fi
|
|
if ! content=$(tune2fs -m 0 "$dev" 2>&1) ; then
|
|
echo "Virgin boot of the VM: marking free space on $dev as usable failed:" >&2
|
|
echo "$content" >&2
|
|
echo "Virgin boot of the VM: aborting" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Private device management: checking $dev" >&2
|
|
if content=$(fsck.ext4 -p "$dev" 2>&1) ; then
|
|
echo "Private device management: fsck.ext4 of $dev succeeded" >&2
|
|
else
|
|
echo "Private device management: fsck.ext4 $dev failed:" >&2
|
|
echo "$content" >&2
|
|
fi
|
|
fi
|