2013/12/06

Grow root partition and filesystem in Ubuntu and Linux Mint

Here are the steps to grow the root filesystem on an existing system that does NOT use LVM:
  1. First, use LVM; it makes resizing filesystems nearly trivial, robust, without any real downsides.  Just another way that Ubuntu is not enterprise-worthy.  But, we don’t have LVM on these systems’s as they are….
  2. Second, before doing any operations on your partitions, always perform and test a backup (to a separate system!) of your data. You may make your system unbootable and/or nuke all of your data!
  3. The system I performed these steps on was partitioned thus:
    1. /dev/sda – 7GB – /
    2. /dev/sda2 – remainder – Extended partition
    3. /dev/sda5 – swap – partition within the extended partition.
  4. So, to grow “/”, we will become root, delete the swap partition and the extended partition, grow /, and then re-create the swap partition.  Adjust the steps below according to the partition numbers and layout of your particular system:
    1. Disable swap:
      1. swapoff /dev/sda5
    2. Delete and re-create partitions as appropriate.
      1. fdisk /dev/sda
      2. print out partition information (p)
      3. Delete partition 5 (d – 5)
      4. Delete partition 2 (d – 2)
      5. Delete partition 1 (d)
      6. Create partition 1 (n – p – 1)
        1. It must start on the exact same sector as before (as seen in the print command)
        2. It must end on a sector higher than it did before.  Num_GB*1024*1024*2 = ending sector
      7. Create partition 2 (n – p – 2)
      8. Change partition 2 to type “Linux Swap” (t – 2 – 82 )
      9. Activate partition 1 to make it bootable (a - 1)
      10. Double-check everything.
      11. Exit (w)
    3. recreate the swap partition, using a label:
      1. mkswap -L swap /dev/sda2
    4. add a label to the root filesystem
      1. e2label /dev/sda1  /   (in centos, it’s e4label)
    5. Fix up /etc/fstab
      1. Fix the “swap” line to use LABEL=swap instead of UUID=
      2. Fix the “/” line to use LABEL=/ instead of UUID=
    6. swapon /dev/sda2
    7. Fix up /boot/grub/grub.cfg
      1. Either: Find the “linux” line for the menu option you will boot, change UUID= to LABEL=/
      2. Or: update-grub
    8. Re-create the initrd
      1. update-initramfs -u -k 3.2.0-38-generic
    9. Reboot the VM. *Cross your fingers!* This is your moment of truth.
    10. Grow the root filesystem
      1. resize2fs /dev/sda1  (resize4fs on CentOS, I believe).
    11. If it didn't boot, then that's what you get for biting off more than you could chew, and for choosing a distro that doesn't leverage LVM.  Boot off your Ubuntu/Mint install disk, and copy off your data to a USB disk, and start over. (...but you DID back up your data anyway, right?)

2013/11/15

Automatically delete old NetApp snapshots left by backups

Backup software may sometimes leave behind a snapshot.  This can increase the space consumption a lot over time.

Here's a script that can be run against NetApp filers to clean up those "stale" backups.  Note that in my case, I configured CommVault to name the snapshots with the string "snapshot_for_backup", though the default is just "ndmp".  You may change that as needed.




#!/bin/bash

# This script is to look for snaps that are left over from backups, that # are no longer in use, and delete them.
# This script requires two parameters:
# snap_cleanup     (list or delete all stale snaps on the specified servers)

NasUser="root"
SnapshotString="snapshot_for_backup"
SshIdentityFile="/root/.ssh/id_rsa_auslxfs00_rsync"
SshBinary=/usr/bin/ssh


# This function receives a volume name as a parameter, and returns # the number of snaps that are elligible for deletion, defined by being:
#                             1. Having a certain string in the snapshot name;
#                             2. Not marked as "busy"
function CountStaleSnaps ()
{
                local VolToCheck=$1
                local StaleSnaps=`$SshCmd "snap list $VolToCheck" | grep $SnapshotString | grep -v "busy" | wc -l`
                if [ $? -ne 0 ]; then
                {
                                echo "getting count of elligible snapshots returned an error"
                                exit 1
                } else
                {
                                echo $StaleSnaps
                } fi
}

