Monday, September 3, 2012

Disable ipv6 on Ubuntu LTS (12.04)

add the following lines to /etc/sysctl.conf

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

… and reboot.
Or simply reload the settings:

sysctl -p

2019 update:
sysctl.conf still works, but it won’t be processed during boot.
Therefor recent Ubuntu’s need an extra grub parameter ipv6.disable=1. Like so:

GRUB_CMDLINE_LINUX_DEFAULT="splash quiet ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

Monday, August 13, 2012

Ubuntu 12.04 LTS and HP ProLiantSupportPack

Quick reference:

  • wget http://downloads.linux.hp.com/SDR/downloads/bootstrap.sh
  • chmod +x bootstrap.sh
  • ./bootstrap.sh -v -r stable ProLiantSupportPack
  • wget http://downloads.linux.hp.com/SDR/downloads/ProLiantSupportPack/GPG-KEY-ProLiantSupportPack
  • apt-key add GPG-KEY-ProLiantSupportPack
  • apt-get update
  • apt-get install hpacucli

Too bad the hp software doesn’t support 3.x kernels, so you need to fool it a little.

setarch i686 --uname-2.6 hpacucli controller all show config

Monday, December 12, 2011

Migrate inbox and sent items from old mailserver to google apps using imapsync

In my case i’m migrating from a Kerio Mailserver that is presenting all the folders as a subfolder of inbox, hence the

--sep1 . --prefix1 inbox

Always start the commands with the “–dry” option to do a dry-run (test-run) first!

To migrate the inbox and all subfolders:

imapsync --syncinternaldates --useheader 'Message-Id' --buffersize 8192000 --nosyncacls --host1 oldhost.domain.com --user1 [email protected] --passfile1 passfile1.txt --ssl1 --host2 imap.gmail.com --user2 [email protected] --passfile2 passfile2.txt --ssl2 --authmech2 LOGIN --sep1 . --sep2 . --prefix1 inbox --folderrec INBOX

Sent items need a little bit of translation. “Sent Items” will be translated to “[Gmail]\Verzonden berichten” (Dutch language).

imapsync --syncinternaldates --useheader 'Message-Id' --buffersize 8192000 --nosyncacls --host1 oldhost.domain.com --user1 [email protected] --passfile1 passfile1.txt --ssl1 --host2 imap.gmail.com --user2 [email protected] --passfile2 passfile2.txt --ssl2 --authmech2 LOGIN --sep1 . --prefix1 inbox --folder "Sent Items" --regextrans2 's/Sent Items/\[Gmail\]\/Verzonden berichten/'

Thursday, July 14, 2011

rsync with ssh on a different port (and sudo)

If you want to rsync data from/to a remote server with ssh, you could do something like this:

