Monday, 25 October 2010

Enable Directory Listing in Apache2

You need to add a line to your "site" file. For the default site you would do this;

vi /etc/apache2/sites-enabled/000-default

Add this line inside the main VirtualHost *:80 section;

Options Includes ExecCGI

Restart apache and you are done!

Friday, 15 October 2010

rsync on a non standard port

If you have a machine with an ssh server that listens on a port other than the default 22 then you need to modify the way you would normally invoke the rsync command.

rsync -parv --inplace -e "ssh -p 2222" $source $dest

Thursday, 14 October 2010

HOWTO: Syncing your /home with a server

Do you have a storage server where you keep your files? Do you think it would be a neat idea to keep a copy of your user files (home directory) on that storage in case your laptop or desktop suffers some sort of a catastrophe? Would you like an approximation of Windows roaming profiles?

If you answered yes to any of the above then read on! (However you should read the disclaimer at the end of this post.)

PLATFORM :
* Ubuntu (Tested with 10.04.1 Lucid but should work with any version)

PREREQUISITES :
* You must have passwordless SSH configured between the client and server users on the two hosts.
* rsync and openssh-server are installed on both hosts.

b) On the server;

The server part is pretty simple. First we will login as the root user;

sudo -i

We need a place to store the copies of the home folders. Create a folder;

mkdir -p /store/homes

Go back to the client;

Now assuming that we have keyless access to our server from the client we just need a script to do the syncing.

Create a script in /etc/init.d

root@hack:~# vi /etc/init.d/homesync
#!/bin/sh
### BEGIN INIT INFO
# Provides: homesync
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: sync homes at startup and shutdown
# Description:
### END INIT INFO

MODE=$1
TARGET="root@zen:/store/homes/"
EXCLUDE="/root/excludes.rsync"

case $MODE in

start)
rsync -parv --inplace $TARGET /home/
;;

stop)
rsync -parv --inplace --exclude-from=$EXCLUDE --delete /home/ $TARGET
;;

esac

Note: Of course you need to change TARGET= to suit your own environment. Also, if your SSH server is listening on a non standard port you will need to modify the rsync command as per this post

Make the script executable;

chmod +x /etc/init.d/homesync

If you look carefully, you will notice that the script will refer to /root/excludes.rsync for any files or folders that it should avoid syncing. We should create that file;

touch /root/excludes.rsync

Now, there are no files on the server yet so we should do an initial sync.
WARNING: If this is not the first (ie primary) client that you are setting this up on then don't run the following command as is or else it will wipe out the "backup" that is already on the server. In such a case you need to replace the "stop" in the command with "start" in order to retrieve the primary files from the server instead.

Perform an initial sync;

/etc/init.d/homesync stop
Note: Depending on how much stuff you have in your user homes this may take some time. You should also ensure that you have enough space to fit everything!


OK, assuming everything is working, the final step is to make sure the homesync script executes when the system stops and start. We do that with the update-rc.d command;

sudo update-rc.d -f homesync defaults

That's it. You can test your setup by adding or altering a file in your home folder and then shutting down your system. If you check the server you should see your changes appear there after it shuts down. If you delete or alter the file again on the server the change should appear on the client after reboot.

If you want to exclude particular files or directories then you may list them in the exludes.rsync file we created earlier.

Here is a sample list;

Junk*
oops*
.pulse*
.cache*
tmp*
temp*
gvfs*
.gvfs*
.Trash*
Trash*
*~
Thumbs.db*
desktop.ini*
lost+found*


DISCLAIMER: Be very careful using this setup in a multiuser environment where there is more than one PC (in use) at any one time. If a user is logged in on more than one PC then it is possible that they could lose data. Be sure you understand the limitations of this system before proceeding down such a path. Also note that the script only executes at startup and shutdown so if the PC is rarely restarted then this system will be of little value. I recommend using it for a simple home network only. It is not flexible or robust enough for use in a corporate network. And one final note, this does not work if you connect to the server using a wifi connection due to the way Ubuntu connects and disconnects after the user logs in. Any script such as this one that runs at boot time will not be able to connect to the network in order to do the sync. In such scenarios you could consider using a cron job or syncing manually.

Wednesday, 29 September 2010

Shrinking vmware vmdk disk images

Firstly, you should delete all unnecessary files from within the guest. This includes stuff in /tmp and any cached files, including the apt-get cache. When you have cleared out everything

Deleting files is not enough however because when you a delete file it only deletes the directory entry for the file, all the "1's and 0's" stay as they were before and therefore cannot be efficiently shrunk.

Run this command to fill all empty space on each drive with zero's.

cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

Note: if you have more than one virtual disk you will need to run this command from within any directory on the mounted disk.

Shut down the guest and log on to the host server.

Change directory (cd) to where the virtual machines vmdk files are located.

Use the vmware-vdiskmanager command to shrink the disk(s).

vmware-vdiskmanager -k sda.vmdk

When this completes, check the size of your vmdk files and they should now be considerably smaller!

Solving "udevadm trigger is not permitted while udev is unconfigured"

After updating a server recently I was presented with the following error after attempting to reboot;

udevadm trigger is not permitted while udev is unconfigured

To fix this we need to do something similar to one of my previous entries on Centos

Boot up a desktop LiveCD and perform the following steps from within a console;

Determine your boot disk, it will usually be /dev/sda1;

sudo fdisk -l

This will produce output like this;

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d730c

Device Boot Start End Blocks Id System
/dev/sda1 * 1 994 7977984 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 994 1045 407553 5 Extended
/dev/sda5 994 1045 407552 82 Linux swap / Solaris


The device with the * is the boot disk.

Create a folder in the "ubuntu" users home;

mkdir tmproot

Mount the disk to that folder (change the boot device if yours is not /dev/sda1);

sudo mount /dev/sda1 /home/ubuntu/tmproot

Chroot the mounted disk;

sudo chroot /home/ubuntu/tmproot

Finding the latest installed version of the kernel.

ls /boot

This will produce output like this;

abi-2.6.32-21-generic-pae memtest86+.bin
abi-2.6.32-24-generic-pae System.map-2.6.32-21-generic-pae
System.map-2.6.32-22-generic-pae config-2.6.32-21-generic-pae
System.map-2.6.32-24-generic-pae config-2.6.32-22-generic-pae
config-2.6.32-24-generic-pae vmcoreinfo-2.6.32-21-generic-pae
vmcoreinfo-2.6.32-24-generic-pae grub
initrd.img-2.6.32-21-generic-pae vmlinuz-2.6.32-21-generic-pae
initrd.img-2.6.32-22-generic-pae vmlinuz-2.6.32-22-generic-pae
initrd.img-2.6.32-24-generic-pae vmlinuz-2.6.32-24-generic-pae


Your latest kernel is the one with the highest version number. In my case it is 2.6.32-24-generic-pae

Update initramfs to load the latest kernel;

sudo update-initramfs -u -k 2.6.32-24-generic-pae

There will likely be an error "unable to resolve hostname ubuntu" and a few errors about /proc/mount not existing. These can be safely ignored.

Reboot the system and all should now be good!

Friday, 24 September 2010

Download from RapidShare via Command Line

Plain old wget is not able to download files from rapidshare so we need a tool that can cope with the timers and counters put up when trying to download from that site,

For this we can use "Plowshare"

You can download the deb for the current version from the Download page on the link above. At the time of writing the current version was plowshare_0.9.3-1_all.deb

Once you have the deb file install it with dpkg

sudo dpkg -i sudo dpkg -i plowshare_0.9.3-1_all.deb

This will fail due to unmet dependencies but panic not! We can fix this using apt-get;

sudo apt-get install -f

This will download and install all the missing dependencies automatically.

To use Plowshare, the authors have made it a little unintuitive, by naming the executable differently to the package name.

The executable is named "plowdown"

To download a file from Rapidshare you need the url for the file. To do this simply navigate to the Rapidshare page for the file you are after (the one with the "Speed Meters"), and click on "Free User".

This will take you to the page with the "Seconds Countdown". Copy the URL for that page and paste it into your command.

Example:
plowdown http://rs215.rapidshare.com/files/314956608/ubuntu-9.10-dvd-i386.iso.part01.rar

From here plowshare will do all of the negotiating with RapidShare, wait for any countdown timers and make the appropriate "clicks" as required for you.

This means no more waiting for timers.

Enjoy!

Friday, 13 August 2010

LVM VolGroup00 not found (CENTOS)

UPDATE: I've had a similar problem on Ubuntu recently, look here if you are trying to fix a "udevadm trigger is not permitted while udev is unconfigured" error.

-----------

Had to fix this on a server at work. Scenario was that I used Clonezilla to convert a server to an image and then created a virtual server from that image. Because the hard disk drivers had changed the virtual system failed to boot with the above error followed by the dreaded "Kernel Panic". The solution requires us to rebuild our initrd image to suit the new disk architecture.

To start we need to boot from the Centos CD/DVD and into "Rescue system" mode. Follow the prompts until you end up at a shell prompt.

Now, chroot to your system boot;

chroot /mnt/sysimage

Change to your boot directory;

cd /boot

We need to take note of the kernel version that we will be making an image for, it will usually be the latest version. In my case it was 2.6.18-53.el5PAE We will be using this info later. Just do an ls of the directory to see all the installed images.


Once you have identified the correct initrd image, we probably should back it up.

mv initrd-2.6.18-53.el5PAE.img initrd-2.6.18-53.el5PAE.img.backup

Now, we can build a new initrd;

mkinitrd /boot/initrd-2.6.18-92.el5.img 2.6.18-53.el5PAE

Once the image has been built we should rebuild grub just in case.

grub-install /dev/sda

If your drive is on /dev/hda or something else entirely then substitute the correct value in the command above.


Remove the disc from the drive and exit.

exit

And with that your system should boot up happily!