Quick Quality-of-Life Improvements

VM Management

  • Reduce VM boot time - Debian 12 only - [TemplateVM] Enter sudo cp /lib/systemd/system/systemd-binfmt.service /etc/systemd/system, then delete After=local-fs.target from /etc/systemd/system/systemd-binfmt.service @renehoj

  • Shut down selected window’s VM - [dom0] Create /bin/halt-vm-by-window containing the code below, run chmod +x /bin/halt-vm-by-window, then map to shortcut @tasket

    halt-vm-by-window
    #!/bin/bash
    
    CUR_WIN_ID=`xdotool getwindowfocus`
    CUR_VM=`xprop _QUBES_VMNAME -id $CUR_WIN_ID |cut -d \" -f2`
    
    qvm-run $CUR_VM 'xdotool search --name "Mozilla Firefox" key ctrl+q'
    qvm-run $CUR_VM 'xdotool search --name "Mozilla Thunderbird" key ctrl+q'
    sleep 4
    /usr/bin/qvm-shutdown $CUR_VM  --wait --timeout=40
    
  • Memory warning notifications - [dom0] Create the files below as needed, then for each file: chmod +x [FILENAME], enter crontab -e, then add */5 * * * * [FILENAME] and save @ddevz

    /bin/dom0-Memory-Notification
    #!/bin/bash
    
    FREE_MEMORY=$((`free -m | grep '^Mem' | awk '{print $7}'`))
    if (( $FREE_MEMORY < 500 )); then
        notify-send  --expire-time=360000 --urgency=critical 'dom0: Low memory' "Remaining: $FREE_MEMORY MBs"
    fi
    
    /bin/Xen-Memory-Notification
    #!/bin/bash
    
    FREE_MEMORY=$((`xl info | grep free_memory | sed 's/^.*:\([0-9]*\)/\1/'` / 1000))
    if (( $FREE_MEMORY < 8 )); then
        notify-send --expire-time=360000 --urgency=critical 'Xen: Low memory' "Remaining: 
    $FREE_MEMORY GBs"
    fi
    

 

Input Devices

  • Prevent loss of control from sys-usb shutdown - [dom0] crontab -e, then enter * * * * * qvm-start --skip-if-running sys-usb > /dev/null 2>&1 and save. Reverse the change by commenting out that line @SteveC

  • Create a toggle to hide the cursor - [dom0] Install unclutter, run the code below (expandable), then map toggle-unclutter.sh to a key @ludovic vecna13 from the 2676 issue

    Hide cursor (dom0)
    mkdir $HOME/bin
    cat << 'EOF' | tee $HOME/bin/toggle-unclutter.sh
    
    #! /bin/sh
    if pgrep unclutter &> /dev/null 2>&1
    then
       killall unclutter
    else
       unclutter -idle 1 &
    fi
    EOF
    
    chmod +x $HOME/bin/toggle-unclutter.sh
    
  • Trigger the QubesOS widgets via keyboard - [dom0] In dom0 create a script containing the code below (expandable), make it executable (chmod +x) and bind to keyboard shortcut @Bearillo

    widget-click.sh

    Call this script with either the argument devices (so widget-click.sh devices) or domains to open the respective widget.

    #!/bin/bash
    # call with argument 'devices' or 'domains'
    sleep 0.1
    eval $(xdotool search --onlyvisible --name "qui-$1" getwindowgeometry --shell)
    xdotool mousemove $X $Y click 1 mousemove restore
    
  • Trigger the QubesOS app menu via keyboard - [dom0] In dom0 create a script containing the code below (expandable), make it executable (chmod +x) and bind to keyboard shortcut @Bearillo

    qubes-menu.sh

    Note that you may need to adjust the numbers if your screen is not 1080p.

    #!/bin/bash
    eval $(xdotool getmouselocation --shell)
    xdotool mousemove 5 5
    gdbus call --session --dest org.qubesos.appmenu --object-path "/org/qubesos/appmenu" --method org.freedesktop.Application.Activate "{}"
    if [ $X -lt 720 ] && [ $Y -lt 775 ]; then
    	X=720	# prevent the mouse from selecting items in the app menu when opening it with the keyboard
    fi		# note that these values may need adjusting if using a screen with a resolution other than 1080p
    xdotool mousemove $X $Y
    

 

