Archive for the ‘Linux’ Category

Enable Hibernate in Ubuntu 18.04

September 12th, 2019 14 comments


All credits goes to !

make it work with Ubuntu 18.04.

Make your /swapfile have at least the size of your RAM (make it double the size of your RAM if you have problems using the same size as your RAM).

sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrunc
sudo mkswap /swapfile
sudo swapon /swapfile

Note the UUID of the partition containing your /swapfile:

$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0

Reconfigure the package uswsusp in order to correctly use the swapfile:

sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"

Edit the SystemD hibernate service using sudo systemctl edit systemd-hibernate.service and fill it with the following content:

ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep

Note the resume offset of your /swapfile:

$ sudo swap-offset /swapfile
resume offset = 34818

Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:

GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"

Update Grub:

sudo update-grub

Update initramfs: sudo update-initramfs -u -k all

Create the following /etc/initramfs-tools/conf.d/resume:

RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfile

Update initramfs:

sudo update-initramfs -u -k all

Now you can hibernate with sudo systemctl hibernate.

One can also create those scripts:

    sudo tee /usr/local/bin/gotosleep <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo /usr/sbin/s2both
    sudo chmod +x /usr/local/bin/gotosleep
    sudo tee /usr/local/bin/gotohibernation <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo systemctl hibernate
    sudo chmod +x /usr/local/bin/gotohibernation

So you can sleep with gotosleep or hibernate with gotohibernation.

You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.

You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):

     %powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate

Documentation used:

Add ‘Hibernate’ Option in Power Menu in Ubuntu 18.04


sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following content and save it.

[Re-enable hibernate by default in upower]

[Re-enable hibernate by default in logind]

Install the Gnome connector:

sudo apt-get install chrome-gnome-shell

Open Firefox, press CTRL+SHIFT+a, and install the “GNOME Shell integration” Add-On. Link to the add-on:

Go to and search for “Hibernate Status Button“, or click this link: Turn “ON” the extension in the upper right corner.

Restart your computer and enjoy the new hibernate-button in the shut-down dialog!

For those who never installed a gnome extension, see this how to tutorial for details.

Categories: Bash, Linux, Ubuntu Tags:

How to Change Lid Close Action in Ubuntu 18.04 LTS

September 5th, 2019 No comments

Open terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to:

  • HandleLidSwitch=poweroff, shutdown / power off when lid is closed.
  • HandleLidSwitch=hibernate, hibernate when lid is closed (need to test if hibernate works).
  • HandleLidSwitch=ignore, do nothing.
  • HandleLidSwitch=suspend, suspend laptop when lid is closed.

Save the file and finally restart the Systemd service to apply changes via command:

systemctl restart systemd-logind.service
Categories: Bash, Linux, Ubuntu Tags:

Reboot linux at specific time

August 13th, 2019 No comments

Sometimes you want to reboot a server in the middle of the night. With linux it’s as simple as this command:

shutdown -r 04:00

Which will reboot the machine at 4 am in the morning. If you need to abort the reboot, use the following to abort the reboot:

shutdown -c
Categories: Bash, Linux, Red Hat / CentOS, Ubuntu Tags:

Mount exFAT in Ubuntu 18.04

August 8th, 2019 No comments

The exFAT file system is created by Microsoft to overcome the 4GB file size limit in FAT. To mount such an partition you need to enable exFAT. Otherwise you’ll get an error saying can’t mount unknown filesystem type “exfat”. In Ubuntu 18.04 it’s simple, just open a terminal and type:

sudo apt install exfat-fuse exfat-utils

If this doesn’t work you might need to add the “universe” repository first. Here’s an example followed by a mount of the device at /dev/sdb1. Replace this device with your own device:

sudo add-apt-repository universe
sudo apt update
sudo apt install exfat-fuse exfat-utils
sudo mkdir /mnt/myEXFAT
sudo mount /dev/sdb1 /mnt/myEXFAT

To list devices and their partitions, use the command:

sudo parted -l

Beware that exFAT can’t handle certain characters in the file names, like “:”. If you need to rename multiple file names you can modify the below example that replaces all “:”-characters with an underscore “_” in the current directory:

find . -depth -maxdepth 1 -name '*:*' -execdir bash -c 'mv -- "$1" "${1//:/_}"' bash {} \;

Categories: Bash, Linux, Ubuntu Tags:

Upgrade Ubuntu Linux using command line

August 6th, 2019 No comments

To upgrade Ubuntu Linux open up a terminal and type:


The old way using apt isn’t needed in Ubuntu to upgrade the system. dist-upgrade has been superseded in Ubuntu by full-upgrade.

The do-release-upgrade command can be run as an user with admin rights without sudo. The user password will be asked when starting the command. The system will then make different checks before the upgrade starts. If using SSH an additional port will be opened on port 1022 that can be used if the ordinary SSH-tunnel are broken during the update.

Categories: Bash, Linux, Ubuntu Tags:

Linux dist “Chapeau”

July 12th, 2019 No comments

Chapeau is a high-performance, cutting-edge operating system built from the GNU/Linux distribution Fedora Workstation with the GNOME desktop environment. In comparison to Fedora, Chapeau adopts a more relaxed approach to software licences and is intended to be just as useful for advanced users as it is easy for those new to using a Linux system. There is built-in access to third-party software and sources repositories not included in Fedora such as RPMFusion, DropBox, Steam, Adobe Flash and Oracle VirtualBox. Chapeau also includes pre-installed core packages to make the installation of new kernel modules pain-free, built-in remote and virtual system management tools, a selection of maintenance tools that come in especially handy when running Chapeau’s live image on a DVD or USB drive to analyse and fix broken systems.

