Howto refresh /dev/disk/by-uuid on Ubuntu

I was recently setting up a Ubuntu server and was partitioning it after it had been installed.

There was lots of free space on the drives as the root partition was only using a small portion of the disk. After running fdisk to partition it and mkfs.ext3 on the partitions to format them I couldn't see them in /dev/disk/by-uuid.

A quick google presented the solution:

sudo udevtrigger

According to the man page this makes udev request the kernel device uevents, which in essence makes it read the disk info again and show it all up so you can mount it happily.

Cheers, Mark

DVD to iPod conversion - Linux, Mac & Windows

I've been looking for a while for a way to convert DVD's and other movies that I have into iPod format and have been failing miserably. That is until today, when I came across the unusually named HandBrake.

It does exactly what is says on the tin and makes it very easy to copy dvd's. Initially I used it from my Mac and it worked flawlessly.

I also tried the Linux version on Ubuntu Hardy (8.04) which has no GUI but it is pretty simple when you get the hang of it.

Here's a typical command line:

HandBrakeCLI --preset="iPod Low-Rez" -i /media/cdrom -o myvideo.mp4 -t 2

This reads from /dev/cdrom and uses the handy "iPod Low-Rez" preset which fixes it all up nicely for the iPod.

And here's one that takes the second title:

HandBrakeCLI --preset="iPod Low-Rez" -i /media/cdrom -o myvideo.mp4 -t 2

The wiki has more information on command line usage.

Happy iPodding.

Cheers, Mark

Power saving tips for Ubuntu on laptops

One of the things that Ubuntu (gutsy 7.10) and probably most versions of linux) are currently lacking is out of the box support for power saving and hence suffers from poor battery life when unplugged.

My HP nc8430 also runs particularly hot by default - but I've spent a bit of time hunting down tips for reducing the power usage and heat produced from the laptop to get a longer battery life. I'm sure there are a lot more ways that power can be saved and I suspect that future versions of Ubuntu will catch up and produce the same level of battery life or even longer than windows.

Here is what I am using so far:

Set powerplay mode on ATI fglrx driver

aticonfig --lsp # show current and available modes
aticonfig --set-powerstate=1 #set to low power mode

If anyone has equivalent code for other video cards please let me know and I'll add it here.

Disable 'hal' from polling your cdrom

From powertop: 'hal' is the component that auto-opens a window if you plug in a CD but disables SATA power saving from kicking in.

sudo hal-disable-polling --device /dev/scd0

Disable bluetooth if you are not using it

sudo hciconfig hci0 down
sudo rmmod hci_usb

Remove the usb 1.1 kernel driver if not using it

Apparently the usb 1.1 driver does frequent polling and prevents the processor from staying in low power states for any length of time.

sudo rmmod uhci_hcd

Increase the VM dirty writeback time

From powertop: This wakes the disk up less frequenty for background VM activity.

echo 1500 |sudo tee /proc/sys/vm/dirty_writeback_centisecs

Turn off second processor

This is a very extreme measure and I haven't measured how much extra battery life it gives - but it is a bit cool to be able to turn it on and off if you have a dual core or dual CPU machine.

echo 0 | sudo tee /sys/devices/system/cpu/cpu1/online
and to turn it back on use the following:
echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online

How cool is that?

Let me know if you come across any more tips. Cheers, Mark

Updated 17/Mar/07: Fixed commands based on feedback from Neil. Thanks Neil.

Adding Mime-type for Adobe AIR Packages on Ubuntu

If you've just put you Adobe AIR package on you server and you get something that looks like the picture below then you need to add a mime type so that apache can tell your browser what type of file it is.

The reason that apache doesn't already know about it is that the Adobe AIR format has only just been released.

To fix up a Ubuntu server all you need to do is add the following line to the /etc/mime.types file:

application/vnd.adobe.air-application-installer-package+zip air

Then restart apache with:

sudo /etc/init.d/apache restart

All done. I'm sure that the mime type will be included going forward so this won't be a problem.

SSH Portforward - Address already in use - Solved

We uses SSH portforward's to ensure security of many of our systems as it allows us to have VPN-like functionality with a very simple configuration. As our use of it has grown over time I've become more and more familiar with the following error from SSH:

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 2000

This occurs when you are already using a particular port for another port forward. Eg in this case I might be trying to forward port 2000 to two different machines. However, I came across this great and simple way to prevent this.

The basic theory is to use a unique local ip address for each portforward host you wish to connect to instead of using localhost (127.0.0.1) for each.

