qubes-sysinit.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. # Source Qubes library.
  3. # shellcheck source=init/functions
  4. . /usr/lib/qubes/init/functions
  5. # List of services enabled by default (in case of absence of qubesdb entry)
  6. DEFAULT_ENABLED_NETVM="network-manager qubes-network qubes-update-check qubes-updates-proxy"
  7. DEFAULT_ENABLED_PROXYVM="qubes-network qubes-firewall qubes-update-check"
  8. DEFAULT_ENABLED_APPVM="cups qubes-update-check"
  9. DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_APPVM updates-proxy-setup"
  10. DEFAULT_ENABLED=""
  11. # devices emulated by qemu, first list of vendor IDs then list of device IDs:
  12. qemu_devices="0x8086
  13. 0x8086
  14. 0x8086
  15. 0x8086
  16. 0x8086
  17. 0x5853
  18. 0x1013
  19. 0x1237
  20. 0x7000
  21. 0x7010
  22. 0x7020
  23. 0x7113
  24. 0x0001
  25. 0x00b8
  26. "
  27. if [ -z "$(ls /sys/bus/pci/devices/)" ] || \
  28. [ "$(cat /sys/bus/pci/devices/*/{vendor,device})" != "$qemu_devices" ]; then
  29. # do not enable meminfo-writer (so qmemman for this domain) when any real PCI
  30. # device is present
  31. DEFAULT_ENABLED="$DEFAULT_ENABLED meminfo-writer"
  32. DEFAULT_ENABLED_APPVM="$DEFAULT_ENABLED_APPVM meminfo-writer"
  33. DEFAULT_ENABLED_PROXYVM="$DEFAULT_ENABLED_PROXYVM meminfo-writer"
  34. DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_TEMPLATEVM meminfo-writer"
  35. fi
  36. if systemd_version_changed ; then
  37. # Ensure we're running right version of systemd (the one started by initrd may be different)
  38. systemctl daemon-reexec
  39. fi
  40. # Wait for xenbus initialization
  41. while [ ! -e /dev/xen/xenbus ] && [ -e /proc/xen/xenbus ]; do
  42. sleep 0.1
  43. done
  44. mkdir -p /var/run/qubes
  45. chgrp qubes /var/run/qubes
  46. chmod 0775 /var/run/qubes
  47. mkdir -p /var/run/qubes-service
  48. mkdir -p /var/run/xen-hotplug
  49. # Set permissions to /proc/xen/xenbus, so normal user can talk to xenstore, to
  50. # open vchan connection. Note that new code uses /dev/xen/xenbus (which have
  51. # permissions set by udev), so this probably can go away soon
  52. chmod 666 /proc/xen/xenbus
  53. # Set permissions to /proc/xen/privcmd, so a user in qubes group can access
  54. chmod 660 /proc/xen/privcmd
  55. chgrp qubes /proc/xen/privcmd
  56. [ -e /proc/u2mfn ] || modprobe u2mfn
  57. # Set permissions to files needed by gui-agent
  58. chmod 666 /proc/u2mfn
  59. # Set default services depending on VM type
  60. is_appvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_APPVM && touch /var/run/qubes/this-is-appvm
  61. is_netvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_NETVM && touch /var/run/qubes/this-is-netvm
  62. is_proxyvm && DEFAULT_ENABLED=$DEFAULT_ENABLED_PROXYVM && touch /var/run/qubes/this-is-proxyvm
  63. is_templatevm && DEFAULT_ENABLED=$DEFAULT_ENABLED_TEMPLATEVM && touch /var/run/qubes/this-is-templatevm
  64. # Enable default services
  65. for srv in $DEFAULT_ENABLED; do
  66. touch "/var/run/qubes-service/$srv"
  67. done
  68. # Enable services
  69. for srv in $(qubesdb-multiread /qubes-service/ 2>/dev/null |grep ' = 1'|cut -f 1 -d ' '); do
  70. touch "/var/run/qubes-service/$srv"
  71. done
  72. # Disable services
  73. for srv in $(qubesdb-multiread /qubes-service/ 2>/dev/null |grep ' = 0'|cut -f 1 -d ' '); do
  74. rm -f "/var/run/qubes-service/$srv"
  75. done
  76. # Prepare environment for other services
  77. echo > /var/run/qubes-service-environment
  78. debug_mode=$(qubesdb-read /qubes-debug-mode 2> /dev/null)
  79. if [ -n "$debug_mode" ] && [ "$debug_mode" -gt 0 ]; then
  80. echo "GUI_OPTS=-vv" >> /var/run/qubes-service-environment
  81. fi
  82. exit 0