Technical Notes

These notes are my personal online notebook of useful commands and "how-to's". You are welcome to make use of them if you find them helpful. They obviously don't come with any warranty! Click on one of the category tags above for the notes in any category.

Recover disk drive using ddrescue

See user manual here:…escue_manual.html

Example script:

  • /dev/sdc is the bad drive which is being recovered to /dev/sdb
# first pass to copy the good sectors and make a log file of the bad
ddrescue -n /dev/sdc /dev/sdb logfile
# second pass keeps retrying the bad sectors
ddrescue -dr3 /dev/sdc /dev/sdb logfile

# have a look at what we have and do some validation
fdisk /dev/sdb
e2fsck -v -f /dev/sdb1
e2fsck -v -f /dev/sdb2

iptables configuration on a linux server

  • List current tables with line numbers and stats
iptables -L INPUT --line-numbers -v
  • Append another rule
iptables -A INPUT -s -j DROP
  • Delete rule #3
iptables -D INPUT 3
  • The moment you apply IPTABLE rule it immediately becomes active.But it will not survive a reboot.
  • To be able to survive IPTABLES a reboot in your network configuration file /etc/network/interfaces file (referring to a Debian/Ubuntu system) you need to add:
pre-up  iptables-restore < firewall.txt

Making changes persistent in CentOS 5

iptables rules are stored in memory.

A simple way of restoring the content of deleted text files

Undeleting a file is not easy in Linux.
However, if it's a text file, and you know a phrase from it, you can search the whole drive for the contents:
grep -a -C 200 -F "words in file" /dev/hda1 | more #change /dev/hda1 to whatever is appropriate

Setting up NFS on Ubuntu 16.04

Make sure userid’s and groupid’s match between the systems

  • e.g. usermod -u 1001 -g 504 -c "Andrew Fountain" andrewf

Set up the server

  • set up the fully qualified domain name, e.g.

SMART monitoring of USB drives on Linux

using smartmontools documentation, try:

smartctl -d sat,16 -i /dev/sdc # find if enabled
smartctl -d sat,16 -a /dev/sdc # display all info

more documentation:

umount - device is busy

I you get “device is busy” when running umount, try

sudo lsof | grep /dev/xxxx
# or
sudo fuser -cu /dev/xxxx

Upgrading CentOS 6 to PHP 5.4 (or 5.5)

  • SCL is the way to go since it has RedHat’s blessing

Note that it is the .conf file that controls which version of php is used. For some reason this does not seem to be available for php55.

Creating a startup script

# Provides:          mystartup
# Required-Start:    $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Enable Wine 16bit support
# Description:       Fix recommended by Linus to enable Wine 16bit support
echo 1 > /proc/sys/abi/ldt16
  • Then activate with:
chmod +x /etc/init.d/
update-rc.d defaults 99

Setting up X2GO

Install on Ubuntu server

add-apt-repository ppa:x2go/stable
apt-get update
apt-get install x2goserver x2goserver-xsession
apt-get install python-software-properties
apt-get install x2godesktopsharing
  • For Ubuntu 14:10, edit /etc/apt/sources.list.d/x2go-stable-utopic.list and replace trusty with utopic
  • For Ubuntu 16:04 you will need to apply this fix:
export GSETTINGS_SCHEMA_DIR=/usr/share/mate:/usr/share/mate:/usr/local/
Syndicate content