Posts List

virsh-sliver: A simple tool for creating slivers of virtual machines on Fedora

Basic script to create qcow2 backed kvm domains based on a golden domain. Your golden domain must be using qcow2 To install the dependencies on fedora 19 run the following: yum install libvirt-client qemu-img libguestfs-tools xmlstarlet libxml2 The virt-sysprep tool can do much more than this and I could potentially set the hostname and configure the machine to run some scripts when it starts up to check in with puppet which I may do in the future.

Easy OpenSSH VPN using tunneling

This is a simple VPN for those times when you want the ease of use of a VPN but only have a ssh server available. Both servers need to have ssh configured to allow tunnels. You need to change the configs for ssh under /etc/ssh Remote server sshd_config: PermitTunnel yes Local server ssh_config: Tunnel yes Remote server Setting up the tunnels requires you to use root when sshing. Since I don’t open my servers up to remote root logins I work around it by first creating a reverse tunnel from the remote server back to my home machine. You will need to forward your external ssh port on your broadband router to the ssh on your local machine. Then create the reverse tunnel like this.

Installing stock CentOS kernel on an OVH or Kimsufi server

I recently signed up for a small dedicated server at Kimsufi.co.uk for the grand price of £14 a month which I think is pretty good price for what you get. Brand Intel Model Celeron / Atom Frequency 1.20+ GHz Architecture 64 bits NIC FastEthernet Memory 2 GB Hard disk 1 TB FTP Backup 100 GB Bandwidth Heaps more than I need :-) The machine itself is nothing special but they do have remote management and you can install a variety of Linux and Windows operating systems. I am quite happy with their service and management tools but I wasn't happy with the fact that they run their own custom kernels on them. The kernel that they install is a 'grsec' hardened 3.2 kernel but this caused a variety of issues when doing 'yum update', mainly dependency issues. I Googled around and found a few different solutions on remotely installing CentOS which were all basically variations on the way I describe in a previous post using [grub to re-install](http://www.thegoldfish.org/2009/12/reinstall-centos-using-grub/). Whatever I tried with this including [using VNC](http://forum.ovh.co.uk/showthread.php?t=4991) and attempting a fully automated install with a tested kickstart file it would become unresponsive when rebooting into the OS the first time. Instead of all these methods I should have been thinking inside the box instead of outside it :-(

Set txqueuelen on virtual vnetX devices with libvirt

The txqueuelen is a value in the kernel on network interfaces that sets the transmit queue length. This value can be tuned for different work loads. In the case of modern networking the defaults can sometimes be changed to get better line speeds over ethernet. Most people will do this using a rc.local command to set it on the physical ethX devices like this. vim /etc/rc.local Add the following /sbin/ip link set eth0 txqueuelen 2500 This is a perfectly reasonable way of doing it but what happens when network interfaces appear after boot and the name is unknown before hand? This is exactly what happens with Libvirt vnetX interfaces. Ideally we would be able to get Libvirt to tune these interfaces when it creates them, but that level of control is yet to be implemented BZ#809172. Libvirt >= 0.8.0 has some hooks which enable you to run commands at specific times in the lifecycle of a guest which may be good for this but on RHEL 5 Libvirt is version 0.6.0 so I needed a different solution.

Reverting to a previous snapshot using Linux LVM

