25 Dec 2009

Fiddling with bridges for kvm on ubuntu (9.04)

For most virtualization technologies, bridged network interfaces are usefull if a host has to be accessible from outside (ssh for example). Bridging makes this possible.

Install bridge-utils

Disable your primary network interface, create a bridge and link the bridge to the original interface:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
#    address 10.0.0.33
#    network 10.0.0.0
#    netmask 255.255.255.0
#    gateway 10.0.0.1

#auto eth1
iface eth1 inet dhcp

auto vnet0
iface vnet0 inet static
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
address 10.0.0.33
network 10.0.0.0
netmask 255.255.255.0
gateway 10.0.0.1

22 Dec 2009

ssh keyboard-interactive with no subsequent questions

Some scripts which bootstrap clients into my network need to do many subsequent ssh requests to servers to determine its state and change server values (dns, dhcp, accounts, etc). It can be cumbersome to enter the admin's ssh password again and again, sshpass to the rescue (bash example):

#!/bin/bash
# ask for root password, use it for any further ssh connection
remoteuser='adm' # could be root|admin|sysadmin|etc.
stty -echo
read -p 'Password for '$remoteuser': ' pw
echo
stty echo
export SSHPASS="$pw" # export, so subcommands can use it
unset pw
alias ssh='sshpass -e ssh'

ssh $remoteuser@someserver  'ls -la /tmp' # no password asked if it matches
ssh $remoteuser@otherserver 'ls -la /tmp' # no password asked if it matches

When the script ends the variable «$SSHPASS» will be destroyed. It makes sense to have user and passwords stored locally (ie. ldap/kerberos/nis/etc.).

6 Dec 2009

Dealing with UUIDs in fstab

Since there are more and more removable block devices in use (Memmory Sticks, External HDs, etc.) it makes sense to mount them via UUID, since the device name may vary.

Two tools have been very useful for finding out the UUIDs for a partition:

$ blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: UUID="D8A03377A0335B68" LABEL="HP_PAVILION" TYPE="ntfs"
/dev/sda3: UUID="4562-2B6E" TYPE="vfat"
/dev/sda4: LABEL="HP_RECOVERY" UUID="4B6E-6BC0" TYPE="vfat"
/dev/sda5: UUID="2e551b01-6f76-4d8e-85cd-7adc6abc9a2d" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda6: UUID="6cb7b571-be94-4882-a504-fddf8fa1388a" TYPE="swap"
/dev/sda7: UUID="402b3442-1432-4676-ab6f-6cb3c403a4f2" TYPE="ext3"
/dev/sda8: UUID="8501e0d1-55b5-4899-8553-37129213d803" TYPE="ext3"
/dev/sdb1: UUID="7868C17F68C13D1E" LABEL="Volume" TYPE="ntfs"
/dev/sdb2: UUID="e1454921-55a4-42af-9484-e6a82eb33329" SEC_TYPE="ext2" TYPE="ext3"
$ sudo vol_id /dev/sda3
ID_FS_USAGE=filesystem
ID_FS_TYPE=vfat
ID_FS_VERSION=FAT32
ID_FS_UUID=4562-2B6E
ID_FS_UUID_ENC=4562-2B6E
ID_FS_LABEL=
ID_FS_LABEL_ENC=

An easy readable list of device names and UUIDs:
$ blkid -s device -s UUID | sed -e 's|:||; s|UUID="||; s|"||'
/dev/sda1 D8A03377A0335B68
/dev/sda3 4562-2B6E
/dev/sda4 4B6E-6BC0
/dev/sda5 2e551b01-6f76-4d8e-85cd-7adc6abc9a2d
/dev/sda6 6cb7b571-be94-4882-a504-fddf8fa1388a
/dev/sda7 402b3442-1432-4676-ab6f-6cb3c403a4f2
/dev/sda8 8501e0d1-55b5-4899-8553-37129213d803
/dev/sdb1 7868C17F68C13D1E
/dev/sdb2 e1454921-55a4-42af-9484-e6a82eb33329