Ubuntu Notes.  Peter Halverson     Last update 3/13/2020
http://halverscience.net/index.html

Link to latest notes on Google Docs:
https://docs.google.com/document/d/1P-cUDhJhSQuvSHSRrN4GcRmKRwpBav7t5VRw-JxouCI/edit?usp=sharing

These are Halverson's personal notes. They are unedited and there is no guarantee of accuracy.  Use at your own risk. I am making them available to you because they might actually be helpful.  If they are helpful, I would really appreciate a "thank you". 

My version of Ubuntu:  16.04 LTS

I am using this version because it matches the Ubuntu used in Red Pitaya.

-----------------  How to run the "finder" (the gui/window way to access files) -----------
Run nautilus.

To do in such a way as to overcome protections, use the command
sudo -H nautilus    (works)
or
sudo -i nautilus    (didn't try)

-------------------------  Where are the disk drives in the Ubuntu file system? -----------------
“Mount point”
Location of disk drives (USB drives, DVDs) in the files system.
For nautilus, (the "finder") look in Computer/media
For the terminal, look in /media

--------------------------------------- How to burn DVDs --------------------------------------
Software to burn DVDs.  Use to make .iso images of Ubuntu installation disks.
Brasero     (Find in the graphical Ubuntu software finder)
  
Alternative, better software: K3b   

------------------------------ Recovering from the "purple screen" in a messed up boot. -------------
When the "man" briefly appears at the bottom of the screen during boot, press the down-arrow key to enter the GRUB (boot) menu.

------------------------------ How to change the name of the computer ----------------------
(works on in Ubuntu 16)
halver@halver-Dell-DXP061:~$ hostnamectl
   Static hostname: halver-Dell-DXP061     <------------ old name
         Icon name: computer-server
           Chassis: server
        Machine ID: b438f03aeccc4560a6b15affa10ecbf6
           Boot ID: a626ac229068405796ba9bae909213ae
  Operating System: Ubuntu 16.04.6 LTS
            Kernel: Linux 4.15.0-58-generic
      Architecture: x86-64
halver@halver-Dell-DXP061:~$ hostnamectl set-hostname 'ALPHA'
Reboot
halver@ALPHA:~$ hostnamectl
   Static hostname: ALPHA
         Icon name: computer-server
           Chassis: server
        Machine ID: b438f03aeccc4560a6b15affa10ecbf6
           Boot ID: b784bd0040084d45a13258407f4fd383
  Operating System: Ubuntu 16.04.6 LTS
            Kernel: Linux 4.15.0-58-generic
      Architecture: x86-64

NOTE:  It looks like you also need to change (edit using nano) /etc/hosts
Also, check that /etc/hostname is correct.

----------------------------------- How to prevent or stop thrashing ------------------------------
Use the “magic key” alt-sysreq    (aka alt-sysrq)
Or use the script that is mentioned to prevent thrashing.

https://superuser.com/questions/248707/how-do-i-quickly-stop-a-process-that-is-causing-thrashing-due-to-excess-memory

List of magic key combinations is in Wikipedia:
https://en.wikipedia.org/wiki/Magic_SysRq_key

Note that there isn’t necessarily any visible feedback from doing the key combination.

Recommended sequence to reboot a stuck system:
REISUB   In other words do 
Alt sysrq r     then Alt sysrq e     then Alt sysrq i then   Alt sysrq s then Alt sysrq ru  then Alt sysrq b   
Note that you press and hold the Alt key then press SysRQ then press R.  Then repeat with the E,I,S,U,B 

----------------------------- How to activate the Magic key, alt-sysreq ------------------------
This is a feature to stop the computer in emergencies.
Edit (using nano) the file
/etc/sysctl.d/10-magic-sysrq.conf

To include the line 
Kernel.sysrq = 1

I got this info from 
https://askubuntu.com/questions/11002/alt-sysrq-reisub-doesnt-reboot-my-laptop

-----------------------------  How to extract/unzip/untar a .tar.gz file ---------------------
tar -xvzf community_images.tar.gz
To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things:
  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • z: tells tar to decompress the archive using gzip
  • x: tar can collect files or extract them. x does the latter.
  • v: makes tar talk a lot. Verbose output shows you all the files being extracted.
This came from https://askubuntu.com/questions/25347/what-command-do-i-need-to-unzip-extract-a-tar-gz-file

-------------------------------------  Screenshots ---------------------------------
To take a screenshot of the desktop, a window, or an area at any time using these global keyboard shortcuts:
  • Prt Scrn to take a screenshot of the desktop.
  • Alt + Prt Scrn to take a screenshot of a window.
  • Shift + Prt Scrn to take a screenshot of an area you select.
----------------  How to get a record (history) of commands you typed in to the terminal -------------
There is already a hidden file in your home directory called .bash_history which you can print. One observation here: this file, in a default configuration, doesn't contain the commands used in your current opened terminal session. So, close the terminal before you print it.
But if you want to save the terminal history in another file, then you can use the following command (this new file will contain also and the commands used in your currently opened terminal session):
history > history_for_print.txt

A new file called history_for_print.txt will be created in your currently working directory containing your last used commands (by default HISTSIZE=1000 and HISTFILESIZE=2000, but you can change these values in your ~/.bashrc file). You can also run "history -a" to write commands from the current session to the history file without having to exit.
This is from https://askubuntu.com/questions/409541/save-the-terminal-history-to-a-file-for-print
----------------------------------------  How to get normal scrollbars -------------------------------
See
https://askubuntu.com/questions/775201/how-do-i-get-a-bigger-static-scrollbar-aka-normal-scrollbar

------------------------  How to enable root as a user; how to enable root logins ------------------
https://askubuntu.com/questions/44418/how-to-enable-root-login
sudo passwd root                     (This sets the password for the root account)
sudo passwd -u root                 (This unlocks it.)
The article also explains how to lock it again:
sudo passwd -l root

------------------------------------- How to format external disks ---------------------------
The “disks” utility works but the result is read-only, as the owner is root.
To make a functional external disk I ended up using a Mac, the Disk Utility program.
This only works for FAT-32 format (the old MS-DOS format).  This has problem of 4 Gb file size limit.
Solution to the ownership problem:
Change the ownership (use chown) or the permissions (chmod) at the mount point.
See
https://help.ubuntu.com/community/InstallingANewHardDrive
(I need to do more notes here)

----------------------------- How to list all the disks connected to the computer ---------------------
sudo lshw -class disk -short
(“lshw” stands for “LiSt HardWare”)

-----------------------------  How to make bootable backups of the system disk --------------------
(Specifically for the NUC computer I’m using for FPGA work.)
I make myself a live DVD of Clonezilla.  https://clonezilla.org/
I attach a 1Tb hard drive via SATA cable to the SATA connector inside the NUC.  (Connecting the hard drive via USB didn’t seem to result in a bootable backup.)
Boot the NUC (my computer) from the Clonezilla DVD.
Tell Clonezilla to make a copy of the NUC’s internal solid state drive on the external hard drive.  This takes about two hours, as Clonezilla makes an exact copy, all 500 Gb.
To verify that my backup is good, I remove the solid state drive from the NUC and boot from the hard drive.  Yes! It works. From now on I will make bootable backups once every few days.
Note:  The Clonezilla site says I can’t use the SSD and the backup drive at the same time because they are really identical and the system may mix up the two devices.
I remove the hard and put the SSD back in and continue with my work.

-------------------- How to make a bootable USB flash drive version of Clonezilla. --------------------
First I need to install Tuxboot.  Instructions here: https://tuxboot.org/download/
  • sudo apt-add-repository ppa:thomas.tsai/ubuntu-tuxboot
  • sudo apt-get update
  • sudo apt-get install tuxboot
  • sudo tuxboot
This open a window called Tuxboot.  The USB flash drive appears to be sdb1.
I select the option to get Clonezilla from on-line distribution (rather than a local ISO file) and click OK and it starts installing on the flash drive.  Takes a few minutes.

---------------------- How to get exFAT formatted disks drives to work with ubuntu. ------------------
Note:  Most USB sticks are formatted with the MS-DOS file system known as FAT32.  (I think it means File Allocation Table) But FAT32 is limited to files no bigger than 4 Gb so exFAT is needed for big things like Xilinx Vivado downloads.
https://askubuntu.com/questions/370398/how-to-get-a-drive-formatted-with-exfat-working
Install exFAT “drivers”
sudo apt-get install exfat-utils exfat-fuse

----------------------------------  How to search for text in a Ubuntu file system -------------------------
The old fashioned way is to use "grep" and search all the files on a disk.  It works but it is very slow.

https://askubuntu.com/questions/127892/how-to-find-a-text-file-which-contains-a-specific-word-inside-not-in-its-name
This works well:  Install gnome-search-tool.
sudo apt-get install gnome-search-tool
Then go to the upper-left corner of the desktop (the “search”) and get “Search  for Files…”

---------------- How to make active tabs more distinguishable from inactive tabs. ----------------
Ubuntu 16 has a small but very annoying problem with its windows.  Multiple tab windows are confusing because the active tab is indistinguishable from inactive tabs.

I tried this:
https://askubuntu.com/questions/355297/gnome-terminal-tabs-no-contrast-between-active-and-inactive-tabs
DOESN'T WORK FOR ME.   Maybe gtk.css isn't getting read?
Try instead this:  
https://ubuntuforums.org/showthread.php?t=2347833
Edit /usr/share/themes/Ambiance/gtk-3.0/gtk-widgets.css

/* give active tab a background, as it might be dragged across of others when reordering */
/* Halverson change:  @bg_color changed to @selected_bg_color */
.notebook tab:active {
    background-color: @selected_bg_color;
}
********  YES This Works! *******

-------------------- Make ethernet work after computer is "suspended" or "sleeping" ----------------

I had a problem with the network not working after the computer sleeps.  Bing/Google search found that many others have this problem. I found a hint that helped here:
https://askubuntu.com/questions/997859/ubuntu-16-04-ethernet-resume-after-suspend-cold-boot

In it there is mention of an Intel-specific utility "powertop" that can help solve the problem.  (Relevant to me b/c I have an Intel NUC).

I found instructions on installing "powertop" here:
https://linoxide.com/linux-how-to/install-use-powertop-ubuntu-16-04/

What I did is, in a terminal,
sudo apt-get update             (updates the lists of available software and libraries?)
sudo apt-get install powertop
sudo powertop

This brings up a primitive text-based menu. (Expand the terminal to see the full menu and use the "r" key to refresh.)
---Use the Tab key to select the "Tunables" menu.
---Scroll down to the line that says
Runtime PM for PCI Device Intel Corporation Ethernet Connection (3) I218-V
---Use the spacebar to toggle from "Bad" to "Good."
---Use the Esc key to exit.
---Try suspend and wake.  Now the ethernet is working again.

**********  YES This works! **********
Note that I'm doing the opposite of what the "Ask Ubuntu" advice was.  Strange, but it works for me.

----------------- How to add an application to the launcher in Ubuntu 16.04 ----------------------

This came from http://nmp90.com/2018/06/add-application-launch-ubuntu-16-04/

Use a program called alacarte:
     sudo apt-get install alacarte
To start it, I just type "alacarte" in a terminal.
Click on the New Item button, write the command & name of the app, choose a logo if you want and you will see it appearing shortly in the Unity launcher by typing the name. Otherwise, you will have to create a *.desktop file and add it to .local/share/applications which I couldn’t make it work after spending a couple of hours.

---------------------------- How to make the Ubuntu desktop appear on another computer, such as my Mac, for making a screencast. -------------------------------------------------------------------

 Use a tool called "VNC" which stands for "Virtual Network Computer."

Two options on the mac: 
   (1)  Use "chicken" a free VNC application.   This seems to work well.
   (2) VNC is already installed in OS-X.  Look for the application called "Desktop Sharing"

To make the mac VNC into Ubuntu...
---Install "Chicken" from sourceforge on the mac from https://sourceforge.net/projects/chicken/
---Install ssh on Ubuntu (see below)
---Find out the Ubuntu computer's IP address by going to System Setting > Network
     (currently 192.168.1.125)
---Start the server by running "Desktop Sharing".   (You get to it by doing "Search your computer")
--- Start "Chicken".  In the VNC Login box, put the host (currently 192.168.1.125)
  Display port 0,    The password and click connect.
  The screen will be black until you click "Allow" in the box that appears on the Ubuntu machine.

---If you get the "Unknown authType 18" error, then in a terminal do this:
  gsettings set org.gnome.Vino require-encryption false
                  This crucial tip is from https://www.brentalexander.com/chicken-of-the-vnc-unknown-authtype-18/

--- Stupid "fat dot" mouse pointer fix is here:
http://hints.macworld.com/article.php?story=20040827145528277
The pointer's image can be edited.  To get to it, control-click on the application, choose Show Package Contents, navigate into Contents -> Resources.  To change the pointer, just open the TIFFs (called rfbCursor.tiff, rfbCursor2.tiff, and rfbCursor3.tiff) in your favourite image editor (I used Graphic Converter), and replace them with your own 16x16 TIFF images.

Alternative to Chicken:  Use the Mac's built-in VNC.  In the Finder, click Go > Connect to Server... >  vnc://192.168.1.125:5900/ It actually works OK, but the mouse cursors are weird.

------------------------------ How to install ssh  -----------------------------------
See this web page:
http://ubuntuhandbook.org/index.php/2016/04/enable-ssh-ubuntu-16-04-lts/

Steps I did:
sudo apt-get install openssh-server
sudo service ssh status

There are things that can be adjusted:
sudo nano /etc/ssh/sshd_config

----------------------------- 

-----------------------------