Storage

  • Send files directly to external storage mounted in other qube - [AppVM] Run the code below (expandable), then copy/move your file(s) @SteveC

    In destination qube:

    In the following instructions [ORIGIN QUBE] is the qube name without brackets or slashes!

    mkdir ~/QubesIncoming
    mv ~/QubesIncoming/[ORIGIN QUBE] ~/QubesIncoming/[ORIGIN QUBE]_backup
    ln -s [MOUNT POINT] ~/QubesIncoming/[ORIGIN QUBE]
    

 

Networking

  • Toggle NetVM of qube in focus - [dom0] In dom0 create the following script, make it executable (chmod +x) and bind to keyboard shortcut (expandable) @Bearillo

    vm-give-default-network
    #!/bin/bash
    
    CUR_WIN_ID=$(xdotool getwindowfocus)
    CUR_VM=$(xprop _QUBES_VMNAME -id $CUR_WIN_ID | cut -d \" -f 2)
    
    if [[ "$CUR_VM" != *"not found"* ]];then
    	if ! qvm-prefs "$CUR_VM" netvm | head -c1 | grep -E '.';then
    		
    		TEXT="TOR"
    		while read -r line
    	       	do
    			if [[ "$line" == "anon-vm" ]];then
    				TEXT="TOR"
    				break
    			else
    				TEXT="DEFAULT"
    			fi
    		done <<< $(qvm-tags "$CUR_VM")
    
    		ANSWER=$(notify-send -A Y="Yes" -A N="No" "Grant $TEXT network access to $CUR_VM" "Do you want to grant $TEXT network access to $CUR_VM?")
    		
    		if [[ "$ANSWER" == "Y" ]];then
    			if [[ "$TEXT" == "DEFAULT" ]];then
    				qvm-start --skip-if-running $(qubes-prefs default_netvm) &&
    				qvm-prefs "$CUR_VM" netvm -D &&
                    		notify-send "Granted $CUR_VM $TEXT network access!" "The netvm of $CUR_VM was set to $(qvm-prefs "$CUR_VM" netvm)."
    			else
    				qvm-start --skip-if-running sys-whonix &&
    				qvm-prefs "$CUR_VM" netvm sys-whonix &&
    				notify-send "Granted $CUR_VM $TEXT network access!" "The netvm of $CUR_VM was set to $(qvm-prefs "$CUR_VM" netvm)."
    			fi
    		fi
    	else
           	qvm-prefs "$CUR_VM" netvm None
    		notify-send "Disconnected $CUR_VM from network!" "The netvm of $CUR_VM was set to None (n/a)."
    	fi
    fi
    
  • Keep WiFi off by default on boot - [TemplateVM] In sys-net’s template, create /var/lib/NetworkManager/NetworkManager.state containing the code below (expandable) @Bearillo

    NetworkManager.state
    [main]
    WirelessEnabled=false
    
  • Soft toggle WiFi - [dom0] qvm-run sys-net -- "if nmcli radio wifi | head -c1 | egrep 'e'; then nmcli radio wifi off; else nmcli radio wifi on; fi" (can be mapped to shortcut) @Bearillo

 

Video playback

 

Etc.

  • View dom0 update history - [dom0] Enter dnf history to view update events; enter dnf history info [EVENT ID] to view event details. Also works for Fedora in general @adw

  • Disable notifications per VM - Fedora-XFCE only - [AppVM] Run xfce4-notifyd-config, then xfconf-query -c xfce4-notifyd -p /do-not-disturb --set true @solene

 

 


 

This is a thread where we collect quick tips and tricks that can improve the Qubes experience.

Feel free to add your tip to this wiki post (anyone can edit this)

 

Guidelines

  1. Your tip should contain as few words as possible
     
  2. If your tip can’t be condensed into a few lines, it doesn’t belong here
     
  3. If your tip is niche with regard to Qubes users, it doesn’t belong here*
     
  4. Follow the established style convention
     
  5. Give credit, even to yourself, and link to the original (if needed, also post your tip as reply so you have a link)

* “What’s niche?” is going to spawn a lot of debate and angst, but this constraint is necessary to prevent the post from getting bloated and mostly irrelevant

10 Likes

I’d add Disable notification per XFCE Qubes (do not disturb mode) because notifications can be really annoying at time, and knowing how to disable notifications per qube can be useful

2 Likes

19 posts were split to a new topic: Send files directly to external storage mounted in other qube

Command to soft switch WiFi on and off (bind to keyboard shortcut or put into a script):

qvm-run sys-net -- "if nmcli radio wifi | head -c1 | egrep 'e'; then nmcli radio wifi off; else nmcli radio wifi on; fi"

To keep WiFi off by default on boot, drop the file /var/lib/NetworkManager/NetworkManager.state with the following content in sys-net’s template:

[main]
NetworkingEnabled=true
WirelessEnabled=false
WWANEnabled=true
1 Like

@Bearillo @SteveC
I can see many people using these
Feel free to add them to the top post (it’s a wiki post, so anyone can update it)

1 Like

@Deeplow
I just remembered from my CPU survey that there’s a limit to how many user mentions a single post can contain. This post should reach that limit quickly, but I want to see if there’s a way to get around that limit before I start removing them (i.e. “Does mod fairy dust fix this?”)

1 Like

Thanks for updating the wiki
I reformatted your entries; please check for technical accuracy

1 Like

It does. One can now mention up to 100 people. Thanks for bringing it up!

3 Likes

Thanks for book-bossing this. I added just a bit more. If it’s too much feel free to cut.

And I’ve added one about how to protect against the rather obnoxious consequences of accidentally shutting down sys-usb.

1 Like

I added the Cursor / Manual hide the mouse cursor procedure.

Posting the original to serve as a thread-splitting header before I summarize it.

Is there a Discourse/Markdown/HTML guru here? I need a way to indent the details tab/expander so that it’s flush or deeper than a level 1 bullet, making it clear that it’s part of the preceeding entry.

Subheader

  • Level 1 bullet
Uncooperative details tab
Please help me tame this rebellious tab (with code block)
  • Level 1 bullet

The challenge is to keep a code block inside the tab while indenting it. This would hugely improve the flow of the document. I’m this close to issuing a bounty for this since it’s driving me mad.

Edit: Forgot to include the code block condition
Edit 2: The solution: use two spaces, not four–Two extra spaces is the difference between breezing through life and looking like a dunce

This?

2 Likes

Er, I meant can you do it with a code block inside?

Like this?

1 Like

Wow. Why does it fail so horribly when I try to do the exact same thing?
I’m saying this while looking at your reply’s source code since I have quasi-mod privileges and I’m just confused. Does Markdown have something against me?

Edit: The solution: use two spaces, not four–Two extra spaces is the difference between breezing through life and looking like a dunce

Anyways a big thank you!

1 Like

Moved posts for “Send files directly to external storage mounted in other qube” to its own thread

1 Like

May I suggest using */2 * * * * or even */5 * * * * to reduce the number of useless call by a factor 2 or 5?

I mean, this would save you when you accidentally stop sys-usb, I don’t think this is very common but very annoying when it happens. I think waiting 2 or 5 minutes instead of less than 60 seconds seems reasonable when it happens, so it wastes less CPU cycles trying every 60 seconds :smiley:

That’s not really wasting that much, but still, the frequency is very high here and I don’t know how complex qvm-start code is behind that, it must call a lot of python code which is extremely CPU inefficient.

1 Like

I don’t know the inner workings of qvm-start, but I think it’s safe to assume that the --skip-if-running parameter makes it check before doing anything, so the cost of running it every minute should be minimal.

It stills needs to run python3, evaluate all the required libraries and check the qube is started to abort.