# Function GetStaleSnapNames
# This function creates, given a volume name, an array of snapshots that are # candidates for deletion.
# Parameters
#             1. volume to check
function GetStaleSnapNames ()
{
                local Volume=$1
                StaleSnapNames=( $($SshCmd "snap list $Volume" | grep $SnapshotString| grep -v busy | cut -c 39- | cut -f 1 -d " ") )
                if [ $? -ne 0 ]; then
                {
                                echo "getting names of elligible snapshots returned an error"
                                exit 1
                } else
                {
                                printf -- '%s\n' "${StaleSnapNames[@]}"
                } fi
}

# Function DelStaleSnaps
# This function deletes stale snaps for the Volume name passed to it.
# Parameters
#  1. volume
#  2. snapshot_name
function DelStaleSnaps ()
{
                local Volume=$1
                local SnapToDelete=$2
                $SshCmd "snap delete $Volume $SnapToDelete"
                if [ $? -ne 0 ]; then
                {
                                echo "error deleting snapshot $Volume:$SnapToDelete"
                                exit 1
                } else
                {
                                echo "successfully deleted snapshot $Volume:$SnapToDelete"
                } fi
}

# Parse command line parameters
case $2 in
                "")
                                echo "ERROR: you must specify as a second parameter a host name on which you want to delete snapshots."
                                ;;
                *)
                                NasName=$2
                                ;;
esac
case $1 in
                list)
                                Operation=list
                                ;;
                delete)
                                Operation=delete
                                ;;
                *)
                                echo "ERROR: invalid operation specified on command line.  Please specify either 'list' or 'delete' followed by the servername on which you want to delete the snapshots."
                                exit 1
                                ;;
esac

SshCmd="/usr/bin/ssh -i $SshIdentityFile $NasUser@$NasName"

VolumesToCheck=( `$SshCmd "vol status -b" | cut -f 1 -d " " | egrep -v "Volume|-----"` )

for CurrentVol in ${VolumesToCheck[@]}; do {
                echo -n "checking $NasName:$CurrentVol... "
                StaleSnaps=`CountStaleSnaps $CurrentVol`
                echo $StaleSnaps            
                if [ $Operation = list ]; then
                                if [ $StaleSnaps -ne 0 ]; then
                                                GetStaleSnapNames $CurrentVol |  awk '{ print "    " $1 }'
                                fi
                elif [ $Operation = delete ]; then
                                GetStaleSnapNames $CurrentVol
                                ArrayOfSnaps=( $(GetStaleSnapNames $CurrentVol) )
                                for TargetSnap in `printf -- '%s\n' "${ArrayOfSnaps[@]}"`; do
                                                                DelStaleSnaps $CurrentVol $TargetSnap
                                done
                fi
                               
}; done


2013/07/10

Linux bash shell options parsing


Normally, command line parameters come in as separate, positional values, and may be referenced as:
  • $# - the number of command line arguments (positional parameters)
  • $* - all positional parameters expressed as a single string
  • $@ - all positional parameters, but with each as a quoted string (each positional parameter is intact and presented as a quoted string)
  • $0 - (the base name of the script itself)
  • $1 - The first positional parameter
  • $2 - The second positional parameter, and $3, $4, etc.  Starting with 10, they must be expressed as ${10}, ${11}, etc.
Sometimes a variable is passed from a wrapper script to a child script where the positional parameter is in fact several parameters that should be parsed separately.

Here, we test for that case, and if found, we peel off the first parameter within that group of strings, and assign the remaining parameters in the group of springs:

# from the front, and make the rest of the data be the options passed to rsync.
if [ $# -eq 1 ]; then
{
   Params=($1)
   PARAM_1=${Params[0]}
   unset Params[0]
   ChildCommandOpts=${Params[*]}
} fi


2013/07/02

Manipulate windows firewall from CLI

The windows firewall UI is a bit cumbersome.  This method will let you set up a host reliably to be secure, and to allow only inbound traffic that you want.

Enable firewall in all profiles (home / domain / public)
netsh advfirewall set allprofiles state on

By default, deny all inbound and allow all outbound traffic
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound

Add rule to allow SMTP traffic inbound to a specific port from a specific network range
netsh advfirewall firewall add rule name="Allow Inbound TCP/25 from SMTP relay hosts" protocol=TCP dir=in localport=25 action=allow remoteip=10.20.30.0/24


Add rule to allow all HTTP and HTTPS traffic inbound
netsh advfirewall firewall add rule name="Allow Inbound TCP/80 from everywhere" protocol=TCP dir=in localport=80 action=allow

2013/04/08

Upgraded ESXi host has errors, won't permit some operations

I have some ESXi hosts that were 4.x, then upgraded to 5, then 5.1 .  As of today, they have errors that complain about the HA agent being broken.  They also won't let me enable/disable the SSH service nor modify the firewall configuration.

The error for the SSH service starts with 'Call "HostFirewallSystem.DisableRuleset" for object' .

These two articles provide the answers. After following the first step, I no longer get the error about SSH and firewall.

After following the second article, my HA agent is no longer complaining.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2037544

http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&docTypeID=DT_KB_1_1&externalId=1003490

Boiling the steps down, I have
  1. Fix SSH and firewall
    1. enable ssh on the host (if not already enabled); this is under host --> configuration --> security profile
    2. ssh to the host
    3. cd /etc/vmware/service
    4. cp services.xml service.xml.bak
    5. vi services.xml (remove the line with "sshServer")
    6. esxcli network firewall refresh
    7. disable ssh on the host (but don't close your connection if you're going to continue with the next process)
  2. Restart the ESXi host agents
    1. On the host, run this command: /sbin/services.sh restart
    2. this step takes a few minutes to complete.

2013/03/15

SNMP OIDs for temperature monitoring

...This is for anyone looking for these things in one place, with the scale and units. ( extracted from http://wleibzon.bol.ucla.edu/nagios/plugins/check_snmp_temperature.pl )
  • Dell (10C)
    • 1.3.6.1.4.1.674.10892.1.700.20.1.8
    • 1.3.6.1.4.1.674.10892.1.700.20.1.6
  • Cisco (C)
    • 1.3.6.1.4.1.9.9.13.1.3.1.2
    • 1.3.6.1.4.1.9.9.13.1.3.1.3
    • fans: 1.3.6.1.4.1.9.9.13.1.4.1.3
  •  juniper (C)
    • 1.3.6.1.4.1.2636.3.1.13.1.5
    • 1.3.6.1.4.1.2636.3.1.13.1.7
  • HP (C)
    • 1.3.6.1.4.1.232.6.2.6.8.1.3
    • 1.3.6.1.4.1.232.6.2.6.8.1.4
  • alteon (C)
    • Rear Left Sensor - 1.3.6.1.4.1.1872.2.1.1.6.0
    • Rear Middle Sensor - 1.3.6.1.4.1.1872.2.1.1.7.0
    • Front Middle Sensor - 1.3.6.1.4.1.1872.2.1.1.8.0
    • Front Right Sensor - 1.3.6.1.4.1.1872.2.1.1.9.0
  • baytech PDU (10C)
    • 1.3.6.1.4.1.4779.1.3.5.2.1.2
    • 1.3.6.1.4.1.4779.1.3.5.2.1.8
  • Linux lmsensors (1000C)
    • 1.3.6.1.4.1.2021.13.16.2.1.2
    • 1.3.6.1.4.1.2021.13.16.2.1.3
  • APC temperature
    • 1.3.6.1.4.1.318.1.1.2.1.1.0
  • APC humidity 
    • 1.3.6.1.4.1.318.1.1.2.1.2.0
  • HP switch
    • temperature: 1.3.6.1.4.1.11.2.14.11.1.2.6.1.4.4
    • fan: 1.3.6.1.4.1.11.2.14.11.1.2.6

2013/02/07

Tweaks for Linux Mint

These were started with Linux Mint 14.1 Cinnamon

Menu bar shows up on the wrong screen:

Do this to find out the name of the displays:
sudo xrand -q
Do this to make the menu show up on one display or the other, for example:
sudo xrand --output VGA1 --primary

Sound doesn't come out through the correct device (speaker, headphone, etc.):

run these:
sudo apt-get install alsa-base alsa-utils pavucontrol pavumeter paman
alsamixer
...then in alsamixer, select the desired output "card", then ensure that "automute" is set to disabled or some other device.


I want to watch Netflix on Mint:

Run these commands:
sudo apt-add-repository ppa:ehoover/compholio
sudo apt-get install netflix-desktop


Display locks up with my NVidia card:

During install, select "compatibility mode".

After install, before logging in, select session type "Cinnamon 2D", then
sudo apt-get install nvidia-current nvidia-settings
sudo reboot