Ubuntu: Difference between revisions

No edit summary
Adds section about using Netplan to set up WLAN access.
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
<br />
<br />
=== <br /> Introduction ===
== <br /> Introduction ==
Ubuntu (http://ubuntu.com) is probably the best supported [[Linux]] distribution in the computer industry. Ubuntu is based on [http://debian.org Debian] Linux. The package management tools are therefore [https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html ''dpkg'' and ''apt-get''].
[https://ubuntu.com Ubuntu] is a [[Linux]] distribution with excellent support and a broad user community. Many technical projects use this distribution as their target platform. Ubuntu is based on [http://debian.org Debian] Linux. The package management tools are therefore [https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html ''dpkg'' and ''apt-get''].
<br />
<br />
<br />
<br />


=== Upgrading To A New Release ===
== Determining the Version of Ubuntu Running ==
Use the '''lsb_release''' command to view version information about the running [https://en.wikipedia.org/wiki/Linux_Standard_Base LSB-compliant] Linux system.
<pre class="terminal">
sudo apt install lsb-release
lsb_release -a
</pre>
generates the example output
<pre class="terminal">
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
</pre>
<br />
 
== Upgrading To A New Release ==
First of all, check you current version by typing
First of all, check you current version by typing
<pre class="terminal">
<pre class="terminal">
Line 20: Line 36:
</pre>
</pre>
<br />
<br />
=== Working With Repositories ===
== Working With Repositories ==
==== Repository Sources ====
=== Repository Sources ===
Third-party repositories can be added to the list of source repositories with the command
Third-party repositories can be added to the list of source repositories with the command
<pre class="terminal">
<pre class="terminal">
Line 42: Line 58:
<br/>
<br/>
<br/>
<br/>
=== SSH Logins Without Typing The Password ===
 
If you connect to a remote computer via ''ssh'' or copy files via ''scp'' frequently, you should consider using ''ssh-agent'', which saves you from typing your login password each time.
== Setting up WLAN with Netplan ==
[https://netplan.io Netplan] is a network configuration system created by Canonical. YAML files are used to describe the desired network configurations. Netplan command-line tools are used to apply a given network configuration.
<br />
<br />
<br />
<br />
First, you create an RSA public/private key pair that identifies your local machine. You may already have created such a key in your SSH keychain. It is good security practice, however, to use a separate key for each device you want to connect to. Let us assume you want to connect to a [[Raspberry Pi]]. The command to create a new SSH key would be
To set up WLAN access using Netplan In the '''/etc/netplan''' folder, find the network configuration definition file (most likely '''50-cloud-init.yaml'''). Open the file in an editor. You should find an existing ethernet configuration:
<pre class="code">
network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
</pre>
where ''eth0'' is an example ethernet interface. To add a WiFi configuration, add the lines
<pre class="code">
    wifis:
        <wlan>:
            optional: true
            access-points:
                "<ssid>":
                    password: "<password>"
            dhcp4: true
</pre>
where ''<wlan>'' is usually ''wlan0'', and ''<ssid>'' and ''<password>'' need to be replaced with the actual WiFi SSID and password.
<br/>
<br/>
As this is a YAML file, make sure that indentation levels are correct and only whitespace (no tab characters) is used.
<br/>
<br/>
Now activate the new configuration via
<pre class="terminal">
sudo netplan generate
sudo netplan apply
</pre>
and check with
<pre class="terminal">
<pre class="terminal">
ssh-keygen -t rsa -b 2048 -C "for Raspberry Pi"
ip a
</pre>
</pre>
where '-b 2048' specifies the key length in bits. You will be prompted to enter the path and name of the file in which the key will be saved. Choose a name that makes it clear that it was created for connecting to the Raspberry Pi. Next, you will be prompted for a password. Just press the Enter key for no password.
<br/>
<br />
<br/>
<br />
<br/>
Now that the SSH key is created, you need to copy the generated key ('''public''') into the folder ''/home/pi/.ssh/'' on the Raspberry Pi:
 
== NFS (Network File System) ==
=== Setting up an NFS Server ===
<pre class="terminal">
sudo apt install nfs-kernel-server
</pre>
then edit '''/etc/exports''' to add lines in the following format:
<pre class="code">
<directory>    <hostname>(<options>) [<hostname>(<options>)]*
</pre>
where ''<directory>'' is the directory that you want to make available over NFS, followed by one or more pairs of client host names and access options. ''<hostname>'' can be an IP address, a domain name with wildcards, or a subnet.  of the allowed client machine, ''<options>'' is a list of options that determine whether the directory is, e.g., writable. The file format is better explained in this [https://www.thegeekdiary.com/understanding-the-etc-exports-file/ article]. Examples are
<pre class="code">
/home/james/photos    192.168.178.62(r,async) 192.168.178.55(r, async)
/mnt/storage2        192.168.178.0/24(rw,sync,no_subtree_check)
</pre>
After editing ''/etc/exports'', apply the NFS configuration via '''/usr/sbin/exportfs''':
<pre class="terminal">
<pre class="terminal">
scp ~/.ssh/for-raspberry-pi_rsa.pub pi@192.168.1.10:/home/pi/.ssh/authorized_keys
sudo exportfs -ar
</pre>
</pre>
The copied file is renamed to '''authorized_keys''', which is the expected file name for the SSH server to look up the public keys of trusted clients.
<br />
<br />
<br />
Query the allowed NFS protocol versions for the clients via
Now use ''ssh-agent'' on your local machine to start a special shell session that uses the new SSH key to automatically authenticate any SSH connection from your machine to the Raspberry Pi:
<pre class="terminal">
<pre class="terminal">
eval "$(ssh-agent -s)" # starting a new shell session
sudo cat /proc/fs/nfsd/versions
ssh-add ~/.ssh/for-raspberry-pi_rsa
</pre>
</pre>
Done! This was the last time you had to enter the password for user ''pi''.
<br />
<br />
<br />
 
By the way, you can list all the keys that were added to the SSH agent by entering
=== Mounting an NFS Drive ===
<pre class="terminal">
<pre class="terminal">
ssh-add -l
sudo apt install nfs-common
</pre>
</pre>
and mount the NFS with the usual ''/usr/bin/mount'' command using the '''-t nfs''' option like in this example:
<pre class="terminal">
sudo mount -t nfs -o vers=4 192.168.178.8:/storage /backups
</pre>
where ''vers=4'' indicates the NFS protocol version, ''192.168.178.8'' is the address of the NFS server, ''/storage'' is the path of the served directory on the NFS server (in NFS version 4 the path is relative to the served NFS root directory), and ''/backups'' is the mount point on the client machine
<br />
<br />
<br />
<br />


=== Installing NVIDIA Drivers ===
== Installing NVIDIA Drivers ==
Follow the [https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia instructions from Ubuntu] to install device drivers for NVIDIA graphics cards and configure for your system. There are also instructions for [https://help.ubuntu.com/community/NvidiaManual manually installing a driver] downloaded from NVIDIA, which is not recommended.
Follow the [https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia instructions from Ubuntu] to install device drivers for NVIDIA graphics cards and configure for your system. There are also instructions for [https://help.ubuntu.com/community/NvidiaManual manually installing a driver] downloaded from NVIDIA, which is not recommended.
<br />
<br />
Line 141: Line 204:
for showing a list of possible display modes in which the connected screen can operate.
for showing a list of possible display modes in which the connected screen can operate.
<br />
<br />
<br />
==== Workaround for libEGL.so.1 bug ====
There is a bug in the installation script for the recent Ubuntu NVIDIA drivers. The two files ''/usr/lib32/nvidia-375/libEGL.so.1'' and ''/usr/lib/nvidia-375/libEGL.so.1'' (assuming you are installing the NVIDIA drivers with major revision number 375) should not be real files but symbolic links to the actual library file ''libEGL.so.375.xx'', where ''xx'' stands for the minor version number of the driver. This bug can prevent your Ubuntu from initializing the graphics system during booting, which makes the bug a critical error. The workaround is to manually create the symboling links:
<pre class="terminal">
cd /usr/lib32/nvidia-375/
sudo mv libEGL.so.1 libEGL.so.1.orig
sudo ln -s libEGL.so.375.66 libEGL.so.1
cd /usr/lib/nvidia-375/
sudo mv libEGL.so.1 libEGL.so.1.orig
sudo ln -s libEGL.so.375.66 libEGL.so.1
sudo ldconfig
</pre>
See this [https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-375/+bug/1662860 forum discussion] for more information.
<br />
<br />

Latest revision as of 2022-12-09T13:23:05



Introduction

Ubuntu is a Linux distribution with excellent support and a broad user community. Many technical projects use this distribution as their target platform. Ubuntu is based on Debian Linux. The package management tools are therefore dpkg and apt-get.

Determining the Version of Ubuntu Running

Use the lsb_release command to view version information about the running LSB-compliant Linux system.

sudo apt install lsb-release
lsb_release -a

generates the example output

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.1 LTS
Release:	22.04
Codename:	jammy


Upgrading To A New Release

First of all, check you current version by typing

lsb_release -a

To upgrade to a new major release (for example, 16.04 to 16.10) type the command

do-release-upgrade

If there is no major release available but a point release has been issued, you can upgrade by typing

sudo apt-get update
sudo apt-get dist-upgrade


Working With Repositories

Repository Sources

Third-party repositories can be added to the list of source repositories with the command

sudo apt-add-repository <repository URL>


Source repositories that are provided by Ubuntu can be found in the file /etc/apt/sources.list. Third-party repositories that have been added afterwards can be found in the directory /etc/apt/sources.list.d/.

Querying Installed Packages

To find out which package a given file belongs to:

apt contains <file path>


To find out which files are included in a package use the Debian utility dpgk:

dpkg -L <package name>



Setting up WLAN with Netplan

Netplan is a network configuration system created by Canonical. YAML files are used to describe the desired network configurations. Netplan command-line tools are used to apply a given network configuration.

To set up WLAN access using Netplan In the /etc/netplan folder, find the network configuration definition file (most likely 50-cloud-init.yaml). Open the file in an editor. You should find an existing ethernet configuration:

network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2

where eth0 is an example ethernet interface. To add a WiFi configuration, add the lines

    wifis:
        <wlan>:
            optional: true
            access-points:
                "<ssid>":
                    password: "<password>"
            dhcp4: true

where <wlan> is usually wlan0, and <ssid> and <password> need to be replaced with the actual WiFi SSID and password.

As this is a YAML file, make sure that indentation levels are correct and only whitespace (no tab characters) is used.

Now activate the new configuration via

sudo netplan generate
sudo netplan apply

and check with

ip a




NFS (Network File System)

Setting up an NFS Server

sudo apt install nfs-kernel-server

then edit /etc/exports to add lines in the following format:

<directory>    <hostname>(<options>) [<hostname>(<options>)]*

where <directory> is the directory that you want to make available over NFS, followed by one or more pairs of client host names and access options. <hostname> can be an IP address, a domain name with wildcards, or a subnet. of the allowed client machine, <options> is a list of options that determine whether the directory is, e.g., writable. The file format is better explained in this article. Examples are

/home/james/photos    192.168.178.62(r,async) 192.168.178.55(r, async)
/mnt/storage2         192.168.178.0/24(rw,sync,no_subtree_check)

After editing /etc/exports, apply the NFS configuration via /usr/sbin/exportfs:

sudo exportfs -ar


Query the allowed NFS protocol versions for the clients via

sudo cat /proc/fs/nfsd/versions


Mounting an NFS Drive

sudo apt install nfs-common

and mount the NFS with the usual /usr/bin/mount command using the -t nfs option like in this example:

 
sudo mount -t nfs -o vers=4 192.168.178.8:/storage /backups

where vers=4 indicates the NFS protocol version, 192.168.178.8 is the address of the NFS server, /storage is the path of the served directory on the NFS server (in NFS version 4 the path is relative to the served NFS root directory), and /backups is the mount point on the client machine

Installing NVIDIA Drivers

Follow the instructions from Ubuntu to install device drivers for NVIDIA graphics cards and configure for your system. There are also instructions for manually installing a driver downloaded from NVIDIA, which is not recommended.

Alternative packages with newer drivers are available via Launchpad after adding the graphics-drivers repository by typing

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update


If your monitor cable (HDMI, DisplayPort, etc.) is connected to the output of the integrated graphics solution of your computer (e.g., Intel Skylake Graphics) you should shut down your computer and your monitor, unplug the monitor cable from the integrated graphics port and plug it into one of the ports of the NVIDIA card. Restart your computer, boot into the BIOS utility provided by your motherboard and check that Secure Boot is disabled, otherwise it will prevent kernel modules from being loaded.

Make sure nvidia-prime is installed and use it to select the NVIDIA card as the prime graphics output:

sudo apt install nvidia-prime
sudo prime-select nvidia

This modifies /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf and /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf to use the latest installed nvidia driver. To check the status of the graphics card and the driver assigned to it you can enter

inxi -G

The output should look like this:

Graphics:  Card: NVIDIA Device 1b81
           Display Server: X.Org 1.18.4 drivers: nvidia (unloaded: fbdev,vesa,nouveau)
           Resolution: 3840x2160@60.00hz
           GLX Renderer: GeForce GTX 1070/PCIe/SSE2 GLX Version: 4.5.0 NVIDIA 370.28

Note that nvidia is the selected driver in the line that starts with Display Server:.

You may have to add the string nomodeset to the line that starts with GRUB_CMDLINE_LINUX_DEFAULT= in the file /etc/default/grub. For example,

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"

where quiet and splash were the default options on my system. Be sure to run

sudo update-grub

so that the change to /etc/default/grub has an effect on /boot/grub/grub.cfg. Beware, however, that adding nomodeset will also prevent your display mode from being detected and set automatically if anything should go wrong. Finally, if your boot disk contains multiple bootable Linux system partitions, make sure that the bootloader that you just updated is the one installed in the Master Boot Record (MBR). You can install a Grub bootloader in the MBR via

$ sudo grub-install --boot-directory=/boot /dev/sda
$ sudo update-grub 

where /dev/sda is an example and needs to be replaced with your specific boot disk device file.

Other useful commands to check the device status are:

ubuntu-drivers devices

for showing a list of packages from the Ubuntu repository that are drivers for the installed hardware,

sudo lshw -c display

for showing information about installed hardware in the display category,

lspci -nnk | grep -iA3 vga

for showing information about graphics cards connected to the PCI bus, and

xrandr

for showing a list of possible display modes in which the connected screen can operate.