Miscellaneous
A collection of system configurations, tweaks and quick fixes for Linux environments.
Laptop optimization
This ensures your laptop stays awake with the lid closed, maintains a stable network connection and boots quickly by ignoring unused network interfaces.
-
Lid and sleep configuration
These steps prevent the system from suspending or shutting down when the lid is closed or the power button is pressed.
-
Open logind config
Terminal window sudo nano /etc/systemd/logind.conf -
Update config
Update the following lines to
ignoreto keep the system awake./etc/systemd/logind.conf HandleSuspendKey=ignoreHandleLidSwitch=ignoreHandleLidSwitchExternalPower=ignoreHandleLidSwitchDocked=ignore -
Restart logind
Terminal window sudo systemctl restart systemd-logind
-
-
Disable system-wide sleep
To prevent the kernel from attempting to sleep even if triggered by software, create a “no-sleep” override.
-
Create nosuspend config
Terminal window sudo mkdir -p /etc/systemd/sleep.conf.d/ && sudo nano /etc/systemd/sleep.conf.d/nosuspend.conf -
Add config
/etc/systemd/sleep.conf.d/nosuspend.conf [Sleep]AllowSuspend=noAllowHibernation=noAllowSuspendThenHibernate=noAllowHybridSleep=no -
Reload daemon
Terminal window sudo systemctl daemon-reload
-
Configure ethernet and Wi-Fi
This process configures your server to use Netplan and systemd-resolved to manage both ethernet and Wi-Fi connections through a single, unified configuration file.
-
Install network driver (if applicable)
Terminal window lspci -nnk | grep -iA 3 netIf the network controller says “Broadcom” and “BCM43xx”, install the drivers below; otherwise, skip to step 2.
Terminal window sudo apt update && sudo apt install linux-headers-$(uname -r) -y && sudo apt install bcmwl-kernel-source -yFor changes to take effect, reboot the system.
Terminal window sudo rebootVerify the driver is active by running
ip link. A wireless interface, typicallywlan0, should now appear in the list. -
Install and enable wpa_supplicant
Terminal window sudo apt install wpasupplicant -y && sudo systemctl enable --now wpa_supplicant -
Create symlink to systemd-resolved
Terminal window sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf -
Network configuration
systemd-resolved
-
Open netplan config
Terminal window sudo nano /etc/systemd/resolved.conf.d/10-override-dns.conf -
Update config
/etc/systemd/resolved.conf.d/10-override-dns.conf [Resolve]DNS=1.1.1.1 8.8.8.8FallbackDNS=1.0.0.1 8.8.4.4Domains=~.DNSStubListener=no
netplan
-
Open netplan config
Terminal window sudo nano /etc/netplan/50-cloud-init.yaml -
Update config
- Replace
enp3s0with your ethernet ID fromip link. - Replace
wlan0with your Wi-Fi ID fromip link. - Replace
Your_SSID_NameandYour_Passwordunder access-points.
/etc/netplan/50-cloud-init.yaml network:version: 2renderer: networkdethernets:enp3s0:dhcp4: true# Remove if causing issues when rebootingoptional: truedhcp4-overrides:route-metric: 100use-dns: falsenameservers:addresses: [1.1.1.1, 8.8.8.8]# Optionalwifis:wlan0:dhcp4: trueoptional: truedhcp4-overrides:route-metric: 600use-dns: falsenameservers:addresses: [1.1.1.1, 8.8.8.8]access-points:"Your_SSID_Name":password: "Your_Password" - Replace
-
Apply the config
Terminal window sudo chown root:root /etc/netplan/50-cloud-init.yaml && sudo chmod 600 /etc/netplan/50-cloud-init.yaml -
Apply the config
Terminal window sudo netplan apply
-
-
Restart systemd-resolved
Terminal window sudo systemctl restart systemd-resolved -
Enable systemd-networkd-wait-online
Terminal window sudo systemctl enable systemd-networkd-wait-online.service -
Reboot the system
Terminal window sudo reboot
Expand storage to full capacity
This process extends the logical volume and resizes the filesystem to utilize all remaining unallocated space on your primary hard drive.
-
Extend the logical volume
Terminal window sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv -
Resize the filesystem
Terminal window sudo resize2fs /dev/ubuntu-vg/ubuntu-lv -
Verify
Terminal window df -h /
Wake-on-LAN (WOL)
If your computer supports Wake-on-LAN, you can send a “magic packet” to wake it from a powered-down state. This is primarily supported on Ethernet connections.
-
Identify network interface
Find the name of your Ethernet adapter. Look for names starting with
e(e.g.,eth0orenp3s0).Terminal window ip link show -
Install ethtool
Install the utility required to manage network hardware settings.
Terminal window sudo apt update && sudo apt install ethtool -y -
Check support
Verify if your hardware supports the magic packet. Look for
gin the “Supports Wake-on” line.Terminal window sudo ethtool $INTERFACE_NAME -
Enable WOL (temporary)
Enable WOL manually to test the configuration. This setting will reset after a reboot.
Terminal window sudo ethtool -s $INTERFACE_NAME wol g -
Persist with systemd
Create a service to ensure WOL is re-enabled automatically on every boot.
/etc/systemd/system/wol.service [Unit]Description=Enable Wake On Lan[Service]Type=oneshotExecStart=/usr/sbin/ethtool -s $INTERFACE_NAME wol g[Install]WantedBy=basic.target -
Enable the service
Reload systemd and enable the new service.
Terminal window sudo systemctl daemon-reload && sudo systemctl enable wol.service -
Send Wake-up packet
From another device on the network, trigger the boot sequence using the target’s MAC address.
Terminal window wakeonlan $MAC_ADDRESS