Category Archives: Tips and tricks

Wake on Lan with Linux

Wake on Lan is a great functionality to have if for some reason you have issues accessing the power button of your machine.
Generally, wake on lan works on Linux and Windows with modern machines that support it. Wake on lan also needs a wired connection in order to work.

Here is short guide on how to use wake on lan on Debian based distributions and with Lenovo Ideapad laptop.

Note: On many occasions you will need to also enable wake on lan support on Bios. My Asus desktop (Windows) machine required this. In case of my Lenovo Ideapad, there was no Bios entry at all. However, this Ideapad model still supported wake on lan.

  1. Install ethtool:

    sudo apt install ethtool

    1. Find your lan interface:

    ip a

    For me it was:
    2: enp3s0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    On the very same ip a command you will also locate a MAC address, similar to:

    link/ether 11:a1:11:1c:a1:11

    See if wake on lan is enabled: sudo ethtool enp3s0| grep Wake-on

    When it is enabled you will see something like:

    Supports Wake-on: pumbg
    Wake-on: g

    If you run this command for the very first time, you will more than likely miss the g on Wake-on. To enable wake on lan on the interface(the g letter), execute: ethtool -s enp3s0 wol g

    1. Enable lan interface to support wake on lan on system level during start.

    I did not want to do this every time manually. I created a file called wol.service with the following content:

    [Unit]
    Description=Wake-On-LAN
    #After=network.target
    
    [Service]
    Type=oneshot
    ExecStart=ethtool -s enp3s0 wol g
    RemainAfterExit=true
    #ExecStop=/opt/foo/teardown-foo.sh
    StandardOutput=journal
    
    [Install]
    WantedBy=multi-user.target
    

    Then I copied it to right place, enabled it during the system start, and started it on my current session:

    sudo cp wol.service /etc/systemd/system/wol.service
    sudo systemctl enable wol
    sudo systemctl start wol

    4. How to wake on Lan

    I noticed that only systemctl suspend was something that I was able to use and produce a working wake on lan situation. This will likely vary based on your setup.
    In comparison: On Windows hosts, the system needs to be shutdown cleanly and wake on lan will just work.

    On another Debian Linux box you can install: sudo apt install wakeonlan

    Then you can wake the machine with: wakeonlan 11:a1:11:1c:a1:11

    5. Waking with Android or Iphone:

    Wake on lan can also be produced with Android or Iphone. I used Wake On Lan by Mike Webb. You can use that app or something else. I will not directly recommend any applications. I suggest that if you want to use your phone as a wake on lan controller, that you will do some investigation of your own and find out what application is best for your device.

    Getting external screen to work on Lenovo Ideapad 1 laptop (Debian based systems)

    External screen might not work out of the box with Lenovo Ideapad 1 laptops.

    The following steps were performed on PostX Gnu/Linux (based on Debian 11) to remedy the situation.

    • Remove nomodest entry from grub config file:

    sudo nano /etc/default/grub
    sudo update-grub

    • Reboot the system.
    • Install arandr to identify & setup the (external) display:

    sudo apt install -y arandr

    • Save configuration to an sh file(screen.sh here) and make it autostart. Openbox as an example:

    nano .config/openbox/autostart

    bash screen.sh &
    exec openbox

    Fixing error on Debian 11: No module named py_compile

    The root cause of an error is: /usr/bin/python3.9: No module named py_compile.

    This will prevent python3 packages from installing as the dpkg errors out during configuration.

    A more complete error example, will look something like this:


    Setting up python3.9-minimal (3.9.2-1) …
    /usr/bin/python3.9: can’t open file ‘/usr/lib/python3.9/py_compile.py’: [Errno
    2] No such file or directory
    dpkg: error processing package python3.9-minimal (–configure):
    installed python3.9-minimal package post-installation script subprocess return
    ed error exit status 2
    Errors were encountered while processing:
    python3.9-minimal
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    /usr/bin/python3.9: No module named py_compile

    Regardless of the package name, missing the py_compile will give plenty of issues. Here comes an easy fix.

    Continue reading

    Adding backports to Debian stable

    Sometimes there might come a situation where Debian stable is just too old. This is usually related to hardware support of some component that the computer has that has no current support on a kernel that Debian stable ships with. Kernel is a typical example but others may exist as well. Backports might be of help when trying to get some more support to hardware. However, before proceeding it is good to notice that backports might cause issues down the line if used too carelessly.

    A typical case of an issue might be that when the next Debian stable eventually arrives upgrade might be tricky if you have some packages that are more recent than those Debian is offering. This used to be more of a big deal back in the day. Currently, I believe that backports generally do not provide any significant risk that could not be handled during upgrades. Caution is still adivised,

    To add backports to Debian stable you need to do the add the following entry (as sudo or root) to your /etc/apt/sources.list or equivalent file under /etc/apt/sources.list.d folder structure:

    deb http://deb.debian.org/debian bullseye-backports main contrib non-free

    After the above line is added do: sudo apt-get update

    Installing from backports is done by first locating the package you want to install. A good source for this is https://backports.debian.org/

    When the package of choice is found, then the installation command will be, for example:

    sudo apt install linux-image-amd64/bullseye-backports

    On the above command, linux-image-amd64 is a metapackage that will install a more later kernel from Debian backports. Finally, to start using the later kernel, I would need to reboot my computer.