Linux

How to create a LXC Ubuntu container in 15 seconds

Run this:

lxc launch ubuntu:22.04 mycontainer

In case you see this error message

Error: Failed container creation: No storage pool found. Please create a new storage pool

see How to fix lxd ‘Failed container creation: No storage pool found. Please create a new storage pool.’

Now you can connect to your container using

lxc exec mycontainer /bin/bash

 

Posted by Uli Köhler in Container, Linux, LXC

How to run docker container as current user & group

If you want to prevent your docker container creating files as root, use

--user $(id -u):$(id -g)

as an argument to docker run. Example:

docker run --user $(id -u):$(id -g) -it -v $(pwd):/app myimage

 

Posted by Uli Köhler in Container, Docker, Linux

How to get current user’s primary group GID on Linux

Run

id -g

to get the GID of the current user’s primary group. Example:

$ id -g
1000

You can also get the GID of another user’s primary group:

$ id -g root
0

 

Posted by Uli Köhler in Linux

How to get current user’s UID on Linux

Run

id -u

to get the current user’s UID. Example:

$ id -u
1000

You can also get another user’s UID:

$ id -u root
0

 

Posted by Uli Köhler in Linux

How to recompress gzipped .gz files to .xz files on Linux

Copy and paste this shell function into your bash or zsh:

function gzToXz { zcat "$1" | xz -c - -ev9 > "${1%.*}.xz" ; }

This will decompress the file using zcat and pipe it into xz with the highest compression setting (-ev9). If you prefer less compression but more speed, use e.g. -5 instead of -ev9.

Use like this:

gzToXz my.gz

which will recompress my.gz to my.xz.

In case you want to recompress every .gz file in the current directory, use:

for i in *.gz ; do echo "$i" ; gzToXz "$i" ; done

It might be best to make a backup of the data even though I have used this script many times for my own data.

Posted by Uli Köhler in Linux, Shell

How to fix Wireshark "Couldn’t run /usr/bin/dumpcap in child process: Permission denied" on Linux

If you see an error message like this in Wireshark:

this is because your current user doesn’t have permission to capture packets from your network card.

This can be the case even if you have selected to allow normal users to capture packets during the Wireshark installation process. This is because the setting only takes effect after logging out and logging back in (or rebooting).

To fix the issue temporarily without logging out, run Wireshark as root: sudo wireshark

In order to fix the issue permanently, ensure your user is added to the wireshark group:

sudo usermod -a -G wireshark $USER

and then log out and log back in again (or reboot your computer).

Posted by Uli Köhler in Linux

How to fix LaTeX error File `environ.sty’ not found on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! LaTeX Error: File `environ.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Solution

sudo apt -y install texlive-latex-extra

This will install, among many other LaTeX files, environ.sty.

Posted by Uli Köhler in LaTeX, Linux

How to fix LaTeX error Package babel Error: Unknown option `ngerman’ on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! Package babel Error: Unknown option `ngerman'. Either you misspelled it
(babel)                or the language definition file ngerman.ldf was not foun
d.

See the babel package documentation for explanation.
Type  H <return>  for immediate help

Solution

sudo apt -y install texlive-lang-german

This will install, among many other LaTeX files, the files for the ngerman language.

Posted by Uli Köhler in LaTeX, Linux

How to fix Ubuntu LaTeX ! I can’t find file `ecrm1200′.

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

kpathsea: Running mktexmf ecrm1200
! I can't find file `ecrm1200'.
<*> ...ljfour; mag:=1; nonstopmode; input ecrm1200
                                                  
Please type another input file name
! Emergency stop.
<*> ...ljfour; mag:=1; nonstopmode; input ecrm1200
                                                  
Transcript written on mfput.log.
grep: ecrm1200.log: No such file or directory
mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input ecrm1200' failed to make ecrm1200.tfm.
kpathsea: Appending font creation commands to missfont.log.

! Font T1/cmr/m/n/12=ecrm1200 at 12.0pt not loadable: Metric (TFM) file not fou
nd.
<to be read again> 
                   relax 
