Author Archives: Simon

Mount a Linux NFS Share on Windows 7

First you need to install the windows nfs client. Go to

Control PanelAll Control Panel ItemsPrograms and Features

Then click on Turn Windows features on or off then select NFS Services Client for NFS. After the installation start a dos box or power shell. And enter the following command to mount the share backup on server 192.168.1.1 and assign the drive letter k:

mount \\192.168.1.1\backup k:

Example: mount [options] \\nfs-server\unc-nameshare-name [drive letter]

Extracting a Database From a mysqldump File

Restoring a single database from a full dump is pretty easy, using the mysql command line client’s –one-database option:

mysql -u root -p --one-database db_to_restore < fulldump.sql

But what if you don’t want to restore the database, you just want to extract it out of the dump file? Well, that happens to be easy as well, thanks to the magic of sed:

sed -n '/^-- Current Database: `test`/,/^-- Current Database: `/p' fulldump.sql > test.sql

You just need to change “test” to be the name of the database you want extracted. Or you can use this shell script:

Download mysqldumpsplitter

Usage:

$>sh MyDumpSplitter.sh
Usage: sh MyDumpSplitter.sh DUMP-FILE-NAME — Extract all tables as a separate file from dump.
sh MyDumpSplitter.sh DUMP-FILE-NAME TABLE-NAME — Extract single table from dump.
sh MyDumpSplitter.sh DUMP-FILE-NAME -S TABLE-NAME-REGEXP – Extract tables from dump for specified regular expression.

Further instructions for using this script can be found here:

Mysql dump-shell script

MySQL Dump the table structure only no data

The only option that is different than creating an entire backup is the -d switch, which tells mysqldump not to output the data.

mysqldump -u root -pmypassword -d proftpd > /root/proftp.sql

This should leave you with the table structure without the data. To restore the DB do the following:

mysql -u root -pmypassword proftpd < proftpd.sql

For this to work the database proftpd must exist as an empty database.

Upgrading Debian Lenny to Squeeze

Upgrade to Debian Squeeze if you have some Linux experience this upgrade should be fairly straight forward. Please read everything and do not skip steps unless you know what you are doing. You may be left with a system that will not boot. Please also consult the official Debian upgrade guide if you run into any problems or conflicts:


Debian upgrade guide


Create a list of installed packages and check the list for deinstalled packages this is an optional step to make sure you have a clean system:

uninstall=$(dpkg --get-selections > /root/package.list.lenny ; cat /root/package.list.lenny | grep deinstall |awk {'print $'1}) ; aptitude purge $uninstall

Check for half installed packages:

dpkg --audit

Remove Backuports and APT Pinnings Check for non debian sources and change them to the squeeze repo if available

Replace lenny entries with squeeze replace volitile with squeeze-updates:

Also make sure to add non-free and contrib in case your server needs the firmware-linux-nonfree package. This is a example sources list for squeeze if you live in Germany:

############################################################
deb http://ftp.hosteurope.de/pub/linux/debian/ squeeze main contrib non-free
deb-src http://ftp.hosteurope.de/pub/linux/debian/ squeeze main contrib non-free

deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free

deb http://ftp.hosteurope.de/pub/linux/debian/ squeeze-updates main contrib non-free
deb-src http://ftp.hosteurope.de/pub/linux/debian/ squeeze-updates main contrib non-free
#############################################################

Update sources:

apt-get update

Check to see if you have sufficient disk space:

apt-get -o APT::Get::Trivial-Only=true dist-upgrade

Preform a minimal System Upgrade:

apt-get upgrade

Install the new kernel important otherwise your system may not boot because of the new udev version choose your kernel:

apt-get install linux-image-2.6-amd64

This would install the 64bit Debian Kernel

Check the Kernel Install:

dpkg -l "linux-image*" | grep ^ii

Upgrade udev:

apt-get install udev

If you see any firmware warnings make sure to install the firmware-linux-nonfree or the firmware-linux package before you reboot:

apt-get install firmware-linux-nonfree

or

apt-get install firmware-linux

Preform a system Upgrade or full upgrade:

apt-get dist-upgrade

Change init scripts to inssrv this is normally done automatically:

dpkg-reconfigure sysv-rc

Reboot the system

After first reboot Install Grub 2 to MBR:

upgrade-from-grub-legacy

