# Ubuntu hints

### General hints

This page is a collection of hints from myself to myself, gathered during installation of several instances of Ubuntu and Debian. Some hints are particular to my configuration, some are of a more general nature.

### Installation on new hardware

Just insert the CD/DVD and take it from there. Installation is entirely straightforward.

### Installation of RAID1

This may or may not work in the regular installer. I used the server installer and chose manual partitioning. For instructions see this post. Note that the use type of the physical partitions must be set to raid. Also, don’t forget to define the use type and the mount points for the RAID partitions.

If something goes wrong, the Gparted live CD comes handy for erasing all hard drives. This is done by writing a new partition table onto the device.

Of some reason one of my disks was disconnected from the RAID almost immediately. I did:

cat /proc/mdstat

and got [U_] meaning that one disk wasn’t working. To get more details I did:

sudo mdadm --detail /dev/md[0,1]

and saw that the sdb disk was “removed” (the one that is not in state active sync). I then did:

sudo mdadm /dev/md0 -a /dev/sdb1
sudo mdadm /dev/md1 -a /dev/sdb2

to add the disks again. Doing:

cat /proc/mdstat

I now see that recovery is taking place.

For instructions on how to replace a faulty drive, see this tutorial. Note that if you are using sudo, then the command for copying the partition from the existing healthy disk to the new disk should read:

sudo sfdisk -d /dev/sda | sudo sfdisk /dev/sdb

i.e. a sudo is needed also after the pipe.

On my hardware it has happened a couple of times that a disk is totally disconnected. This can be seen for instance using the Disk Utility application. Restarting the computer usually reconnects the disk and then it can be again added to the raid as described above. I guess it’s time to consider an upgrade of the machine. It’s from 2008.

### Installation alongside Windows 10

I installed Ubuntu 14.04 alongside W10. I, like many others, didn’t get the installer  to automatically detect that there was already a Windows OS installed so I did it the hard way:

First, get some free space on the disk with Windows on it or install a new disk. To shrink the Windows partition, right-click on the  Windows Start button and choose Disk Management. Right-click on a partition that has extra space and select Shrink Volume.

Next use GParted to create partitions on the free space according to this guide. It refers then to another guide that shows how Ubuntu is installed on the  created partitions. Note that the swap partition is automatically detected (and formatted) and doesn’t need to be identified explicitly.

After the installation run

sudo update-grub

### Mounting volumes on other computers

See these instructions. I use the “cifs, user perms” option. Don’t forget to create the mount points (directories) under e.g. /mnt. I’m mostly using sshfs instead now. See below.

### Backup

Use either regular Compress or Grsync. In Grsync check to box Do not leave filesystem. I you don’t it will traverse a .gvfs directory that may point at other computers. Not sure if it actually copies anything but it’s very time consuming. It is also good to clear the trash when backing up the home folder.

### Home network DNS

If there are many computers on your network and perhaps a web server or two too, then a LAN DNS comes handy. It looks up the local IP address of a named computer. An alternative would be to edit the hosts files on all computers.

To install the bind9 DNS, follow these excellent instructions.

### File sharing

To add Samba shares, install packages samba and smbfs. Then edit the file /etc/samba/smb.conf. Change Workgroup to HOME and add shares. Add each share according to:

[Share] path = /home/Share read only = No browseable = yes

sudo smbpasswd -a <username>

service samba restart (Debian) or service smbd restart (Ubuntu). If permissions have been changed, then clients need to log out and log in again before they can use the new priviledges on the samba server.

An alternative is to use the GUI to share a folder. This doesn’t work until you’ve restarted the system though after your first try (when Samba is automatically installed).

To auto-mount Samba volumes at boot time, follow these instructions. Don’t forget to create the directory, e.g. /mnt/Server/Folder, manually (“mount point”). This method also handles Swedish characters in filenames.

Bookmarks to Samba shares don’t always work unless you do the following:

$gconftool-2 --set --type=string /desktop/gnome/url-handlers/smb/command 'nautilus "%s"'$ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/smb/enabled true $gconftool-2 --set --type=bool /desktop/gnome/url-handlers/smb/need-terminal false To avoid getting the desktop cluttered with shortcuts to all mounted volumes, uncheck the volumes_visible flag under nautilus -> desktop in Configuration Editor. (Configuration Editor is probably installed by default but not shown in the Application menus by default so it needs to be made available first or started from the command line.) Sometimes I need to disable and then enable networking to make my server visible on the network again. Instead of Samba, i mostly use sshfs these days. See below. ### Rygel Media Server To share media over the network to e.g. an Android TV, I’m using the Rygel media server. It can be installed from the Ubuntu repository. To run it as a service that starts automatically when the computer is booted, create a user “rygel” that owns the service. Then switch to that user, create ~/.config and copy /etc/rygel.conf there. Modify it as needed. Instead of using Tracker to export media, I’m using MediaExport so I’ve disabled Tracker and enabled MediaExport. I don’t export the default directories so I have modified according to the following:  uris=/home/Music;/home/Videos;/home/Pictures;  I also added the mts extension to the include-filter directive. Then copy upstart/rygel.conf from the Rygel repository to /etc/init and call “sudo start rygel” to start the service. It should get started at every boot from now on. Note that it may take several hours at a high CPU load for the MediaExport to index all the data. During this time expect glitches in the media streaming. On the TV I’m using the Kodi player which has a nice interface. It should detect the Rygel server on the network so that it can be added as a media source. It does crash on my TV when I try to add the Rygel server as a Picture source, probably due to the massive number of photos. So I add the Picture source through Samba instead. ### Adding a hard disk A hard drive added to the system will be possible to browse through the user interface but it will be a second class citizen until it has been tied to the regular file system (e.g. symbolic links will not work). To do so, create a folder, e.g. /mnt/backup. Find the unique id (uuid) of your hard drive by doing: blkid. This command requires root privileges. Connect the uuid to the newly created folder with an entry in the /etc/fstab file like this: UUID=c1133b53-44c9-477b-8b28-528bc864bb28 /mnt/backup ext3 errors=remount-ro 0 2 This also works for mounting the Windows disk in Linux if you are running them in a dual boot configuration. In this case the file system type is ntfs. For more on this, see the fstab documentation. ### LAMP server Install LAMP according to the ApacheMySQLPHP documentation on the Ubuntu site. If one fails to install the libapache2-mod-php5 module for apache then the browswer till throw a “PHTML” file at you and ask you what to do with it. The libapache2-mod-php5 should be enabled automatically when installed. Otherwise it can be enabled with sudo a2enmod php5. Use MySQLAdmin (or nowadays, alas, MySQL Workbench) to either restore the site from a backup or to create new tables for the applications that will be used, e.g. the tables “blog” and “gallery2”. Create users, in my case the user blog, for each table. Note that you need a @localhost subsection to the user. To get rid of the error message about “fully qualified domain name” when restarting apache2, add a file /etc/apache2/conf.d/fqdn with the line ServerName$HOSTNAME in it.

To stop apache2 from starting automatically, do sudo update-rc.d -f apache2 remove.

### WordPress

Download the latest WordPress package from WordPress download. If you’re starting from a backup, copy the wp-content directory from the backup instead of from the WordPress installation archive.

When migrating from another database, export only the relevant blog tables, not the built in tables. Otherwise the import will fail in MySQL Workbench. (It seemed to work in MySQL Admin though.)

Use the installation guide on the WordPress site. If restoring from a backup, then the site of course already exists and all that is needed is to configure WordPress in the wp-config.php file.

Add Google Analytics tracking code to the footer.php file of your theme if you wish to have access stats.

A neat plug-in for a compact sidebar is the WP-dTree by Ulf Benjaminsson. It is installed just like any other plug-in by copying it into the plug-in directory and activating it from the site admin pages. Customize under the Design tab. Don’t forget to check the Folders are links check boxes. Otherwise it will only show leaf pages in page hierarchies.

I needed to add a file searchform.php to my theme to avoid XHTML errors. It removes the offending attribute role. The contents of this file are as follows:

<form action="http://www.ostrogothia.com/process/" id="searchform" method="get"> <div><label for="s" class="screen-reader-text">Search for:</label> <input type="text" id="s" name="s" value=""/> <input type="submit" value="Search" id="searchsubmit"/> </div> </form>

For the automatic updates to work, ssh-access is recommended. See below for how to install an ssh server. To enable ssh access to WP, first do:

sudo apt-get install php-pear

You will also have to install libssh2-1-dev. It can be found in the Ubuntu Software Center.

Then follow these instructions. In Ubuntu the simple pecl install ssh2 will probably not work. Instead you have to use:

sudo pecl install channel://pecl.php.net/ssh2-0.12

This should start a build process and result in a successful build. (The version of the ssh library may have been bumped.)

### Remote desktop access

Use Internet -> Desktop Sharing to grant access to a machine’s desktop.

Use vinagre with the VNC protocol to access the remote desktop. Vinagre, when installed, is called Remote Desktop Viewer in the menu. The Remmina client doesn’t seem to display all colors of the remote desktop.

### Spotify

To install the Linux version, follow the instructions here.

The Spotify sources are disabled at upgrades of Ubuntu so they need to be manually enabled again for Spotify upgrades to work.

### SSH and SCP

Install the OpenSSH server according to these hints. Don’t forget to disable password login to only allow login using a private key.

Generate a pair of keys using:

arto@Heron:~$ssh-keygen -t rsa  Add the public key to the authorized keys like this: arto@Heron:~$ cat id_rsa.pub >> authorized_keys
arto@Heron:~$sudo service ssh restart  To test the access, copy the private key to the .ssh directory of a remote machine and set it’s mode to 600 (ssh refuses to use keys with too liberal access). Then type: ssh -i /home/user/.ssh/private_key_rsa user@host Or, using a non-standard port (when you have several ssh servers running behind a router): ssh -p 23 -i /home/arto/.ssh/private_key_rsa user@host (replace “user”, “private_key” and “host”). If you want to use Putty on a PC then the private key needs to be converted into Putty format using the Linux application puttygen like this: arto@Heron:~$ sudo apt-get install putty-tools
arto@Heron:~/.ssh$puttygen id_rsa -o id_rsa.ppk  To access the desktop remotely, follow these instructions. Remember that the ip-address to be entered is the local ip-address (inside the router domain) of the server. Files can be conveniently copied back and forth using the WinSCP application. Also in its configuration the ip-address to enter is the local ip-address of the server. Select file protocol SCP and enter the path to the private (Putty format) key file. An even easier way to mount a part of the server computer’s file system on the remote computer is by using win sshfs on Windows and sshfs on Linux. win sshfs works rather straightforward except that it doesn’t support the standard rsa key format. The private key instead needs to be converted with: openssl rsa -in id_rsa -out newkey_id_rsa -des3 Linux works with the (unconverted) rsa key generated above. Install sshfs and then run: sshfs user@host:/remote/path /local/path/ -o IdentityFile=/path/to/key -o reconnect host is either the ip number or the symbolic name for the host like ssh.myhost.com. The reconnect option reconnects the remote volume after waking up from suspension. When using a non-standard port: sshfs user@host:/remote/path /local/path -C -p 23 The local directory should be owned by user. To unmount, do: fusermount -u /local/path If you get a “connection reset by peer” check so that you’ve set the mode of the private key file to 600. To auto-mount a volume at start-up, follow these instructions. If you get an “offending key” dialog, then check this out for a fix. Add the option -o reconnect to the script so that the volume re-mounts when waking up from sleep. sshfs doesn’t give much verbose error messages. If something seems to go wrong, use: ssh user@x.x.x.x For more on ssh, see this excellent guide. ### Gnome Classic Unity sucks! To install Gnome do:  sudo apt-get install gnome-session-flashback sudo apt-get install compizconfig-settings-manager compiz-plugins  This will add the Gnome alternatives to the login screen. The compizconfig-settings-manager enables setting of e.g. the number of virtual desktops. The prefereces in the GUI don’t seem to work. ### Trash can etc The trash can is not visible on the desktop per default. The easiest way to show it is by using the gnome-tweak-tool. Install it and start it from a terminal window (it doesn’t seem to install any menu item). The tool is pretty self-explanatory. ### Installing a new kernel See e.g., this post. Note that three linux packages are required. Change the name of the package as desired. All kernels can be found here. ### LibreOffice Install Microsoft fonts like Arial and Verdana: sudo apt-get install ttf-mscorefonts-installer ### RabbitVCS RabbitVCS is a graphical front end to svn and Git. Works out of the box except for the following quirk when logging into an svn server on a Windows domain: the login name must include the domain name and a backslash like this:  contextvision\ArtoJ  The user name must have the correct case. Note that the backslash is not escaped (with another backslash). ### Deep learning environment The following has been tested on an Ubuntu 14.04. Python 2.7 comes pre-installed. In addition we need:  sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git sudo apt-get install python-matplotlib sudo pip install Theano sudo pip install keras  Install Cuda: Get a Cuda .deb file from Nvidia.  sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb sudo apt-get update sudo apt-get install cuda  Add this to your .bashrc file:  export CUDA_HOME=/usr/local/cuda export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}  To install the Cuda samples and to check so that Cuda is working do: $ cuda-install-samples-7.5.sh ~ $cd ~/NVIDIA_CUDA-7.5_Samples$ cd 1_Utilities/deviceQuery $make$ ./deviceQuery 

The output from the program should end with Result = PASS.

To accelerate the GPU even further, install CuDNN.

 cudnn-8.0-linux-x64-v5.0-ga.tgz 
It consists of one header file and one shared object (library). The most straightforward installation is to copy the files to where the rest of the Cuda files are, i.e. /usr/local/cuda/include/ and /usr/local/cuda/lib64/. This way no paths need to be edited for the files to be found. There may be some version incompatibilities. Go as far back in older versions as you need while still matching the Cuda version.

When installing Tensorflow (using pip), remember to install the GPU version.

The .theanorc file should look like:
 [global] device = gpu floatX = float32

[cuda]
root = /usr/local/cuda/bin

[lib]
cnmem = 0.9

The cnmem parameter gives the fraction of the GPU memory that will be used by Theano. 0.9 thus means 90%. This will further accelerate the calculations somewhat. Note that this number has to be a float.

### Markdown Editor

ReText is a good one for Linux. It can be installed with apt.

To be able to show math, also install:
 sudo apt-get install libjs-mathjax 

Then add “mathjax” to the extensionlist in ReText preferences. Finally select “Use WebKit renderer”. Otherwise the math won’t still show.