l.105 \fontencoding\encodingdefault\selectfont

Solution

sudo apt -y install texlive-fonts-recommended

This will install, among many other LaTeX files, ecrm1200.mf and ecrm1200.tfm.

.

Posted by Uli Köhler in LaTeX, Linux

How to fix LaTeX Error: File `scrartcl.cls’ not found on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! LaTeX Error: File `scrartcl.cls' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: cls)

Solution

sudo apt -y install texlive-latex-recommended

This will install, among many other LaTeX files, scrartcl.cls.

Posted by Uli Köhler in LaTeX, Linux

How to check if secure boot is enabled on Ubuntu?

On the command line, run

sudo mokutil --sb-state​

This will tell you

SecureBoot enabled​_

if secure boot is currently active on your machine or

SecureBoot disabled

else.

In case you see an error message like

bash: command not found: mkoutil

you need to install mokutil first using

sudo apt install mokutil​_
Posted by Uli Köhler in Linux

How to install NodeJS 14.x LTS on Ubuntu in 1 minute

Newer version 16 available: How to install NodeJS 16.x LTS on Ubuntu in 1 minute

Run these shell commands on your Ubuntu computer to install NodeJS 14.x:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Instead of setup_14.x you can also choose other versions like setup_12.x. However, using this method, you can’t install multiple versions of NodeJS in parallel.

Source: Official nodesource documentation

Posted by Uli Köhler in Linux, NodeJS

How to install ddrescue on Ubuntu

To install ddrescue, run

sudo apt -y install gddrescue

 

Posted by Uli Köhler in Linux

What does ‘lsusb’ do on Linux?

lsusb lists all the USB devices to your computer.

Example output:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2b Intel Corp. 
Bus 001 Device 002: ID 04f2:b5e8 Chicony Electronics Co., Ltd 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Each line represents a single USB device – but an USB device might also be internal to the computer and not connected to a physical USB port. For example, Bus 001 Device 003: ID 8087:0a2b Intel Corp. is an internal Bluetooth modem in my notebook.

Explanation:

  • Bus 001: The device is connected to the first USB bus (001) on the system
  • Device 003: In the aforementioned bus, the device has been assigned the ID 003.
  • ID 8087:0a2b: This is the ID assigned to that device. The first part (8087) is the Vendor ID (VID). The second part (0a2b) is the Product ID (PID). These IDs are assigned by the USB Implementer’s forum. This ID will always stay the same for any given device. If you buy a USB product multiple times, all of them will have the same ID.
  • Intel Corp.: This is the description of the device. Often Linux can show you more information, but in this case it’s just the name of the manufacturer.
Posted by Uli Köhler in Linux

What is a PPA on Linux?

A PPA (Personal Package Archive) is a repository where you can download packages, that is software, for Debian-based Linux distributions like Ubuntu.

In contrast to “normal” package source that are provided and maintained by distribution providers, PPAs can be created by anyone in order to publish one’s software or special versions of third-party software.

PPAs are hosted on Launchpad, a platform made and supported by Canonical, the company behind Ubuntu.

Are PPAs safe?

While in principle one could publish dangerous software on a PPA, in practice there is virtually no risk since:

  • Most often the PPA is provided by the original author of the software and can hence be trusted, if the software you want to install is trusted
  • PPAs are frequently used by amateurs and experts alike
  • You can only upload source DEB packages to the PPA which is built on Canonical’s server. This reduces the likelihood of smuggeling in binaries with malicious software.
  • Malicious PPAs are quickly removed once reported

Still it is good practice to keep in mind that installing software from anywhere – including PPAs – has a chance (although a very little one) to compromise your computer.

Posted by Uli Köhler in Linux

How to fix iotop ‘Netlink error: Operation not permitted (1)’

Problem:

You are trying to run iotop but you see an error message like

Netlink error: Operation not permitted (1)

The Linux kernel interfaces that iotop relies on now require root priviliges
or the NET_ADMIN capability. This change occured because a security issue
(CVE-2011-2494) was found that allows leakage of sensitive data across user
boundaries. If you require the ability to run iotop as a non-root user, please
configure sudo to allow you to run iotop as root.

