Mar 29, 2012

How to enlarge a VirtualBox disk with Windows XP guest in Kubuntu 12.04

After years of using my VirtualBox instance of Windows XP in my laptop I realized there is not enough space on the disk.

So I decided to enlarge it.

Create a new vdi in ~/.VirtualBox/VDI by running:

$ cd ~/.VirtualBox/VDI
$ VBoxManage createhd -filename new.vdi --size 15000 --remember

where size is in MB, in this example 15000MB ~= 15GB, and new.vdi is name of new hard drive to be created.

Next the old vdi needs to be cloned to the new vdi, this may take some time so wait while it occurs:
 
$ VBoxManage clonehd old.vdi new.vdi --existing

Detach old harddrive and attach new hard drive, replace VMName with whatever you called your VM:

$ VBoxManage modifyvm VMName --hda none
$ VBoxManage modifyvm VMName --hda new.vdi

Boot the VM, run Partition Wizard to resize the partition on the fly, and reboot.
Remove old vdi from VirtualBox and delete it:
 
$ VBoxManage closemedium disk old.vdi
$ rm old.vdi
 
Resources:
https://wiki.archlinux.org/index.php/VirtualBox_%28%C4%8Cesky%29#Increase_the_size_of_a_virtual_hard_drive_for_a_Windows_guest




Mar 21, 2012

Laptop, SSD, tmpfs and Sendmail

After my previous post about setting up Apache with tmpfs I realized I also need to start Sendmail. So let's use similar method:

Create a file:


$ sudo nano /etc/init.d/sendmail-tmpfs

with this content:

#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          sendmail-tmpfs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Required-Start:
# Required-Stop: 
# Short-Description: Create /var/spool/mqueue and /var/log/mqueue-client  on tmpfs at startup
# Description:       Create directory structure needed by Sendmail.
### END INIT INFO

#
# main()
#
case "${1:-''}" in
  'start')
   # create needed directory structure for sendmail
   mkdir /var/spool/mqueue
   mkdir /var/spool/mqueue-client
   chmod 777 /var/spool/mqueue
   chmod 777 /var/spool/mqueue-client

   ;;
  'stop')
   ;;
  'restart')
   ;;
  'reload'|'force-reload')
   ;;
  'status')
   ;;
  *)
   echo "Usage: $SELF start"
   exit 1
   ;;
esac

Let's make this file executable:

$ sudo chmod 0755 /etc/init.d/sendmail-tmpfs

And set it to start and stop before sendmail service when booting or halting the computer:

$ sudo update-rc.d sendmail-tmpfs defaults 20 20

Mar 14, 2012

Laptop, SSD, tmpfs and Apache

When you have SSD disk in your laptop, you probably use tmpfs for /var/log. There is usually no need to store logs between restarts. The number of writes to the disk is much lower with tmpfs. It means the SSD disk lasts longer ;-).

The problem with tmpfs is Apache won't start without /var/log/apache2 directory created. We have to create it before the apache2 service will start.

So let's create a file:

$ sudo nano /etc/init.d/apache2-tmpfs

with this content:

#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          apache2-tmpfs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Required-Start:  
# Required-Stop:   
# Short-Description: Create /var/log/apache2/error.log on tmpfs at startup
# Description:       Create /var/log/apache2/error.log needed by Apache.
### END INIT INFO

#
# main()
#
case "${1:-''}" in
  'start')
   # create the /var/log/apache2/error.log needed by apache
   mkdir /var/log/apache2
   chmod 777 /var/log/apache2
   touch /var/log/apache2/error.log
   chmod 777 /var/log/apache2/error.log
   ;;
  'stop')
   ;;
  'restart')
   ;;
  'reload'|'force-reload')
   ;;
  'status')
   ;;
  *)
   echo "Usage: $SELF start"
   exit 1
   ;;
esac

Let's make this file executable:

$ sudo chmod 0755 /etc/init.d/apache2-tmpfs

And set it to start and stop before apache2 service when booting or halting the computer:

$ sudo update-rc.d apache2-tmpfs defaults 90 10

References: http://bernaerts.dyndns.org/linux/50-compactflash-tune-apache

Mar 1, 2012

Transmission's web GUI is not accessible anymore

I have installed a transmission daemon on my home server. I have used to use it through integrated web GUI. After upgrading my server (from Ubuntu 11.04 Natty Narwhal to Ubuntu 11.10 Oneiric Ocelot) the web GUI was not accessible anymore. Only thing I got was this error:

409: Conflict
Your request had an invalid session-id header.
To fix this, follow these steps:

When reading a response, get its X-Transmission-Session-Id header and remember it Add the updated header to your outgoing requests When you get this 409 error message, resend your request with the updated header This requirement has been added to help prevent CSRF attacks.

X-Transmission-Session-Id: CBcYiodnQIHKYkhr9EceZOMW3ICgMSgt6j2FTCOXbcunA1tK

After hours of searching the solution a decided to use transmission from natty repository. So I did:

$ wget http://security.ubuntu.com/ubuntu/pool/main/t/transmission/transmission-common_2.13-0ubuntu8_all.deb

$ wget  http://security.ubuntu.com/ubuntu/pool/universe/t/transmission/transmission-cli_2.13-0ubuntu8_amd64.deb

$ wget http://security.ubuntu.com/ubuntu/pool/universe/t/transmission/transmission-daemon_2.13-0ubuntu8_amd64.deb

$ wget http://security.ubuntu.com/ubuntu/pool/universe/t/transmission/transmission_2.13-0ubuntu8_all.deb

Then install the downloaded files:

$ sudo dpkg -i transmission*.deb

And repair broken dependencies:

$ sudo apt-get install -f

Now the transmission web GUI works again.