rsync -av [email protected]:/backup/* /storage/monday/

But what if ssh listens on port 2222?

rsync -av --rsh='ssh -p2222' [email protected]:/backup/* /storage/monday/

But what if you need sudo permissions?
Server-side configuration (/etc/sudoers)

#sudo access for myusername running rsync backup
myusername ALL=NOPASSWD:/usr/bin/rsync

Client-side:

rsync -av --rsh='ssh -p2222' --rsync-path="sudo rsync" [email protected]:/backup/* /storage/monday/ .

And in case you want to include multiple directories:

rsync -av --rsh='ssh -p2222' --rsync-path="sudo rsync" [email protected]:{/backup,/root,/etc} /storage/monday/

Wednesday, March 16, 2011

dmesg timestamps

To translate the timestamps in your dmesg into human readable timestamps, use the following perl script:

#!/usr/bin/perl

$uptime = `cat /proc/uptime | awk '{print $1}';`;
$boot = time() - $uptime;
chomp $boot;
while (<STDIN>) {
        if ($_ =~ /^\[([\s\d\.]+)\]/) {
                $time_offset = $1;
        }
        $real_time = sprintf scalar localtime($boot + $time_offset);
        $_ =~ s/\[[\s\d\.]+\]/\[$real_time\]/;
        print $_;
}

e.g.

[    9.815650] 3w-9xxx: scsi2: ERROR: (0x03:0x0101): Invalid command opcode:opcode=0x85.

will be translated into

[Wed Mar 16 16:02:32 2011] 3w-9xxx: scsi2: ERROR: (0x03:0x0101): Invalid command opcode:opcode=0x85.

Syntax:

dmesg | perl /root/print_time_offset.pl

Tuesday, November 9, 2010

rescan scsi bus without rebooting

If you attach an extra harddisk to your virtual machine and you don’t want to reboot, all you need to do is rescan your scsi bus.

First determine how many scsi adapters your system has:

# ls /sys/class/scsi_host
host0

Then order the rescan command to the adapter:

# echo "- - -" > /sys/class/scsi_host/host0/scan

Check your dmesg or /proc/partitions!

Monday, November 8, 2010

find LVM volumes

I needed to make a backup of an old server. So i booted an Ubuntu live cd. Then:

cat /proc/partitions

But I wasn’t able to mount certain partitions. It appeared to be lvm volumes.
To mount them, you’ll need the lvm2 package first.

sudo -s
apt-get update
apt-get install lvm2

Then find the volumes.

vgchange -a y
  3 logical volume(s) in volume group "VolGroup00" now active

Now look in your device mapper:

ls /dev/mapper/

.. and do whatever you like with it. In my case:

mkdir /mnt/vol00
mkdir /mnt/vol01
mkdir /mnt/vol02
mount /dev/mapper/VolGroup00-LogVol00 /mnt/vol00
mount /dev/mapper/VolGroup00-LogVol01 /mnt/vol01
  /dev/mapper/VolGroup00-LogVol01 looks like swapspace - not mounted
root@ubuntu:~# mount /dev/mapper/VolGroup00-LogVol02 /mnt/vol02

apt-get install smbfs
mkdir /mnt/targetserver/
smbmount //10.2.18.224/software /mnt/targetserver/
mkdir /mnt/targetserver/serverbackup/

cd /mnt
rsync -av vol00 vol02 /mnt/targetserver/

Friday, February 5, 2010

Clone your linux boot partition

Where as Windows has many many cloning tools (e.g. Ghost), for linux cloning isn’t quite common.

Yesterday i needed to migrate an installation to another server. First make sure that you compile all the things you need in your current kernel.
With a Iinux live cd I created a backup of my boot partition (/dev/sda1) to a file on a usb disk (mounted as /backup)

dd if=/dev/sda1 of=/backup/sda1.dd

Then i wanted to restore it to another machine with a different partition size.
Here’s how:

  • partition your new harddisk
  • create an ext3 filesystem on your new boot partition
  • mount your usb disk as /backup
  • mount the backup file as /backupsda1
    mount -o loop -t ext3 /backup/sda1.dd /backupsda1
  • mount the newly created boot partition as /mnt
    mount /dev/sda1 /mnt
  • copy all files to the new partition
    cd /backupsda1
    rsync -av * /mnt/
  • mount proc and dev to your new partition
    mount -t proc none /mnt/proc
    mount -o bind /dev /mnt/dev
  • chroot to your new installation
    chroot /mnt
  • reinstall the bootloader (grub)
    grub-install /dev/sda

That’s it!

edit:
if your previous installation has an older version of grub, you might need to create your filesystem with a smaller inode size, otherwise grub won’t function correctly:

mkfs.ext3 -I 128 /dev/sda1

Sunday, June 7, 2009

prevent usb disk from going into standby mode

This week i was copying large amounts of data to a Maxtor USB disk using the midnight commander. While the midnight commander was gathering information about the amounts of data to be processed (taking at least 20 minutes or more), the usb disk was going into standby mode.
By the time it was ready and wanted to start copying data, i got all kinds of i/o errors on /dev/sdb (the usb disk).
So i did a filesystem check on the usb disk and started over again. The same happened.

Then it occured to me: the usb disk was going to standby mode. It will come back alive whenever the OS wants to read or write data, but it takes too long resulting in i/o errors.

This command prevents the disk from going to standby mode:

sdparm --clear STANDBY -6 /dev/sdb 

edit:
Today i played around with some usb disks that don’t support the command above, so i had to dig further.
Seems like i missed this option in my (custom compiled) kernel: ” [*] USB selective suspend/resume and wakeup “. This is actually the real fix.

Saturday, June 6, 2009

portforwarding on linux router

When using linux as a router you also might want to forwards some ports.

This should do the trick (it will when using my script from the other post):

iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 80 -j DNAT --to 192.168.1.50:80
iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth1 -j ACCEPT

But more generally it might be necessary to add an extra line first to allow traffic to your nic connected to the internet at all:

iptables -A FORWARD -i eth1 -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 80 -j DNAT --to 192.168.1.50:80
iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i eth1 -j ACCEPT

linux as router

Back in the days in our student house we used an old pentium II machine to share our internet access. Hardware routers were much more expensive those days.

A simple script to make a NAT router (replace INTERNET= and LOCALNET= if you have other devices).
Place the script in /etc/network/if-up.d/ (at least with debian) and call it natrouter.sh. Make sure you chmod +x natrouter.sh.

#!/bin/sh

INTERNET=eth0
LOCALNET=eth1

PATH=/usr/sbin:/sbin:/bin:/usr/bin

# delete all existing rules
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

# Always accept traffic on individual interfaces
iptables -A INPUT -i lo,$INTERNET,$LOCALNET -j ACCEPT

# Allow established connections back to the LAN
iptables -A FORWARD -i $INTERNET -o $LOCALNET -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow outgoing connections from the LAN to INTERNET
iptables -A FORWARD -i $LOCALNET -o $INTERNET -j ACCEPT

# Masquerade
iptables -t nat -A POSTROUTING -o $INTERNET -j MASQUERADE

# Don't forward from the outside to the inside
iptables -A FORWARD -i $INTERNET -o $LOCALNET -j REJECT

# Enable routing
echo 1 > /proc/sys/net/ipv4/ip_forward