setup-rwdev.sh: Only check first 1 GiB for zeros
As described in QubesOS/qubes-issues#3758, a VM may fail to start
if the volume is large. This because the whole volume is read to
ensure it's empty (=all zeros).
This changes limits the check to the first 1 GiB of the private
volume. As additional safety, a scan with blkid is done.
Fixes https://github.com/QubesOS/qubes-issues/issues/3758
(cherry picked from commit 8ff9cbe299
)
This commit is contained in:
parent
bfe284e7bf
commit
7422d4b27b
|
@ -3,13 +3,17 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
dev=/dev/xvdb
|
dev=/dev/xvdb
|
||||||
|
max_size=1073741824 # check at most 1 GiB
|
||||||
|
|
||||||
if [ -e "$dev" ] ; then
|
if [ -e "$dev" ] ; then
|
||||||
# The private /dev/xvdb device is present.
|
# The private /dev/xvdb device is present.
|
||||||
|
|
||||||
# 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=$(( $(blockdev --getsz "$dev") * 512))
|
||||||
if dd if=/dev/zero bs=512 count="$private_size_512" 2>/dev/null | diff "$dev" - >/dev/null; then
|
if [ $private_size -gt $max_size ]; then
|
||||||
|
private_size=$max_size
|
||||||
|
fi
|
||||||
|
if cmp --bytes $private_size "$dev" /dev/zero >/dev/null && { blkid -p "$dev" >/dev/null; [ $? -eq 2 ]; }; 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user