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 config-2.6.32-21-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.


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.