setup-rwdev.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # Source Qubes library.
  3. # shellcheck source=init/functions
  4. . /usr/lib/qubes/init/functions
  5. set -e
  6. dev=/dev/xvdb
  7. max_size=10485760 # check at most 10 MiB
  8. if [ -e "$dev" ] ; then
  9. # The private /dev/xvdb device is present.
  10. # check if private.img (xvdb) is empty - all zeros
  11. private_size=$(( $(blockdev --getsz "$dev") * 512))
  12. if [ $private_size -gt $max_size ]; then
  13. private_size=$max_size
  14. fi
  15. if cmp --bytes $private_size "$dev" /dev/zero >/dev/null && { blkid -p "$dev" >/dev/null; [ $? -eq 2 ]; }; then
  16. # the device is empty, create filesystem
  17. echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2
  18. # journals are only useful on reboot, so don't write one in a DispVM
  19. if is_dispvm ; then
  20. journal="-O ^has_journal"
  21. else
  22. journal="-O has_journal"
  23. fi
  24. if ! content=$(mkfs.ext4 -m 0 -q "$journal" "$dev" 2>&1) ; then
  25. echo "Virgin boot of the VM: creation of private.img on $dev failed:" >&2
  26. echo "$content" >&2
  27. echo "Virgin boot of the VM: aborting" >&2
  28. exit 1
  29. fi
  30. if ! content=$(tune2fs -m 0 "$dev" 2>&1) ; then
  31. echo "Virgin boot of the VM: marking free space on $dev as usable failed:" >&2
  32. echo "$content" >&2
  33. echo "Virgin boot of the VM: aborting" >&2
  34. exit 1
  35. fi
  36. fi
  37. echo "Private device management: checking $dev" >&2
  38. if content=$(fsck.ext4 -p "$dev" 2>&1) ; then
  39. echo "Private device management: fsck.ext4 of $dev succeeded" >&2
  40. else
  41. echo "Private device management: fsck.ext4 $dev failed:" >&2
  42. echo "$content" >&2
  43. fi
  44. fi