mount-home.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 | 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. resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed"
  10. tune2fs -m 0 /dev/xvdb
  11. mount /rw
  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. touch /rw/config/rc.local-early
  18. mkdir -p /rw/home
  19. cp -a /home.orig/user /rw/home
  20. mkdir -p /rw/usrlocal
  21. cp -a /usr/local.orig/* /rw/usrlocal
  22. touch /var/lib/qubes/first-boot-completed
  23. fi
  24. # Chown home if user UID have changed - can be the case on template switch
  25. HOME_USER_UID=`ls -dn /rw/home/user | awk '{print $3}'`
  26. if [ "`id -u user`" -ne "$HOME_USER_UID" ]; then
  27. find /rw/home/user -uid "$HOME_USER_UID" -print0 | xargs -0 chown user:user
  28. fi
  29. # Old Qubes versions had symlink /home -> /rw/home; now we use mount --bind
  30. if [ -L /home ]; then
  31. rm /home
  32. mkdir /home
  33. fi
  34. if [ -e /var/run/qubes-service/qubes-dvm ]; then
  35. mount --bind /home_volatile /home
  36. touch /etc/this-is-dvm
  37. #If user have customized DispVM settings, use its home instead of default dotfiles
  38. if [ -e /rw/home/user/.qubes-dispvm-customized ]; then
  39. cp -af /rw/home/user /home/
  40. else
  41. cat /etc/dispvm-dotfiles.tbz | tar -xjf- --overwrite -C /home/user --owner user 2>&1 >/tmp/dispvm-dotfiles-errors.log
  42. fi
  43. else
  44. mount /home
  45. fi