Difference between revisions of "GNU Linux/Ubuntu"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Adding entry for building VMware Tools)
m (Added yet another option for reviewing package deps)
 
(13 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
''These are my notes for various Ubuntu tasks.''
 
''These are my notes for various Ubuntu tasks.''
  
== Tips/Tricks ==
+
== Determining the version of the running kernel ==
  
 +
From the Ubuntu kernel wiki page <ref name="ubuntu-wiki-kernel" />:
 +
 +
''<blockquote>The official version of an Ubuntu kernel is found in the <code>/proc/version_signature</code> file. This file contains both the full Ubuntu version of the kernel and the mainline version on which it is based. The first field is always Ubuntu, the second field is the Ubuntu kernel version, and the final field is the upstream version.</blockquote>''
 +
 +
From an Ubuntu 14.04 box:
 +
 +
<syntaxhighlight lang="bash">
 +
$ uname -a
 +
</syntaxhighlight>
 +
 +
<pre>
 +
Linux r2d2 3.13.0-46-generic #77-Ubuntu SMP Mon Mar 2 18:23:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
 +
</pre>
 +
 +
<syntaxhighlight lang="bash">
 +
$ cat /proc/version_signature
 +
</syntaxhighlight>
 +
 +
<pre>
 +
Ubuntu 3.13.0-46.77-generic 3.13.11-ckt15
 +
</pre>
 +
== Packages ==
  
 
=== Package install status cloning ===
 
=== Package install status cloning ===
 +
 +
'''NOTE''': For whatever reason, I've not had any reliable results with this approach since moving to Ubuntu 12.04 and newer. I just manually install packages now.
  
 
Other descriptions:
 
Other descriptions:
Line 21: Line 45:
 
# <code>sudo apt-get dselect-upgrade</code>
 
# <code>sudo apt-get dselect-upgrade</code>
  
 +
=== Viewing installed packages ===
 +
 +
* <syntaxhighlight lang="bash" enclose="none">dpkg --get-selections | grep -v deinstalled</syntaxhighlight>
 +
 +
* <syntaxhighlight lang="bash" enclose="none">dpkg -l | grep -Ev '^rc'</syntaxhighlight>
 +
 +
 +
=== Listing dependencies of a package ===
 +
 +
<ref name="ubuntu-list-deps-1" />
 +
<ref name="ubuntu-list-deps-2" />
 +
 +
# <syntaxhighlight lang="bash" enclose="none">dpkg -I FILE.deb</syntaxhighlight>
 +
# <syntaxhighlight lang="bash" enclose="none">apt-cache depends package_name</syntaxhighlight>
 +
# <syntaxhighlight lang="bash" enclose="none">apt-cache showpkg package-name</syntaxhighlight>
 +
 +
This latter command shows dependencies of packages in the repos. It's pretty verbose.
 +
 +
=== Listing reverse dependencies ===
 +
 +
<ref name="ubuntu-list-reverse-deps" />
 +
 +
# <syntaxhighlight lang="bash" enclose="none">aptitude why $package</syntaxhighlight>
 +
# <syntaxhighlight lang="bash" enclose="none">apt-cache rdepends $package</syntaxhighlight>
 +
 +
 +
=== Cleaning out old kernels ===
 +
 +
For this example, we want to keep these two kernels and get rid of all the others.
 +
 +
 +
We first get the list of kernels installed. I've intentionally trimmed the list to 10 lines.
 +
 +
<syntaxhighlight lang="bash">dpkg --get-selections | grep linux-image</syntaxhighlight>
 +
 +
<pre>
 +
root@silo:~# dpkg --get-selections | grep linux-image | tail -n 10
 +
linux-image-2.6.32-38-generic-pae              install
 +
linux-image-2.6.32-39-generic                  install
 +
linux-image-2.6.32-39-generic-pae              install
 +
linux-image-2.6.32-40-generic                  install
 +
linux-image-2.6.32-40-generic-pae              install
 +
linux-image-2.6.32-41-generic                  install
 +
linux-image-2.6.32-41-generic-pae              install
 +
linux-image-generic                            install
 +
linux-image-generic-pae                        install
 +
linux-image-server                              install
 +
</pre>
 +
 +
As you can see in the list, <code>linux-image-2.6.32-41-generic*</code> is the last one in the list and <code>uname -r</code> confirms the currently running kernel:
  
 +
<pre>2.6.32-41-generic-pae</pre>
 +
 +
We'll want to leave that one in place, so we'll need to exclude it from the list that we'll be removing. There are a LOT of ways this could be done, but the approach below is the one I use for copying/pasting into remote terminals.
 +
 +
<syntaxhighlight lang="bash" enclose="pre">
 +
# Set a variable in the shell that contains MOST of the current running kernel. If
 +
# we match exactly we'll exclude any pae or non-pae versions of the kernel
 +
CURRENT_KERNEL=$(uname -r| cut -c 1-15)
 +
 +
FILTER_OUT="(deinstall|linux-image-generic|linux-image-server|linux-image-virtual|${CURRENT_KERNEL})"
 +
 +
MATCH_ON_REGEX='\<linux-image[0-9.a-zA-z-]+\>'
 +
 +
# Print a list of kernels we'll be removing
 +
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do echo $kernel; done
 +
 +
# Start the removal process
 +
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove --purge $kernel; done
 +
</syntaxhighlight>
 +
 +
If you're looking for a script that you can run instead of having to copy/paste the code, this is the same as above with just a few more lines:
 +
 +
<syntaxhighlight lang="bash" enclose="pre">
 +
#!/bin/bash
 +
 +
# Set a variable in the shell that contains MOST of the current running kernel. If
 +
# we match exactly we'll exclude any pae or non-pae versions of the kernel
 +
CURRENT_KERNEL=$(uname -r| cut -c 1-15)
 +
 +
FILTER_OUT="(deinstall|linux-image-generic|linux-image-server|linux-image-virtual|${CURRENT_KERNEL})"
 +
 +
MATCH_ON_REGEX='\<linux-image[0-9.a-zA-z-]+\>'
 +
 +
 +
echo -e "\n\nPress Enter to remove these kernels or Ctrl-C to Cancel:\n"
 +
 +
# Print a list of kernels we'll be removing
 +
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do echo -e "    * $kernel"; done
 +
 +
read TEMP_VAR
 +
 +
# Start the removal process
 +
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove --purge -y $kernel; done
 +
</syntaxhighlight>
 +
 +
 +
=== Removing packages with 'rc' status <ref name="dpkg-purge" /> ===
 +
 +
Before I knew better I removed old kernel packages with just <code>apt-get remove X</code> instead of also using <code>--purge</code> to completely remove the package and all associated content. Unfortunately because I forgot to use <code>--purge</code> I cannot use <code>apt-get remove</code> to finish the removal. Thankfully we can use <code>dpkg --purge</code> to finish the job.
 +
 +
<syntaxhighlight lang="bash">
 +
dpkg -l |awk '/^rc/ {print $2}' | xargs sudo dpkg --purge
 +
</syntaxhighlight>
 +
 +
==== Use with caution! ====
 +
 +
Thankfully I backed up <code>/etc</code> prior to doing so, but on an Ubuntu 14.04 box I found many instances of packages with the <code>rc</code> status. I removed all of them using the above example and X refused to load. I reverted using the tarball I created just prior to running the command and all was well.
 +
 +
=== Disabling/Removing <code>whoopsie</code> package <ref name="whoopsie-removal" /> ===
 +
 +
As said better elsewhere:
 +
 +
<blockquote>
 +
What's whoopsie? It's the "Ubuntu Error Reporting" daemon, and is installed by default in both desktop/server installations. When something crashes, whoopsie does two things: #1) Collects the crash report generated by Apport and  #2 can send them to Ubuntu/Canonical (specifically to https://daisy.ubuntu.com
 +
</blockquote>
 +
 +
It can be disabled by setting the <code>report_crashes</code> parameter to <code>false</code> in the <code>/etc/default/whoopsie</code> file. It can be removed via <code>apt-get purge whoopsie</code>,
 +
 +
 +
== VMware ==
  
 
=== Ubuntu as a VMware guest ===
 
=== Ubuntu as a VMware guest ===
 +
  
 
==== VMware Tools: Installing the appropriate kernel headers for compilation ====
 
==== VMware Tools: Installing the appropriate kernel headers for compilation ====
  
 
<pre>sudo apt-get install linux-headers-$(uname -r)</pre>
 
<pre>sudo apt-get install linux-headers-$(uname -r)</pre>
 +
  
 
==== Shared Folders: correct fstab options ====
 
==== Shared Folders: correct fstab options ====
Line 55: Line 201:
 
./vmware-install.pl  --default
 
./vmware-install.pl  --default
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
== Remote Access ==
  
 
=== Enabling VNC Server ===
 
=== Enabling VNC Server ===
Line 64: Line 213:
 
# <code>sudo nano /etc/rc.local</code>
 
# <code>sudo nano /etc/rc.local</code>
 
# <code>su - user -c "cd /home/user/ && vncserver :1 -geometry 1024x768 -depth 24" 2>/dev/null &</code>
 
# <code>su - user -c "cd /home/user/ && vncserver :1 -geometry 1024x768 -depth 24" 2>/dev/null &</code>
 
<references />
 
  
 
==== Enable Gnome ====
 
==== Enable Gnome ====
Line 84: Line 231:
 
</pre>
 
</pre>
  
 +
 +
== Firewall ==
  
 
=== Quick UFW rule list ===
 
=== Quick UFW rule list ===
Line 94: Line 243:
  
  
=== Viewing installed packages ===
+
== Networking ==
  
<pre>dpkg --get-selections | grep -v deinstalled</pre>
+
=== Disable IPv6 ===
  
 +
<ref name="ubuntu-disable-ipv6" />
  
 
+
Modify <code>/etc/sysctl.conf</code> add add this to the bottom:
=== Cleaning out old kernels ===
 
 
 
For this example, we want to keep these two kernels and get rid of all the others.
 
 
 
 
 
We first get the list of kernels installed. I've intentionally trimmed the list to 10 lines.
 
 
 
<syntaxhighlight lang="bash">dpkg --get-selections | grep linux-image</syntaxhighlight>
 
  
 
<pre>
 
<pre>
root@silo:~# dpkg --get-selections | grep linux-image | tail -n 10
+
net.ipv6.conf.all.disable_ipv6 = 1
linux-image-2.6.32-38-generic-pae              install
+
net.ipv6.conf.default.disable_ipv6 = 1
linux-image-2.6.32-39-generic                  install
+
net.ipv6.conf.lo.disable_ipv6 = 1
linux-image-2.6.32-39-generic-pae              install
 
linux-image-2.6.32-40-generic                  install
 
linux-image-2.6.32-40-generic-pae              install
 
linux-image-2.6.32-41-generic                  install
 
linux-image-2.6.32-41-generic-pae              install
 
linux-image-generic                            install
 
linux-image-generic-pae                        install
 
linux-image-server                              install
 
 
</pre>
 
</pre>
  
As you can see in the list, <code>linux-image-2.6.32-41-generic*</code> is the last one in the list and <code>uname -r</code> confirms the currently running kernel:
+
Run <code>sudo sysctl -p</code>
 +
 
  
<pre>2.6.32-41-generic-pae</pre>
+
== References ==
  
We'll want to leave that one in place, so we'll need to exclude it from the list that we'll be removing. There are a LOT of ways this could be done, but the approach below is the one I use.
+
<references>
  
<syntaxhighlight lang="bash">
+
<ref name="dpkg-purge">[http://ascending.wordpress.com/2007/04/10/apt-tip-purge-removed-packages/ APT Tip: Purge Removed Packages]</ref>
# Set a variable in the shell that contains MOST of the current running kernel. If
+
<ref name="whoopsie-removal">[http://askubuntu.com/questions/135540/what-is-the-whoopsie-process-and-how-can-i-remove-it askubuntu.com - What is the 'whoopsie' process and how can I remove it?]</ref>
# we match exactly we'll exclude any pae or non-pae versions of the kernel
+
<ref name="ubuntu-disable-ipv6">[http://askubuntu.com/questions/346126/how-to-disable-ipv6-on-ubuntu How to disable IPv6 on Ubuntu?]</ref>
CURRENT_KERNEL=$(uname -r| cut -c 1-15)
 
  
FILTER_OUT="(deinstall|linux-image-generic|linux-image-server|linux-image-virtual|${CURRENT_KERNEL})"
+
<ref name="ubuntu-wiki-kernel">[https://wiki.ubuntu.com/Kernel/FAQ#Kernel.2BAC8-FAQ.2BAC8-GeneralVersionRunning.How_can_we_determine_the_version_of_the_running_kernel.3F Ubuntu wiki - How can we determine the version of the running kernel?]</ref>
  
MATCH_ON_REGEX='\<linux-image[0-9.a-zA-z-]+\>'
+
<ref name="ubuntu-list-deps-1">http://stackoverflow.com/questions/4627158/howto-list-all-dependencies-of-a-package-on-linux</ref>
 +
<ref name="ubuntu-list-deps-2">http://askubuntu.com/questions/80655/how-can-i-check-dependency-list-for-a-deb-package</ref>
  
# Print a list of kernels we'll be removing
+
<ref name="ubuntu-list-reverse-deps">http://askubuntu.com/questions/128524/how-to-list-package-dependencies-reverse-dependencies</ref>
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do echo $kernel; done
 
  
# Start the removal process
+
<references />
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove $kernel; done
 
</syntaxhighlight>
 

Latest revision as of 07:30, 10 March 2015


These are my notes for various Ubuntu tasks.

Determining the version of the running kernel

From the Ubuntu kernel wiki page [1]:

The official version of an Ubuntu kernel is found in the /proc/version_signature file. This file contains both the full Ubuntu version of the kernel and the mainline version on which it is based. The first field is always Ubuntu, the second field is the Ubuntu kernel version, and the final field is the upstream version.

From an Ubuntu 14.04 box:

$ uname -a
Linux r2d2 3.13.0-46-generic #77-Ubuntu SMP Mon Mar 2 18:23:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/version_signature
Ubuntu 3.13.0-46.77-generic 3.13.11-ckt15

Packages

Package install status cloning

NOTE: For whatever reason, I've not had any reliable results with this approach since moving to Ubuntu 12.04 and newer. I just manually install packages now.

Other descriptions:

  • Ubuntu cloning
  • Ubuntu install cloning
  • etc

Steps

  1. sudo dpkg –-get-selections > packages.txt
  2. Copy packages.txt to the remote machine
  3. sudo dpkg –-set-selections < packages.txt
  4. sudo apt-get dselect-upgrade

Viewing installed packages

  • dpkg --get-selections | grep -v deinstalled
  • dpkg -l | grep -Ev '^rc'


Listing dependencies of a package

[2] [3]

  1. dpkg -I FILE.deb
  2. apt-cache depends package_name
  3. apt-cache showpkg package-name

This latter command shows dependencies of packages in the repos. It's pretty verbose.

Listing reverse dependencies

[4]

  1. aptitude why $package
  2. apt-cache rdepends $package


Cleaning out old kernels

For this example, we want to keep these two kernels and get rid of all the others.


We first get the list of kernels installed. I've intentionally trimmed the list to 10 lines.

dpkg --get-selections | grep linux-image
root@silo:~# dpkg --get-selections | grep linux-image | tail -n 10
linux-image-2.6.32-38-generic-pae               install
linux-image-2.6.32-39-generic                   install
linux-image-2.6.32-39-generic-pae               install
linux-image-2.6.32-40-generic                   install
linux-image-2.6.32-40-generic-pae               install
linux-image-2.6.32-41-generic                   install
linux-image-2.6.32-41-generic-pae               install
linux-image-generic                             install
linux-image-generic-pae                         install
linux-image-server                              install

As you can see in the list, linux-image-2.6.32-41-generic* is the last one in the list and uname -r confirms the currently running kernel:

2.6.32-41-generic-pae

We'll want to leave that one in place, so we'll need to exclude it from the list that we'll be removing. There are a LOT of ways this could be done, but the approach below is the one I use for copying/pasting into remote terminals.

# Set a variable in the shell that contains MOST of the current running kernel. If
# we match exactly we'll exclude any pae or non-pae versions of the kernel
CURRENT_KERNEL=$(uname -r| cut -c 1-15)

FILTER_OUT="(deinstall|linux-image-generic|linux-image-server|linux-image-virtual|${CURRENT_KERNEL})"

MATCH_ON_REGEX='\<linux-image[0-9.a-zA-z-]+\>'

# Print a list of kernels we'll be removing
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do echo $kernel; done

# Start the removal process
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove --purge $kernel; done

If you're looking for a script that you can run instead of having to copy/paste the code, this is the same as above with just a few more lines:

#!/bin/bash

# Set a variable in the shell that contains MOST of the current running kernel. If
# we match exactly we'll exclude any pae or non-pae versions of the kernel
CURRENT_KERNEL=$(uname -r| cut -c 1-15)
 
FILTER_OUT="(deinstall|linux-image-generic|linux-image-server|linux-image-virtual|${CURRENT_KERNEL})"
 
MATCH_ON_REGEX='\<linux-image[0-9.a-zA-z-]+\>'


echo -e "\n\nPress Enter to remove these kernels or Ctrl-C to Cancel:\n"
 
# Print a list of kernels we'll be removing
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do echo -e "    * $kernel"; done

read TEMP_VAR

# Start the removal process
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove --purge -y $kernel; done


Removing packages with 'rc' status [5]

Before I knew better I removed old kernel packages with just apt-get remove X instead of also using --purge to completely remove the package and all associated content. Unfortunately because I forgot to use --purge I cannot use apt-get remove to finish the removal. Thankfully we can use dpkg --purge to finish the job.

dpkg -l |awk '/^rc/ {print $2}' | xargs sudo dpkg --purge

Use with caution!

Thankfully I backed up /etc prior to doing so, but on an Ubuntu 14.04 box I found many instances of packages with the rc status. I removed all of them using the above example and X refused to load. I reverted using the tarball I created just prior to running the command and all was well.

Disabling/Removing whoopsie package [6]

As said better elsewhere:

What's whoopsie? It's the "Ubuntu Error Reporting" daemon, and is installed by default in both desktop/server installations. When something crashes, whoopsie does two things: #1) Collects the crash report generated by Apport and #2 can send them to Ubuntu/Canonical (specifically to https://daisy.ubuntu.com

It can be disabled by setting the report_crashes parameter to false in the /etc/default/whoopsie file. It can be removed via apt-get purge whoopsie,


VMware

Ubuntu as a VMware guest

VMware Tools: Installing the appropriate kernel headers for compilation

sudo apt-get install linux-headers-$(uname -r)


Shared Folders: correct fstab options

Assuming:

  • User Id is 1000
  • /mnt/hgfs folder exists
  • VMware Tools are installed
  • You don't need the mount points available at boot
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5,uid=1000,gid=1000,nobootwait 0 0


Building VMware Tools

First, mount the tools installer iso from VMware Workstation, the vSphere Client or VMware Fusion. Then proceed with these steps. Note the suggestion about running the tools installer manually the first time.

cd /tmp
mount /dev/sr0 /media
tar zxf /media/VMware*.gz
cd vmware-tools-distrib

# You probably want to run this manually the first time so your system-specific settings are set
# Note: Not sure where they're stored, but they appear to be saved between tool rebuilds
./vmware-install.pl  --default


Remote Access

Enabling VNC Server

Start at boot

  1. Login as USER [7]
  2. vncpasswd
  3. sudo nano /etc/rc.local
  4. su - user -c "cd /home/user/ && vncserver :1 -geometry 1024x768 -depth 24" 2>/dev/null &

Enable Gnome

nano /home/user/.vnc/xstartup

Include the following:

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession


Firewall

Quick UFW rule list

  1. Set the default rule to deny everything
    ufw default deny
  2. Allow in web traffic from "the world" to port 80
    ufw allow 80
  3. Allow ssh from a trusted network
    ufw allow from 192.168.0.0/24 to any port 22
  4. Enable the rules we've just set
    ufw enable
  5. Show the enabled rules
    ufw status


Networking

Disable IPv6

[8]

Modify /etc/sysctl.conf add add this to the bottom:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Run sudo sysctl -p


References

<references>

[5] [6] [8]

[1]

[2] [3]

[4]