rm -f /boot/grub/menu.lst*

Clean up and remove downloaded packages removing the downloaded packages is a optional step:

apt-get autoremove

rm -f /var/cache/apt/archives/*.deb

This step is also optional remove obsolete packages with deborphan helps to keep your system clean:

install deborphan:

apt-get install deborphan

Use deborphan to remove obsolete packages check the list first:

deborphan --guess-all

Then remove the obsolete packages:

deborphan --guess-all | xargs aptitude -y purge

Thats it you should have a clean system running Debian Squeeze

Manage HP Raid Controllers with hpacucli

This document is a quick cheat sheet on how to use the hpacucli utility to add, delete, identify and repair logical and physical disks on the HP Smart array controller. Some of these commands may need slight modifications. Please do not just copy and paste if you are not 100% sure what you are doing you may lose all of you data.


Utility Keyword abbreviations
Abbreviations chassisname = ch
controller = ctrl
logicaldrive = ld
physicaldrive = pd

drivewritecache = dwc

hpacucli utility
hpacucli # hpacucli

# hpacucli help

Note: you can use the hpacucli command in a script

Controller Commands
Display (detailed) hpacucli> ctrl all show config
hpacucli> ctrl all show config detail
Status hpacucli> ctrl all show status
Cache hpacucli> ctrl slot=0 modify dwc=disable
hpacucli> ctrl slot=0 modify dwc=enable
Rescan hpacucli> rescan

Note: detects newly added devices since the last rescan

Physical Drive Commands
Display (detailed) hpacucli> ctrl slot=0 pd all show
hpacucli> ctrl slot=0 pd 2:3 show detail

Note: you can obtain the slot number by displaying the controller configuration (see above)

Status

hpacucli> ctrl slot=0 pd all show status

hpacucli> ctrl slot=0 pd 2:3 show status

Erase hpacucli> ctrl slot=0 pd 2:3 modify erase
Blink disk LED hpacucli> ctrl slot=0 pd 2:3 modify led=on

hpacucli> ctrl slot=0 pd 2:3 modify led=off

Logical Drive Commands
Display (detailed) hpacucli> ctrl slot=0 ld all show [detail]
hpacucli> ctrl slot=0 ld 4 show [detail]
Status hpacucli> ctrl slot=0 ld all show status
hpacucli> ctrl slot=0 ld 4 show status
Blink disk LED hpacucli> ctrl slot=0 ld 4 modify led=on
hpacucli> ctrl slot=0 ld 4 modify led=off
re-enabling failed drive hpacucli> ctrl slot=0 ld 4 modify reenable forced
Create # logical drive – one disk
hpacucli> ctrl slot=0 create type=ld drives=1:12 raid=0

# logical drive – mirrored
hpacucli> ctrl slot=0 create type=ld drives=1:13,1:14 size=300 raid=1

# logical drive – raid 5
hpacucli> ctrl slot=0 create type=ld drives=1:13,1:14,1:15,1:16,1:17 raid=5

Note:

drives – specific drives, all drives or unassigned drives
size – size of the logical drive in MB
raid – type of raid 0, 1 , 1+0 and 5

Remove hpacucli> ctrl slot=0 ld 4 delete
Expanding hpacucli> ctrl slot=0 ld 4 add drives=2:3
Extending hpacucli> ctrl slot=0 ld 4 modify size=500 forced
Spare hpacucli> ctrl slot=0 array all add spares=1:5,1:7


Ubuntu / Debian Linux Regenerate SSH Host Keys

If you need to regenerate your SSH Host Keys do the following.

1. delete your old keys

rm /etc/ssh/ssh_host_*

2. reconfigure the ssh server

dpkg-reconfigure openssh-server

That’s it now you can update you known_hosts file when you connect next time. If you use strict checking which you should you will need to delete the key from you known_hosts file in you home directory. Or you will not be able to connect.

Openssl Create a Private Key and a CSR with 2048bit for an SSL Certificate

If you need a new SSL certificate for a server you will need a 2048bit private key from 2011 onwards. This command creates both:

openssl req -new -nodes -newkey rsa:2048 -keyout example.key -out example.csr

Thats it send the CSR to you ISP and you should get you SSL cert back. You can also edit:

/etc/ssl/openssl.cnf

And change the default_bits line to 2048 then all new keys we be created with 2048bits.