diff --git a/misc/dispvm-prerun.sh b/misc/dispvm-prerun.sh index 01ab6fe..91b90cb 100755 --- a/misc/dispvm-prerun.sh +++ b/misc/dispvm-prerun.sh @@ -32,10 +32,4 @@ echo "Closing windows..." sleep 1 fuser -vkm /rw -if [ -e /rw/home/user/.qubes-dispvm-customized ]; then - cp -af /rw/home/user /home/ -else - cat /etc/dispvm-dotfiles.tbz | tar -xjf- --overwrite -C /home/user --owner user 2>&1 >>/tmp/dispvm-dotfiles-errors.log -fi - echo done. diff --git a/rpm_spec/core-vm.spec b/rpm_spec/core-vm.spec index 4461d5f..2565bbf 100644 --- a/rpm_spec/core-vm.spec +++ b/rpm_spec/core-vm.spec @@ -546,6 +546,7 @@ The Qubes core startup configuration for SystemD init. /lib/systemd/system/qubes-dvm.service /lib/systemd/system/qubes-misc-post.service /lib/systemd/system/qubes-firewall.service +/lib/systemd/system/qubes-mount-home.service /lib/systemd/system/qubes-netwatcher.service /lib/systemd/system/qubes-network.service /lib/systemd/system/qubes-sysinit.service @@ -561,6 +562,7 @@ The Qubes core startup configuration for SystemD init. /usr/lib/qubes/init/network-proxy-setup.sh /usr/lib/qubes/init/misc-post.sh /usr/lib/qubes/init/misc-post-stop.sh +/usr/lib/qubes/init/mount-home.sh /usr/lib/qubes/init/qubes-sysinit.sh /usr/lib/qubes/init/ModemManager.service /usr/lib/qubes/init/NetworkManager.service @@ -580,7 +582,7 @@ The Qubes core startup configuration for SystemD init. %post systemd -for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-netwatcher qubes-network qubes-firewall qubes-updates-proxy qubes-qrexec-agent; do +for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-home qubes-netwatcher qubes-network qubes-firewall qubes-updates-proxy qubes-qrexec-agent; do /bin/systemctl --no-reload enable $srv.service 2> /dev/null done @@ -648,6 +650,6 @@ if [ "$1" != 0 ] ; then exit 0 fi -for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-netwatcher qubes-network qubes-qrexec-agent; do +for srv in qubes-dvm qubes-sysinit qubes-misc-post qubes-mount-home qubes-netwatcher qubes-network qubes-qrexec-agent; do /bin/systemctl disable $srv.service do diff --git a/vm-systemd/misc-post.sh b/vm-systemd/misc-post.sh index 27b07e2..d3717d3 100755 --- a/vm-systemd/misc-post.sh +++ b/vm-systemd/misc-post.sh @@ -22,39 +22,6 @@ fi # qubesdb-read fails INTERFACE=eth0 /usr/lib/qubes/setup-ip -if [ -e /dev/xvdb -a ! -e /etc/this-is-dvm ] ; then - resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed" - tune2fs -m 0 /dev/xvdb - mount /rw - - if ! [ -d /rw/home ] ; then - echo - echo "--> Virgin boot of the VM: Linking /home to /rw/home" - - mkdir -p /rw/config - touch /rw/config/rc.local - touch /rw/config/rc.local-early - - mkdir -p /rw/home - cp -a /home.orig/user /rw/home - - mkdir -p /rw/usrlocal - cp -a /usr/local.orig/* /rw/usrlocal - - touch /var/lib/qubes/first-boot-completed - fi - # Chown home if user UID have changed - can be the case on template switch - HOME_USER_UID=`ls -dn /rw/home/user | awk '{print $3}'` - if [ "`id -u user`" -ne "$HOME_USER_UID" ]; then - find /rw/home/user -uid "$HOME_USER_UID" -print0 | xargs -0 chown user:user - fi - if [ -L /home ]; then - rm /home - mkdir /home - fi - mount /home -fi - [ -x /rw/config/rc.local ] && /rw/config/rc.local # Start services which haven't own proper systemd unit: diff --git a/vm-systemd/mount-home.sh b/vm-systemd/mount-home.sh new file mode 100644 index 0000000..3307551 --- /dev/null +++ b/vm-systemd/mount-home.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +resize2fs /dev/xvdb 2> /dev/null || echo "'resize2fs /dev/xvdb' failed" +tune2fs -m 0 /dev/xvdb +mount /rw + +if ! [ -d /rw/home ] ; then + echo + echo "--> Virgin boot of the VM: Populating /rw/home" + + mkdir -p /rw/config + touch /rw/config/rc.local + touch /rw/config/rc.local-early + + mkdir -p /rw/home + cp -a /home.orig/user /rw/home + + mkdir -p /rw/usrlocal + cp -a /usr/local.orig/* /rw/usrlocal + + touch /var/lib/qubes/first-boot-completed +fi + +# Chown home if user UID have changed - can be the case on template switch +HOME_USER_UID=`ls -dn /rw/home/user | awk '{print $3}'` +if [ "`id -u user`" -ne "$HOME_USER_UID" ]; then + find /rw/home/user -uid "$HOME_USER_UID" -print0 | xargs -0 chown user:user +fi + +# Old Qubes versions had symlink /home -> /rw/home; now we use mount --bind +if [ -L /home ]; then + rm /home + mkdir /home +fi + +if [ -e /var/run/qubes-service/qubes-dvm ]; then + mount --bind /home_volatile /home + touch /etc/this-is-dvm + + #If user have customized DispVM settings, use its home instead of default dotfiles + if [ -e /rw/home/user/.qubes-dispvm-customized ]; then + cp -af /rw/home/user /home/ + else + cat /etc/dispvm-dotfiles.tbz | tar -xjf- --overwrite -C /home/user --owner user 2>&1 >/tmp/dispvm-dotfiles-errors.log + fi +else + mount /home +fi diff --git a/vm-systemd/prepare-dvm.sh b/vm-systemd/prepare-dvm.sh index f59f06b..ac1022f 100755 --- a/vm-systemd/prepare-dvm.sh +++ b/vm-systemd/prepare-dvm.sh @@ -11,17 +11,10 @@ possibly_run_save_script() } if true; then - if [ -L /home ]; then - rm /home - mkdir /home - fi - mount --bind /home_volatile /home - touch /etc/this-is-dvm systemctl --ignore-dependencies start qubes-gui-agent.service while ! xenstore-read qubes-save-request 2>/dev/null ; do usleep 10 done - mount /rw possibly_run_save_script umount /rw dmesg -c >/dev/null diff --git a/vm-systemd/qubes-misc-post.service b/vm-systemd/qubes-misc-post.service index 8aec208..8450a12 100644 --- a/vm-systemd/qubes-misc-post.service +++ b/vm-systemd/qubes-misc-post.service @@ -1,6 +1,6 @@ [Unit] Description=Qubes misc post-boot actions -After=qubes-dvm.service +After=qubes-dvm.service qubes-mount-home.service [Service] Type=oneshot diff --git a/vm-systemd/qubes-mount-home.service b/vm-systemd/qubes-mount-home.service new file mode 100644 index 0000000..93b3f93 --- /dev/null +++ b/vm-systemd/qubes-mount-home.service @@ -0,0 +1,13 @@ +[Unit] +Description=Mount /rw and /home, initialize them if needed +Before=qubes-gui-agent.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/qubes/init/mount-home.sh +ExecStop=/sbin/fuser -kMm /home ; /bin/umount /home +ExecStopPost=-/bin/umount /rw + +[Install] +WantedBy=multi-user.target