qubes-sysinit.sh 3.1 KB

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