core-agent-linux/init/setup-rwdev.sh
Marek Marczykowski-Górecki 9f9c3c56fc
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 04:21:59 +01:00

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 dd if=/dev/zero bs=512 count="$private_size_512" 2>/dev/null | 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