Set up your Hosts file

Open up your hosts file: /etc/hosts and add entries like this:

#port forward local ip's
system1.fwd 127.0.0.2
system2.fwd 127.0.0.3
anothersystem.fwd 127.0.0.4

I've chosen the .fwd extension to remind me what they are for.

Set up your ssh config

Then in your .ssh/config file add the optional hostnames to the localforward:

#System1 forward to the http and mysql ports
host system1
hostname 111.111.111.111
localforward system1.fwd:80 127.0.0.1:80
localforward system1.fwd:3306 127.0.0.1:3306

host system2
hostname 111.111.111.222
localforward system2.fwd:80 127.0.0.1:80
localforward system2.fwd:3306 127.0.0.1:3306

When you connect to these systems the port forwards will now be set up.

You can access the port forwards by using system1.fwd or system2.fwd instead of localhost.

Eg: http://system1.fwd/ or http://system2.fwd/

Nice, thanks for the tip Cameron.

OS X Leopard and Ubuntu Screen sharing - HOWTO

I just go a nice shiny new Mac Mini today to use as a testing machine.

To make my life easy I want to be able to connect to it remotely from my Ubuntu (Gutsy 7.10) laptop. Luckily with Leopard's new screen sharing and a bit of googling it's easy to connect both ways.

Ubuntu to OS X

The Apple screen sharing uses a version of VNC - but the default VNC client on Ubuntu won't work with it - however thanks to this post I discovered the xtightvncviewer will work.

You need to configure your Mac to allow it with the following settings:

  • Open "System Preferences"
  • Select "Sharing"
  • Ensure "Screen Sharing" is on
  • Select "Computer Settings" on the Screen sharing page
  • Tick both boxes - "Anyone my request..." and "VNC viewers may control..." and add a password.

Note the address of your machine also - eg: vnc://192.168.0.55 or similar

Then over to the ubuntu machine and install xtightvncviewer:

$ sudo apt-get install xtightvncviewer

Then connect to the machine with: (change the ip address as relevant)

$ xtightvncviewer 192.168.0.55
You will then get a prompt - enter the password and you should be good to go.

OS X to Ubuntu

Once I had that working I was keen to see if I could get it working the other way:

You need to enable remote desktop sharing in Ubuntu:

  • Select "System->Preferences->Remote Desktop" from the menu
  • Tick the following boxes: "Allow others to view...", "Allow others to control...", and "Require ... password" and enter a password.

Then open up safari and type in the the address of you Ubuntu machine with vnc:// in front of it. eg:

It will give a warning about the vnc server not supporting "Keystroke encryption" but it will work (albeit not as securely as a Mac to Mac connection) - but good enough for your local network.

That's it - I did notice that it also showed up in Finder->Shared which I presume it found via Avahi/Bonjour - which is nice.

Hope it helps. Cheers, Mark

Setting up Asterisk with Faktortel on Ubuntu - HOWTO

Having just set up an asterisk box to connect to Faktortel I thought I'd post the settings I used as the ones on the Faktortel support website do not work quite right:

For a default asterisk install on Ubuntu do the following:

$ sudo apt-get install asterisk

You then need to edit the following files three files:

sip.conf

[general]
port = 5060 ; Port to bind to (SIP is 5060)
bindaddr = 0.0.0.0 ; Address to bind to (all addresses on machine)

; sets the codecs you can use. First disallow all defaults, then set our own ind ividually.
disallow = all
allow=gsm

; Setup a user with the phone number 1000 on our network.
[1000]
tos=reliability
type=friend
username=1000
host=dynamic
context=default
reinvite=no
canreinvite=no
secret=abc123
nat=yes
qualify=yes

iax.conf

; Setup the general options, including our default port for use with IAX
; the amount of bandwidth we have on our connection to the server (best left as low)
; jitterbuffer, this isn't enabled at the moment in the latest CVS but we don't want it
; to suddenly come on when it is enabled.

[general]
bandwidth=low
jitterbuffer=no
tos=lowdelay


; This line registers your server with the FaktorTel main server, what this means is that
; it tells us where you are on the internet so you can receive incoming calls from our network
; don't forget to replace "YOUR-USERNAME" and "YOUR-PASSWORD" with the ones supplied to you.

register => YOUR-USERNAME:YOUR-PASSWORD@iax.faktortel.com.au

; The following section sets up an IAX user called "faktortel", this is the user which will place
; the call from your server to our network. First we tell it not to use any other codec by setting
; our "Disallow" and "allow" settings. Then we set the type to "friend", then set our password and
; username for the faktortel network (don't forget to change these to the ones supplied to you).
; using the "host" command we tell the user which server to connect to, then using "auth" we tell
; it the type of password to look for, and finally using "qualify" we tell it to keep in touch
; with the server ever 3 seconds. (This is fast enough).

[faktortel]
disallow=all
allow=gsm
type=friend
username=YOUR-USERNAME
secret=YOUR-PASSWORD
host=iax.faktortel.com.au
auth=md5
context=incoming
qualify=yes

extensions.conf

; First we setup a context called "Default" this is our "Encapsulation" context. The only point of this
; context is to point to all our other groups in order. We only have one other outgoing context at the
; moment so we are just including one "faktortel-outgoing" however this will allow you to make a much
; more sturdy network later if you use it as a full PBX. This is also the context we use to place calls out of.

[default]
include => faktortel-outgoing


; FaktorTel-Outgoing is another context, this tells anyone who is trying to make a call out from the PBX
; which starts with a "0" to put that call out to the PSTN via FaktorTel. The format here is best
; described at "www.voip-info.org" under "configuration files" "extensions.conf".

[faktortel-outgoing]
exten => _0.,1,DIAL(IAX2/YOUR-USERNAME@faktortel/${EXTEN:1})
exten => _0.,2,Congestion

; Adding an extension for the number 1234 which will give you the Time.
exten => 1234,1,SayUnixTime
exten => 1234,2,Hangup


; This is our "incoming" context, when a call comes in from the faktortel network it is sent here
; because we set "context=incoming" in our IAX.CONF file under [faktortel]. This then tells it
; that ANY call that comes in should ring the SIP based phone at extension "1000" which we setup
; earlier.

[incoming]
; Add extension for you DID number
exten => YOUR_DID_NUMBER,1,Answer
exten => YOUR_DID_NUMBER,n,SayUnixTime
exten => YOUR_DID_NUMBER,n,Hangup

Hope this helps you get going with Asterisk. Cheers, Mark

Joining video files in Ubuntu

I've been tidying up some video's that were taken on my camera and wanted to merge the short snippets of video so I could convert them to DVD for easy family viewing.

A quick google turned up the relevant details:

Ensure you have mplayer & mencoder installed

sudo apt-get install mencoder mplayer

Merge the files together

cat video1.avi video2.avi video3.avi > merged.avi

Reindex the audio and video

mencoder -forceidx -oac copy -ovc copy merged.avi -o merged_final.avi

All done - if you want to convert it to a DVD check out HOWTO Create DVD's from AVI's on Ubuntu.

Thanks to the good folk at ArsGeek for the tip.

HOWTO Create DVD's from AVI's on Ubuntu

To create simple DVD's (i.e. with no title menu's) you need the following software:

  • mplayer
  • videotrans
  • libxvidcore4
  • dvdauthor
  • mkisofs

To install all this use:

$ sudo apt-get install mplayer videotrans dvdauthor mkisofs libxvidcore4

Here are the simple steps to format a video for DVD:

First, make sure you can view the video using mplayer:

$ mplayer MyMovie.avi

Then we convert if to DVD mpeg format:

$ movie-to-dvd -m pal MyMovie.avi

This will create two files: MyMovie.m2v and MyMovie.ac3 which we need to merge back together:

$ mplex -f 8 -o MyMovie.mpg MyMovie.m2v MyMovie.ac3

Format the video for DVD:

$ dvdauthor -o dvd/ -t MyMovie.mpg

Create a title page for it:

$ dvdauthor -o dvd/ -T

Create an ISO image to burn to dvd:

$ mkisofs -dvd-video -v -o MyMovie.iso dvd

Then right click on the ISO in the file browser (Nautilus) and select "Write to Disc" and you have a DVD that will play in you normal DVD player.

References:

HOWTO insert a line break in SMS

I've spent some time today setting up a ColdFusion scheduled task which is sending out text messages (SMS) via Clickatell HTTP API. SMS contains some reporting data and the problem I encountered was how to display each reporting figure on a new line. I knew I couldn't use br or \n for obvious reasons, so there had to be another magic character that did the trick. That magic character is %0A

For example, if I wanted to display the following text in SMS:

Line 1
Line 2

I would have to write my code like so:

Line 1%0ALine 2

Nice!

Marko

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.