Please do not file bugs on iotop about this.

Solution:

You need to run iotop as root:

sudo iotop

The reason for this is that iotop needs to access kernel interfaces that are only accessible to root users or if the user/process has the CAP_NET_ADMIN capability. In theory you could add this capability using sudo setcap cap_net_admin+ep /usr/sbin/iotop but on Ubuntu 18.04 this did not work for me.

 

Posted by Uli Köhler in Linux

How to use qemu with UEFI on Ubuntu

In order to use QEMU with UEFI on Ubuntu first install OVMF:

sudo apt -y install ovmf

After that, use the -bios /usr/share/ovmf/OVMF.fd with QEMU, for example:

sudo qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -hda /dev/sdb -m 1024
Posted by Uli Köhler in Linux

How to test your live USB without rebooting your computer on Linux

Problem:

You want to create a live USB stick e.g. gparted, Ubuntu etc and you quickly want to test it without rebooting your computer.

Solution:

You can use qemu, a system emulator, to do that.

First, install qemu. On Ubuntu:

sudo apt -y install qemu-system-x86

Now find out what the block  your USB stick is called (e.g. /dev/sdb). You can use lsblk to do this:

sudo lsblk

this will output, for example

[...]
sda      8:0    0 447,1G  0 disk 
├─sda1   8:1    0   549M  0 part 
├─sda2   8:2    0 121,2G  0 part 
├─sda3   8:3    0     1K  0 part 
└─sda5   8:5    0 325,4G  0 part /
sdb      8:16   1  29,3G  0 disk 
└─sdb1   8:17   1   268M  0 part

/dev/sda is usually your own hard drive (in my case, a 500 GB drive – 447.1G listed). In my case, I use a 32 GByte USB stick for the live USB, which is /dev/sdb (29.3 GB).

Note: You want to use the drive block device (e.g. /dev/sdb), not the partition block device (e.g. /dev/sdb1)

Now you can run qemu like this:

sudo qemu-system-x86_64 -hda /dev/sdb -m 1024

Remember to replace /dev/sdb by your USB stick block device (which we identified before using lsblk).

-m 1024 tells qemu to use 1024 Megabytes = 1 Gigabyte of RAM. You might need to increase this depending on what you are trying to boot.

Note that this approach will try to boot using BIOS and won’t try to boot UEFI-only drives like the ones created by tuxboot. In order to use UEFI with qemu you first need to install OVMF (which is a UEFI emulator that can be used for qemu):

sudo apt -y install ovmf

then run qemu like this:

sudo qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -hda /dev/sdb -m 1024

Remember to replace /dev/sdb by your USB stick block device (which we identified before using lsblk).

Since qemu is an emulator, it will be slower than booting your computer from the stick – but you can keep your computer running while you are testing your live USB stick.

Posted by Uli Köhler in Linux

How to install tuxboot on Ubuntu

According to the manual, you can install tuxboot using

sudo apt-add-repository -y ppa:thomas.tsai/ubuntu-tuxboot && sudo apt-get update && sudo apt-get install -y tuxboot

Now you can run tuxboot using

sudo tuxboot

 

Posted by Uli Köhler in Linux

How to fix raspivid ‘* failed to open vchiq instance’

Problem:

You want to capture a video using raspivid, e.g. using a command like

raspivid -o vid.h264

but you only see this error message:

* failed to open vchiq instance

with no video being captured.

Quick solution:

Run raspivid using sudo:

sudo raspivid -o vid.h264

Now either the video will be captured or you will see another error message if there is another issue with your camera setup.

Better solution:

Add your user to the video group so you don’t have to run raspivid as root:

sudo usermod -a -G video $USER

You only need to do this once. After that, log out and log back in (or close your SSH session and connect again). If in doubt, restart the Raspberry Pi. See What does &#8217;sudo usermod -a -G group $USER&#8216; do on Linux? for more details.

Now you will be able to capture video as normal user:

raspivid -o vid.h264

 

Posted by Uli Köhler in Embedded, Linux