2016-10-22 17:43:16 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-02-14 17:35:05 +01:00
|
|
|
# Source Qubes library.
|
|
|
|
# shellcheck source=init/functions
|
|
|
|
. /usr/lib/qubes/init/functions
|
|
|
|
|
2016-10-22 17:43:16 +02:00
|
|
|
set -e
|
|
|
|
|
2016-10-26 14:59:50 +02:00
|
|
|
dev=/dev/xvdb
|
2018-07-03 21:52:32 +02:00
|
|
|
max_size=1073741824 # check at most 1 GiB
|
2016-10-26 14:59:50 +02:00
|
|
|
|
|
|
|
if [ -e "$dev" ] ; then
|
2016-10-22 17:43:16 +02:00
|
|
|
# The private /dev/xvdb device is present.
|
|
|
|
|
|
|
|
# check if private.img (xvdb) is empty - all zeros
|
2018-07-03 21:52:32 +02:00
|
|
|
private_size=$(( $(blockdev --getsz "$dev") * 512))
|
|
|
|
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
|
2016-10-22 17:43:16 +02:00
|
|
|
# the device is empty, create filesystem
|
2016-10-26 14:59:50 +02:00
|
|
|
echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2
|
2020-02-14 17:35:05 +01:00
|
|
|
# journals are only useful on reboot, so don't write one in a DispVM
|
|
|
|
if is_dispvm ; then
|
|
|
|
journal="-O ^has_journal"
|
|
|
|
else
|
|
|
|
journal="-O has_journal"
|
|
|
|
fi
|
|
|
|
if ! content=$(mkfs.ext4 -m 0 -q "$journal" "$dev" 2>&1) ; then
|
2016-10-26 14:59:50 +02:00
|
|
|
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
|
2016-10-22 17:43:16 +02:00
|
|
|
fi
|
|
|
|
|
Use online resize2fs, and run filesystem check only when needed
When trying offline resize2fs, it require running fsck first, which
takes time, especially on large volumes. And in most cases, resize2fs
will notice that no action is needed - after wasting some time on fsck.
To remedy this, use resize2fs in online mode (on mounted filesystem).
And drop fsck call if it fails (filesystem is already mounted
read-write, running fsck isn't good idea).
But do not remove fsck call completely - still call it, but without '-f'
flag, so it run actual check only when really needed (unclean shutdown,
last check far in the past etc).
Fixes QubesOS/qubes-issues#979
Fixes QubesOS/qubes-issues#2583
2017-02-27 02:13:42 +01:00
|
|
|
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
|
2016-10-26 14:59:50 +02:00
|
|
|
else
|
Use online resize2fs, and run filesystem check only when needed
When trying offline resize2fs, it require running fsck first, which
takes time, especially on large volumes. And in most cases, resize2fs
will notice that no action is needed - after wasting some time on fsck.
To remedy this, use resize2fs in online mode (on mounted filesystem).
And drop fsck call if it fails (filesystem is already mounted
read-write, running fsck isn't good idea).
But do not remove fsck call completely - still call it, but without '-f'
flag, so it run actual check only when really needed (unclean shutdown,
last check far in the past etc).
Fixes QubesOS/qubes-issues#979
Fixes QubesOS/qubes-issues#2583
2017-02-27 02:13:42 +01:00
|
|
|
echo "Private device management: fsck.ext4 $dev failed:" >&2
|
2016-10-22 17:43:16 +02:00
|
|
|
echo "$content" >&2
|
|
|
|
fi
|
|
|
|
fi
|