Difference between revisions of "GNU Linux/Ubuntu"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (Added commands to list package dependencies)
m (Rearranged sections)
Line 4: Line 4:
 
''These are my notes for various Ubuntu tasks.''
 
''These are my notes for various Ubuntu tasks.''
  
== Tips/Tricks ==
+
== Packages ==
 
 
  
 
=== Package install status cloning ===
 
=== Package install status cloning ===
Line 22: Line 21:
  
  
 +
=== Viewing installed packages ===
  
=== Ubuntu as a VMware guest ===
+
* <syntaxhighlight lang="bash" enclose="none">dpkg --get-selections | grep -v deinstalled</syntaxhighlight>
 
 
 
 
==== VMware Tools: Installing the appropriate kernel headers for compilation ====
 
 
 
<pre>sudo apt-get install linux-headers-$(uname -r)</pre>
 
 
 
 
 
==== 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
 
 
 
<pre>.host:/ /mnt/hgfs vmhgfs defaults,ttl=5,uid=1000,gid=1000,nobootwait 0 0</pre>
 
 
 
 
 
==== 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.
 
 
 
<syntaxhighlight lang="bash">
 
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
 
</syntaxhighlight>
 
 
 
 
 
=== Enabling VNC Server ===
 
 
 
==== Start at boot ====
 
 
 
# Login as USER <ref>''USER'' is a non-root account that the vncserver will be running as</ref>
 
# <code>vncpasswd</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>
 
 
 
<references />
 
 
 
==== Enable Gnome ====
 
 
 
<code>nano /home/user/.vnc/xstartup</code>
 
  
Include the following:
+
* <syntaxhighlight lang="bash" enclose="none">dpkg -l | grep -Ev '^rc'</syntaxhighlight>
 
 
<pre>
 
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
 
</pre>
 
 
 
 
 
=== Quick UFW rule list ===
 
 
 
# Set the default rule to deny everything <pre>ufw default deny</pre>
 
# Allow in web traffic from "the world" to port 80 <pre>ufw allow 80</pre>
 
# Allow ssh from a trusted network <pre>ufw allow from 192.168.0.0/24 to any port 22</pre>
 
# Enable the rules we've just set <pre>ufw enable</pre>
 
# Show the enabled rules <pre>ufw status</pre>
 
 
 
 
 
=== Viewing installed packages ===
 
 
 
<pre>dpkg --get-selections | grep -v deinstalled</pre>
 
  
  
Line 106: Line 32:
 
# <syntaxhighlight lang="bash" enclose="none">dpkg -I FILE.deb</syntaxhighlight>
 
# <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 depends package_name</syntaxhighlight>
 
  
  
Line 138: Line 63:
 
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.
 
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">
+
<syntaxhighlight lang="bash" enclose="pre">
 
# Set a variable in the shell that contains MOST of the current running kernel. If
 
# 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
 
# we match exactly we'll exclude any pae or non-pae versions of the kernel
Line 156: Line 81:
 
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:
 
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">
+
<syntaxhighlight lang="bash" enclose="pre">
 
#!/bin/bash
 
#!/bin/bash
  
Line 178: Line 103:
 
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove -y $kernel; done
 
for kernel in $(dpkg --get-selections | grep -viE "${FILTER_OUT}" | grep -iEo "${MATCH_ON_REGEX}"); do apt-get remove -y $kernel; done
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
== VMware ==
 +
 +
=== Ubuntu as a VMware guest ===
 +
 +
 +
==== VMware Tools: Installing the appropriate kernel headers for compilation ====
 +
 +
<pre>sudo apt-get install linux-headers-$(uname -r)</pre>
 +
 +
 +
==== 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
 +
 +
<pre>.host:/ /mnt/hgfs vmhgfs defaults,ttl=5,uid=1000,gid=1000,nobootwait 0 0</pre>
 +
 +
 +
==== 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.
 +
 +
<syntaxhighlight lang="bash">
 +
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
 +
</syntaxhighlight>
 +
 +
 +
== Remote Access ==
 +
 +
=== Enabling VNC Server ===
 +
 +
==== Start at boot ====
 +
 +
# Login as USER <ref>''USER'' is a non-root account that the vncserver will be running as</ref>
 +
# <code>vncpasswd</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>
 +
 +
==== Enable Gnome ====
 +
 +
<code>nano /home/user/.vnc/xstartup</code>
 +
 +
Include the following:
 +
 +
<pre>
 +
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
 +
</pre>
 +
 +
 +
== Firewall ==
 +
 +
=== Quick UFW rule list ===
 +
 +
# Set the default rule to deny everything <pre>ufw default deny</pre>
 +
# Allow in web traffic from "the world" to port 80 <pre>ufw allow 80</pre>
 +
# Allow ssh from a trusted network <pre>ufw allow from 192.168.0.0/24 to any port 22</pre>
 +
# Enable the rules we've just set <pre>ufw enable</pre>
 +
# Show the enabled rules <pre>ufw status</pre>
 +
 +
  
  

Revision as of 15:56, 16 September 2014


These are my notes for various Ubuntu tasks.

Packages

Package install status cloning

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 [1]

  1. dpkg -I FILE.deb
  2. apt-cache depends package_name


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 $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 -y $kernel; done


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 [2]
  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



References

  1. http://stackoverflow.com/questions/4627158/howto-list-all-dependencies-of-a-package-on-linux
  2. USER is a non-root account that the vncserver will be running as