Reverting to a previous snapshot has been possible for over a year!!!!! How did I miss that ?? This has for a long time been one of my only real criticisms of LVM and I just discovered that it was quietly committed into the kernel back in 2.6.33 The command used to do the revert is contained within lvconvert. From the lvconvert man page: --merge Merges a snapshot into its origin volume. To check if your ker‐ nel supports this feature, look for 'snapshot-merge' in the out‐ put of 'dmsetup targets'. If both the origin and snapshot vol‐ ume are not open the merge will start immediately. Otherwise, the merge will start the first time either the origin or snap‐ shot are activated and both are closed. Merging a snapshot into an origin that cannot be closed, for example a root filesystem, is deferred until the next time the origin volume is activated. When merging starts, the resulting logical volume will have the origin's name, minor number and UUID. While the merge is in progress, reads or writes to the origin appear as they were directed to the snapshot being merged. When the merge finishes, the merged snapshot is removed. Multiple snapshots may be spec‐ ified on the commandline or a @tag may be used to specify multi‐ ple snapshots be merged to their respective origin. A quick check using the command ‘dmsetup targets’ shows that it is definitely in my kernel so I thought I would give it a quick run through and test it a lot. I created a testing logical volume and then put some data on it, took a snapshot, changed the data and then reverted to the snapshot. Here is what I did.

Turn off the Caps-Lock key

I HATE THE CAPS_LOCK KEY!!!! I don’t like it when people send me messages with full caps and I don’t like accidentally pressing it and then sending messages to other people who then think I am yelling at them. It also wastes too much keyboard space and is in an easy place to accidentally hit. Time to get rid of it. The following method is for Fedora 15 but will probably work on other Gnome 3 systems.

Linux network bond without restarting the network

This is quite handy to know if you need to create a new network bond on a live system without disrupting traffic. First of all create your bond configs in the normal way so that in the event of a reboot it will come back up working. See the Redhat documentation for how to do it in RHEL6. Now because we cannot just restart the networking to bring that up we need to construct it by hand. Let’s say our 2 interfaces we wish to bond are eth3 and eth4 and the bond we are going to create is bond1

Checking SSL certificate expiry dates

This is just a quick note to save this useful bit of information. I may make it into a script one day or use it in something else. echo ''|openssl s_client -connect localhost:636 2>/dev/null | openssl x509 -noout -enddate | sed 's/^not.*\=//'

Unprivileged standalone instance of MySQL

Small script to run an instance of mysql in my home directory using the binary provided by the OS. Maybe some day I will make it more usable but for the time being it suits my needs. #!/bin/bash MYSQL_HOME=$HOME MYSQL_USER=$USER MYSQL_PORT=13306 ACTION=$1 if [ $ACTION == 'init' ]; then echo "initialising new mysql installation at $MYSQL_HOME/var/lib/mysql" rm -rf $MYSQL_HOME/var/lib/mysql mkdir -p $MYSQL_HOME/var/lib/mysql $MYSQL_HOME/mysql/data $HOME/var/lib/mysql/tmp mysql_install_db --user=$MYSQL_USER --datadir=$MYSQL_HOME/var/lib/mysql/data/ cat < $HOME/.my.cnf [mysqld] user=$MYSQL_USER datadir=$MYSQL_HOME/var/lib/mysql/data log-error=mysqld.log pid-file=mysqld.pid socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock port=$MYSQL_PORT [client] user=$MYSQL_USER socket=$MYSQL_HOME/var/lib/mysql/tmp/mysql.sock port=$MYSQL_PORT [safe_mysqld] log-error=mysqld.log pid-file=mysqld.pid port=$MYSQL_PORT EOT echo " Done" elif [ $ACTION == 'start' ];then echo -n "Starting mysqld as $MYSQL_USER on $MYSQL_PORT" nohup mysqld_safe &>/dev/null & echo " Done" elif [ $ACTION == 'stop' ];then PID=$(cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid) echo -n "Stopping mysql instance [$PID]" kill `cat $MYSQL_HOME/var/lib/mysql/data/mysqld.pid` echo " Done" else echo "Unknown command '$1'" fi UPDATED SCRIPT:

Parallel multi process bash with return codes

Have you ever needed to run a bunch of long running processes from a bash script and get their return codes ? I come across this issue quite frequently in my line of work. The most common one is where I need to run rsync to collect files from many machines then if successful run some other task. Depending on the number of servers and data this can take several hours to run sequentially and I don’t really like waiting around to check the output so that I can run the next task.