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.

Feb 22, 2012

Kubuntu 12.04 - computer won't power off

I've had a strange problem when powering off my home computer. It has never powered off. The blue screen with Kubuntu logo appeared and then it hung. I had to long press power off button to complete the shutdown. It was very uncomfortable.

Even stranger thing is that when I want to restart the computer it has restarted always without any problem.

Today I finally find out a solution:

Edit the kdmrc file:

$ sudo nano /etc/kde4/kdm/kdmrc

Change one line in section [Shutdown]. It looked like this:

[Shutdown]
BootManager=None
HaltCmd=/sbin/halt
RebootCmd=/sbin/reboot

So I changed it to:

[Shutdown]
BootManager=None
HaltCmd=/sbin/shutdown -P now
RebootCmd=/sbin/reboot

Now logout from KDE. Switch to console with Ctrl+Alt+F1 and restart the kdm:

$ sudo /etc/init.d/kdm stop
$ sudo /etc/init.d/kdm start

After login to KDE again, perform the shutdown. Now it works again!

Feb 17, 2012

Kubuntu 12.04: Waking up Lenovo X220 w/ or w/o multiple monitor connected

I use my Lenovo X220 laptop in two modes:

1. In the docking station with monitor connected
2. Without the docking station just with the display

I had problems with this setup when suspending / waking up in Kubuntu 12.04. When I suspend without docking station connected and wake up without docking station connected, everything goes well. But when I wake up in the docking station it has problems with recognizing the monitor. All I can do is to restart the Xserver. It means it is useless to suspend.

So I wrote the script to detect whether the laptop is in docking station or not while it is wakeing up.

Create new file:

$ sudo nano /etc/pm/sleep.d/90_switch_display

With this content:

#!/bin/bash

. /usr/lib/pm-utils/functions

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        export DISPLAY=:0
        export XAUTHORITY=/home/<username>/.Xauthority
        xrandr --auto
        if xrandr | grep -q -e "HDMI2 connected"; then
          xrandr --output LVDS1 --off
          xrandr --output HDMI2 --auto --primary
        else
          xrandr --output HDMI2 --off
          xrandr --output LVDS1 --auto --primary
        fi
        ;;
    *)
        ;;
esac

exit

Than save it and set it executable:

$ sudo chmod 755  /etc/pm/sleep.d/90_switch_display

And that's it. Waking up behaves well ;-)

Feb 8, 2012

Kwin GLES as default window manager in Kubuntu 11.10 and KDE 4.8

Kwin GLES has great performance on my Lenovo Thinkpad X220. It looks more snappy and also the battery last longer.

After upgrading my laptop to KDE 4.8 I was unable to start Kwin GLES as default window manager. The only way was to switch it in console:

kwin_gles --replace &

It's not very comfortable. I found this hint on ArchWiki, and adapt it for Kubuntu:

First, you need kwin_gles installed:

sudo apt-get install kde-window-manager-gles

When it is installed, create new file ...

sudo nano /usr/share/kde4/apps/ksmserver/windowmanagers/kwin_gles.desktop

... with this content:

[Desktop Entry]
Name=KWin GLES
Exec=kwin_gles
TryExec=kwin_gles
X-KDE-WindowManagerConfigure=systemsettings
X-KDE-WindowManagerRestartArgument=--replace

Now you can change the window manager in the system settings: Open System Settings, go to Window Manager, select Use a different window manager: and select KWin GLES.


Next time you start your KDE session, you will be using Kwin GLES!