Home Page
User Forums
Categories: Linux, Okategoriserade Tags:

Formattera en USB-pinne i Ubuntu

August 11th, 2012 No comments

Kolla först vilken enhetsnamn pinnen har. Starta ett terminalfönster och skriv:

sudo fdisk -l



Sedan när du kollat namnet måste du avmontera pinnen. I mitt fall hette enheten för USB-pinnen /dev/sdb

umount /dev/sdb

Formattera nu pinnen. Jag väljer att formattera den med VFAT så den går att använda i Windows m.fl. operativsystem.

sudo mkfs.vfat /dev/sdb1

Om du vill döpa om namnet på pinnen i kommandoradsläge kan du installera mtools

sudo apt-get install mtools

Sedan kan det vara bra idé att hoppa över mtoolskontrollen av pinnen då man ibland får ett felmeddelande not a multiple of sectors per track (62)

echo mtools_skip_check=1 >> ~/.mtoolsrc

Döp sedan om USB-pinnen med följande kommando

sudo mlabel -i /dev/sdb1 ::namn



Categories: Bash, Linux Tags:

Installera VM-ware Tools i Ubuntu Server

August 11th, 2012 No comments

Installing VMware Tools in Ubuntu Server 9.10

1. Install software needed by VMware Tools

Install packages to build the kernel modules

sudo apt-get install autoconf automake binutils make cpp gcc linux-headers-$(uname -r)

2. Find out where the kernel headers are (you may need this later)

ls -d /usr/src/linux-headers-$(uname -r)*/include

i.e. /usr/src/linux-headers-2.6.31-14-generic-pae/include

i.e. /lib/modules/2.6.31-14-generic-pae/build/include

3. Get the kernel source

sudo apt-get build-dep linux-image-$(uname -r)

sudo apt-get source linux-image-$(uname -r)

2. Prepare and install VMware Tools

1. From VMware Workstation: go to VM> Install VMware Tools

2. From the VM: mount the virtual cd drive

sudo mount /dev/cdrom /mnt/

3. Extract VMware Tools to /tmp/

tar -C /tmp -zxvf /mnt/VMwareTools-5.5.3-34685.tar.gz

4. Unmount the virtual cd drive

sudo umount /mnt/

5. Now run the installer

cd /tmp/vmware-tools-distrib

sudo ./

6. When asked Do you want to run, answer “Yes”.

3. Run VMware Tools from X

1. Run /usr/bin/vmware-toolbox



Categories: Linux Tags:

Prepare Linux for source compile

August 11th, 2012 No comments

1. Install packages to build the kernel modules

sudo apt-get install autoconf automake binutils make cpp gcc linux-headers-$(uname -r)

2. Find out where the kernel headers are (you may need this later)

ls -d /usr/src/linux-headers-$(uname -r)*/include

i.e. /usr/src/linux-headers-2.6.31-14-generic-pae/include

i.e. /lib/modules/2.6.31-14-generic-pae/build/include

3. Get the kernel source

sudo apt-get build-dep linux-image-$(uname -r)

sudo apt-get source linux-image-$(uname -r)

Categories: Bash, Linux, Programmering, Ubuntu Tags:

Bra Linuxkommandon

August 11th, 2012 No comments

top -s (Visar vilka processer som tar mest processorkraft)

ps (Visar aktuella processer)

ps -A|more (Visar alla processer)

ps -eaf | grep -i smb (visar vilken användare/rättighet en process (smb) körs med)

find / -name foo (Sök efter en fil i alla mappar)

hostname (visar hostname / ändrar temporärt hostname)

/etc/hostname (textfil med hostname i Debian, ändra för att ändra host perm.)

sudo /etc/init.d/ (kör detta skript för att ladda in hostnamn, Debian)

setxkbmap se (Byter till svenskt tangentbord i Ubuntu)

tail -f file.log (Visar en textfil kontinuerligt. Avbryt med CTRL+C)

iostat -x 5 (visar hårddisk prestanda var 5e sekund) kräver paket “sysstat”

lsusb – listar USB enheter

lshal – info om hårdvara

lsattr – lista filattribut i ext2 filsystem

lshw – lista HW info, kör som root

lshw -html > datorinfo.htm – skapar HTML sida med HW info

lsmod – listar vilka kärnmoduler som laddats

lsof – listar öppna filer

lspcmcia – listar PC-Card


Förnya DHCP-adress: sudo dhclient

alt.2: sudo /etc/init.d/networking restart

alt.3: ifdown eth0 && ifup eth0


Byt till statisk IP på Ubuntu server:


Edit file: sudo nano /etc/network/interfaces

Change to your info:

auto eth0

iface eth0 inet static






Add in the DNS: sudo nano /etc/resolv.conf

Remove the dhcp client: sudo apt-get remove dhcp3-client (or dhcp-client)

Restart net: sudo /etc/init.d/networking restart


Omkonfig Ubuntu Desktop: sudo dpkg –configure -a

Konfig X grafik: sudo dpkg-reconfigure xserver-xorg

Kolla Direct Rendering: glxinfo | grep rendering

Starta run-level 1 Recovery mode: sudo init 1

Avsluta Recovery mode: init 2

Uppdatera program och Ubuntu:

apt-get update (synkroniserar lista över program)

apt-get upgrade (uppdaterar alla installerade program till senaste versionen

apt-get dist-upgrade (uppdaterar till senaste, stabila versionen av Ubuntu)

Ändra grafikinställningar i Ubuntu:

Categories: Linux Tags: