mount-home.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. # check if private.img (xvdb) is empty - all zeros
  3. private_size_512=`blockdev --getsz /dev/xvdb`
  4. if dd if=/dev/zero bs=512 count=$private_size_512 2>/dev/null | diff /dev/xvdb - >/dev/null; then
  5. # the device is empty, create filesystem
  6. echo "--> Virgin boot of the VM: creating filesystem on private.img"
  7. mkfs.ext4 -m 0 -q /dev/xvdb || exit 1
  8. fi
  9. tune2fs -m 0 /dev/xvdb
  10. mount /rw
  11. resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed"
  12. if ! [ -d /rw/home ] ; then
  13. echo
  14. echo "--> Virgin boot of the VM: Populating /rw/home"
  15. mkdir -p /rw/config
  16. touch /rw/config/rc.local
  17. cat > /rw/config/rc.local <<EOF
  18. #!/bin/sh
  19. # This script will be executed at every VM startup, you can place your own
  20. # custom commands here. This include overriding some configuration in /etc,
  21. # starting services etc.
  22. #
  23. # You need to make this script executable to have it enabled.
  24. # Example for overriding the whole CUPS configuration:
  25. # rm -rf /etc/cups
  26. # ln -s /rw/config/cups /etc/cups
  27. # systemctl --no-block restart cups
  28. EOF
  29. touch /rw/config/qubes-firewall-user-script
  30. cat > /rw/config/qubes-firewall-user-script <<EOF
  31. #!/bin/sh
  32. # This script is called in ProxyVM after firewall every update (configuration
  33. # change, starting some VM etc). This is good place to write own custom
  34. # firewall rules, in addition to autogenerated one. Remember that in most cases
  35. # you'll need to insert the rules at the beginning (iptables -I) to have it
  36. # efective.
  37. #
  38. # You need to make this script executable to have it enabled.
  39. EOF
  40. touch /rw/config/suspend-module-blacklist
  41. cat > /rw/config/suspend-module-blacklist <<EOF
  42. # You can list here modules you want to be unloaded before going to sleep. This
  43. # file is used only if the VM has any PCI device assigned. Modules will be
  44. # automatically loaded after resume.
  45. EOF
  46. mkdir -p /rw/home
  47. cp -a /home.orig/user /rw/home
  48. mkdir -p /rw/usrlocal
  49. cp -a /usr/local.orig/* /rw/usrlocal
  50. touch /var/lib/qubes/first-boot-completed
  51. fi
  52. # Chown home if user UID have changed - can be the case on template switch
  53. HOME_USER_UID=`ls -dn /rw/home/user | awk '{print $3}'`
  54. if [ "`id -u user`" -ne "$HOME_USER_UID" ]; then
  55. find /rw/home/user -uid "$HOME_USER_UID" -print0 | xargs -0 chown user:user
  56. fi
  57. # Old Qubes versions had symlink /home -> /rw/home; now we use mount --bind
  58. if [ -L /home ]; then
  59. rm /home
  60. mkdir /home
  61. fi
  62. if [ -e /var/run/qubes-service/qubes-dvm ]; then
  63. mount --bind /home_volatile /home
  64. touch /etc/this-is-dvm
  65. #If user have customized DispVM settings, use its home instead of default dotfiles
  66. if [ -e /rw/home/user/.qubes-dispvm-customized ]; then
  67. cp -af /rw/home/user /home/
  68. else
  69. cat /etc/dispvm-dotfiles.tbz | tar -xjf- --overwrite -C /home/user --owner user 2>&1 >/tmp/dispvm-dotfiles-errors.log
  70. fi
  71. else
  72. mount /home
  73. fi