<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>NewInstance</title>
	<link>http://it.newinstance.it</link>
	<description>A tech blog by Luigi R. Viggiano</description>
	<pubDate>Fri, 22 Jan 2010 14:15:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.3</generator>
	<language>en</language>
			<item>
		<title>Syntactic sugar and Java arrays.</title>
		<link>http://it.newinstance.it/2010/01/08/syntactic-sugar-and-java-arrays/</link>
		<comments>http://it.newinstance.it/2010/01/08/syntactic-sugar-and-java-arrays/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 23:53:48 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Java</category>
		<guid isPermaLink="false">http://en.newinstance.it/2010/01/08/syntactic-sugar-and-java-arrays/</guid>
		<description><![CDATA[Recently I got surprised by following case.
In Java you can declare an array in following valid ways:

String[] strings = new String[] { "foo", "bar" };
// the above is equivalent to the following:
String[] strings = { "foo", "bar" };

So following Java code is perfectly valid:

public class Foo {

    public void doSomething(String[] arg) {}

 [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I got surprised by following case.</p>
<p>In Java you can declare an array in following valid ways:</p>
<pre>
String[] strings = new String[] { "foo", "bar" };
// the above is equivalent to the following:
String[] strings = { "foo", "bar" };
</pre>
<p>So following Java code is perfectly valid:</p>
<pre>
public class Foo {

    public void doSomething(String[] arg) {}

    public void example() {
        String[] strings = { "foo", "bar" };
        doSomething(strings);
    }

}
</pre>
<p>Is there any valid reason why, instead, the following code shouldn't be valid?</p>
<pre>

public class Foo {

    public void doSomething(String[] arg) {}

    public void example() {
        doSomething({ "foo", "bar" });
    }

}
</pre>
<p>I think, that the above syntax would have been a valid substitute to the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html">varargs</a> introduced in Java 5. And, more coherent with the previously allowed array declarations.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2010/01/08/syntactic-sugar-and-java-arrays/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>3G USB Stick on Ubuntu</title>
		<link>http://it.newinstance.it/2010/01/08/3g-usb-stick-on-ubuntu/</link>
		<comments>http://it.newinstance.it/2010/01/08/3g-usb-stick-on-ubuntu/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 23:22:33 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Internet</category>
	<category>Linux</category>
	<category>Hardware</category>
		<guid isPermaLink="false">http://en.newinstance.it/2010/01/08/3g-usb-stick-on-ubuntu/</guid>
		<description><![CDATA[I am in London for work, and my hotel wants me to pay £ 17 per day for accessing internet. But I found an internet café which is offering Internet connection on a 3G USB stick for £ 19.99 per week ( reload.com 197 Praed Street, Paddington ). The USB stick is from Three, like [...]]]></description>
			<content:encoded><![CDATA[<p>I am in London for work, and my hotel wants me to pay £ 17 per day for accessing internet. But I found an internet café which is offering Internet connection on a 3G USB stick for £ 19.99 per week ( reload.com 197 Praed Street, Paddington ). The USB stick is from <a href="http://three.co.uk">Three</a>, like the one that can be found <a href="http://threestore.three.co.uk/dealsummary.aspx?offercode=24MB1GD029&#038;id=1397">here</a>.<br />
When you plug it in, Linux will mount a storage device which contains the drivers for OSX/Windows/Linux. The ones for Linux, of course, do not work: there are some files (zte drivers) precompiled for some version of Fedora, and other stuff which doesn't compile on Ubuntu.<br />
The good news is that you don't need any driver in Linux; just some hacking. The kernel of Ubuntu is built with support of the most common 3G drivers.</p>
<p>Below I explain how to make it work.</p>
<h4>Disable the USB storage</h4>
<p>When the USB stick is behaving as USB storage it won't work as 3G modem. The first thing to do is to disable that.</p>
<p>Locate the device assigned to the USB stick:</p>
<pre>
luigi@hal9000:~$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3            199024992 113153688  75761392  60% /
udev                   2018164       296   2017868   1% /dev
none                   2018164       340   2017824   1% /dev/shm
none                   2018164       324   2017840   1% /var/run
none                   2018164         0   2018164   0% /var/lock
none                   2018164         0   2018164   0% /lib/init/rw
/dev/sr1                 26330     26330         0 100% /media/3Connect
</pre>
<p>The 3Connect one is the USB stick, so let's unmount it, to be able - later - to unload the usb_storage kernel module.</p>
<pre>
luigi@hal9000:~$ sudo eject /dev/sr1
[sudo] password for luigi: *****
</pre>
<p>now let's unload the usb_storage kernel module.</p>
<pre>
luigi@hal9000:~$ lsmod | grep usb_storage
usb_storage            66016  0
luigi@hal9000:~$ sudo rmmod usb_storage
luigi@hal9000:~$ lsmod | grep usb_storage
</pre>
<p>The first command (lsmod) checks that usb_storage is loaded, and see if there are other modules depending on it. There aren't, so we can remove the module (rmmod command). Last command (lsmod) is to verify that the module is successfully unloaded; if it doesn't display anything means that the usb_storage module is gone, so it's ok! </p>
<h4>Load the usbserial kernel module</h4>
<p>Now we can load the usbserial kernel module and we can associate that to the USB stick.</p>
<p>First of all, let's check how the module is loaded:</p>
<pre>
luigi@hal9000:~$ lsmod | grep usbserial
usbserial              43248  1 option
</pre>
<p>We see that there's the "option" module depending on the usbserial, so we need to first unload option then usbserial.<br />
Let's do that with rmmod command.</p>
<pre>
luigi@hal9000:~$ sudo rmmod option usbserial
luigi@hal9000:~$ lsmod | grep usbserial
</pre>
<p>The lsmod at the end is just to ensure that usbserial is successfully unloaded. This time it should not display anything.</p>
<p>Now we need to know the manufacturer id and the product id of the usb device. Let's do that with lsusb command:</p>
<pre>
luigi@hal9000:~$ lsusb
Bus 004 Device 003: ID 05ac:8213 Apple, Inc.
Bus 004 Device 002: ID 0a5c:4500 Broadcom Corp.
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 05ac:8507 Apple, Inc.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 003: ID 05ac:0237 Apple, Inc.
Bus 003 Device 002: ID 05ac:8242 Apple, Inc.
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 006: ID 19d2:0031 ONDA Communication S.p.A.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
</pre>
<p>Our device is the 19d2:0031 ONDA Communication S.p.A. I found that after some tries, pluggin and unplugging the USB stick and checking the differences printed by lsmod. Notice that if the usb_storage module is active the product id will be different, while the manufacturer id will be the same. The output of lsmod is not very informative and helping to understand the nature of the usb device, unfortunately. </p>
<p>Now we can load the usbserial device specifying the vendor id and product id of the USB stick.</p>
<pre>
luigi@hal9000:~$ sudo modprobe usbserial vendor=0x19d2 product=0x0031
</pre>
<p>If there are no error displayed, and the command ends silently, then it means that the module is loaded successfully.</p>
<h4>Configuring the 3G connection</h4>
<p>Clicking on the NetworkManager we should now be able to see the New Mobile BroadBand (GSM) Connection:<br />
<img id="image405" src="http://en.newinstance.it/wp-content/uploads/2010/01/new-mobile-broadband.png" alt="new-mobile-broadband.png" /> </p>
<p>Click on it to configure. It will result in a Wizard dialog that will ask you information to "Set up a Mobile Broadband Connection". In my case I filled following information:<br />
Country: I selected "Britain (UK)" ... I took some time to find it: I was looking for "UK" or "United Kingdom" or "England" or some other name...<br />
Select your provider form a list: 3<br />
Select your plan: Internet<br />
Confirm.</p>
<p>After that, the connection is ready and you should be able to browse the internet. Clicking on the NetworkManager tray icon you'll see that you are now connected through it:<br />
<img id="image406" src="http://en.newinstance.it/wp-content/uploads/2010/01/3-internet.png" alt="3-internet.png" /></p>
<h4>Improving the connection reliability</h4>
<p>The connection is quite bad through the 3 network. Sometime you keep being connected but internet stops working. I thought to DNS problem so I set up OpenDNS following <a href="https://store.opendns.com/setup/operatingsystem/ubuntu">these instructions</a>, and now it seems more reliable and usable, but still sometime the connection stops working, and you need to unplug the stick and restart from with the procedure described above.<br />
I don't know why... if somebody knows, please leave a comment.</p>
<p>I'd like to buy a 3G USB Stick or 3G modem; if somebody have some hints on a good supported device, and stable, (easier to set up), please leave a comment.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2010/01/08/3g-usb-stick-on-ubuntu/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Ipod touch with Linux</title>
		<link>http://it.newinstance.it/2009/12/03/ipod-touch-with-linux/</link>
		<comments>http://it.newinstance.it/2009/12/03/ipod-touch-with-linux/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 12:11:58 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Software</category>
	<category>Mac</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/12/03/ipod-touch-with-linux/</guid>
		<description><![CDATA[Yesterday night I tried to connect the iPod to Linux. I tried some programs but none was working decently; but the good news is that you don't really need any special program "made for iPod" to do this. 
For the guys who do not know about iTunes and iPod/iPhone foolishnesses, the problem is that when [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday night I tried to connect the iPod to Linux. I tried some programs but none was working decently; but the good news is that you don't really need any special program "made for iPod" to do this. </p>
<p>For the guys who do not know about iTunes and iPod/iPhone foolishnesses, the problem is that when connecting trough USB they are not exposing the filesystem as usb disk. The second problem is how iTunes memorizes files: they get renamed in 4 char lenght filenames under a 3 char lenght folder... so you have files like: </p>
<pre>
iTunes_Control/Music/F26/UBFF.mp3
iTunes_Control/Music/F26/UEBM.mp3
iTunes_Control/Music/F26/UIPQ.mp3
iTunes_Control/Music/F26/UWCJ.mp3
iTunes_Control/Music/F26/WGOH.m4a
</pre>
<p>As result of this, if you have songs belonging to different authors and coming from different albums, but you was keeping in the same folder to listen together... you can't specify to iTunes to play a folder as a playlist, because folder and filenames gets chaotically "reorganized" when imported in iTunes. iTunes, then uses id3 tags to expose views to the user, grouping by author or album title, etc.</p>
<p>To connect to iPod filesystem with Linux, you need to <a href="http://en.wikipedia.org/wiki/Jailbreak_%28iPhone_OS%29">jailbreak</a> the iPhone or the iPod touch, and have OpenSSH running on it. It is not very difficult, but, afaik it's the only way to access remotely to the iPod filesystem, through network (wifi).</p>
<p>Once done that, you need to mount the filesystem using ssh protocol; this can be done with sshfs, which is the ssh protocol support for <a href="http://fuse.sourceforge.net/">FUSE</a> (Filesystem in USEr space) which allows you to mount several type of local or remote filesystem without needing root privileges.</p>
<pre>
$ sudo apt-get install sshfs
</pre>
<p>Then I created a folder under my ~/Music folder where to mount my iPod media</p>
<pre>
$ mkdir ~/Music/iPod
</pre>
<p>At last I made a bash script to mount and unmount the iPod media to the folder I just created. This is the content:</p>
<pre>
#! /bin/bash

case "$1" in
mount)
        echo -n foobar | sshfs root@Luigi-R-Viggianos-iPod.local:/private/var/mobile/Media/ ~/Music/iPod -o password_stdin
	;;

umount)
        fusermount -u -z ~/Music/iPod
	;;

*)
	echo "Usage: `basename $0` {mount|umount}"
	exit 1
	;;
esac
</pre>
<p>In the above script "foobar" is the password to use to ssh-connect as root on my ipod. Unfortunately I did not succeed in using public key authentication, even modifying the sshd configuration on the ipod, I do not know why... So I had to specify the password in the script.<br />
The Luigi-R-Viggianos-iPod.local is the hostname used by my iPod. Alternatively you can use the ip address, but when you change network you will need to update the script; the hostname usually gets recognized in different WIFIs and mapped to corresponding ip address.</p>
<p>To get the ip address of the iPod connected to WIFI, there are some programs downloadable on the apple store, one is called, with much of fantasy, "IP Address". To know the hostname of the ipod, just connect to it through ssh, and you will see that displayed on the bash prompt line, in my case: "Luigi-R-Viggianos-iPod:~ root#", unfortunately apples likes to have weird unix system on their devices so you don't have basic commands like 'hostname' or files like /etc/hostname to check... did I already said that I hate OSX...? </p>
<p>At this point what I do is just running the script:</p>
<pre>
$ ipod mount
or
$ ipod umount
</pre>
<p>to mount or unmount the iPod to ~/Music/iPod folder. The iPod needs to be attached to a power source, the laptop trough usb or to a docking station, otherwise it will disable the WIFI connection when it goes on stand by; but the file access is fully wireless.</p>
<p>To play files, you need to launch Amarok or Rhytmbox and import the folder ~/Music/iPod. I use Rhytmbox and it indexes the folder. When the folder is mounted I can see the music on my iPod, and when it is not, the music just disappears.</p>
<p>If you want to export an album of MP3 files from the iPod, you just need to select files from Rhytmbox and drag and drop into Nautilus (filesystem browser). But you will have the weird names for the MP3 files set by iTunes. To batch rename the files you can install and use id3ren, which lets you to customize (-template option) how the filename should be renamed (using album title, song title, author, etc):</p>
<pre>
$ sudo apt-get install id3ren
$ id3ren -template='%a - %t - %s.mp3' *
</pre>
<p>If you like to backup the music on your iPod just use rsync or cp. But I don't know how to import new songs in the weird filesystem-format used by iTunes... For this, possibly the easiest solution is to use iTunes on Windows or OSX using VMWare, until Apple does not decide to release <a href="http://www.petitiononline.com/itmslin/petition.html">iTunes on Linux</a>. </p>
<p>Have fun.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/12/03/ipod-touch-with-linux/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Karmic and Luks: USB drive encryption made (almost) easy</title>
		<link>http://it.newinstance.it/2009/11/26/karmic-and-luks-usb-drive-encryption-made-almost-easy/</link>
		<comments>http://it.newinstance.it/2009/11/26/karmic-and-luks-usb-drive-encryption-made-almost-easy/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 16:34:48 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/11/26/karmic-and-luks-usb-drive-encryption-made-almost-easy/</guid>
		<description><![CDATA[I discovered today that in Karmic there is an option to format encrypted usb disks.
But first of all you need to install the support for this feature; from the terminal:

$ sudo apt-get install cryptsetup

When you plug in your USB disk, and mount it, you'll see an icon on your desktop. Right-clicking on it and selecting [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered today that in Karmic there is an option to format encrypted usb disks.<br />
But first of all you need to install the support for this feature; from the terminal:</p>
<pre>
$ sudo apt-get install cryptsetup
</pre>
<p>When you plug in your USB disk, and mount it, you'll see an icon on your desktop. Right-clicking on it and selecting "Format" will let you to specify an encrypted filesystem type:</p>
<p><img id="image396" src="http://en.newinstance.it/wp-content/uploads/2009/11/Screenshot-1.png" alt="Format USB drive" /></p>
<p><img id="image394" src="http://en.newinstance.it/wp-content/uploads/2009/11/Screenshot-Format%20SanDisk%20Cruzer%20Pattern%20%288-0%20GB%29.png" alt="Screenshot-Format SanDisk Cruzer Pattern (8.0 GB)" /></p>
<p>Clicking to "Format" button will ask you to type the password for the encrypted volume: </p>
<p><img id="image395" src="http://en.newinstance.it/wp-content/uploads/2009/11/Screenshot-Enter%20Passphrase.png" alt="Screenshot-Enter Passphrase" /></p>
<p>At this point the format will proceed and, after, the USB drive will be mounted with an open lock icon:<br />
<img id="image397" src="http://en.newinstance.it/wp-content/uploads/2009/11/mounted-encrypted.png" alt="encrypted volume mounted " /></p>
<p>If you want to change the password it should be possible from the "Disk Utility" (System>Administration>Disk Utility, or type "palimpsest" at the command line), but <a href="https://bugs.launchpad.net/ubuntu/+source/gnome-disk-utility/+bug/484904">it seems to be buggy</a>, as it always gives me "Incorrect Passphrase. Try again".</p>
<p>Command line tools always helps in those cases.</p>
<p>First step, add the new password for the volume:</p>
<pre>
$ sudo cryptsetup luksAddKey /dev/sdb
[sudo] password for luigi: (my system admin password)
Enter any LUKS passphrase: (any password registered to this volume)
key slot 0 unlocked.
Enter new passphrase for key slot: (the new password)
Verify passphrase: (the new password again)
Command successful.
</pre>
<p>Second step, dump all the key password for the volume: </p>
<pre>
$ sudo cryptsetup luksDump /dev/sdb
LUKS header information for /dev/sdb

Version:       	1
Cipher name:   	aes
Cipher mode:   	cbc-essiv:sha256
Hash spec:     	sha1
Payload offset:	1032
MK bits:       	128
MK digest:     	c8 97 18 80 0c 0a 86 ed 8f 3c 85 03 e1 de de 2d 68 ed 70 a0
MK salt:       	16 ae 5b 05 2c 2b 02 d5 af 0d 71 d7 08 ba 51 fd
               	9f 98 cd 11 52 e8 14 44 71 4f 84 53 99 02 97 c7
MK iterations: 	10
UUID:          	c4ada688-3cae-4053-a1c6-781614ad683f

Key Slot 0: ENABLED
	Iterations:         	447466
	Salt:               	63 30 36 1f 87 83 f6 73 75 e9 a2 b2 dc f1 30 4c
	                      	09 67 1d e7 82 71 35 6c c4 df ce 10 0e 3b 42 2f
	Key material offset:	8
	AF stripes:            	4000
Key Slot 1: ENABLED
	Iterations:         	451004
	Salt:               	55 c4 d0 4f e9 24 d8 c0 2a cb b2 7f 09 a1 80 98
	                      	4f 4d 1a 5e 6f 1c d5 ad c2 30 a3 02 15 9d 1e bd
	Key material offset:	136
	AF stripes:            	4000
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED
</pre>
<p>Third step: remove the old password:</p>
<pre>
$ sudo cryptsetup luksKillSlot /dev/sdb 0
Enter any remaining LUKS passphrase:
key slot 1 verified.
Command successful.
</pre>
<p>Unmount the volume and try the new password. It should work.</p>
<p>Of course it would be better to have the "change password" feature in the context menu of the mounted volume, or at least having the feature working in the "Disk Utility" program. But, you know, it's Linux, and you need to hack it sometimes <img src='http://it.newinstance.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>It seems also that LUKS is supported on Windows, see <a href="http://www.freeotfe.org/">here</a>.</p>
<p>Another good, portable, free, and more complete solution to encrypted filesystems is the great <a href="http://www.truecrypt.org/">TrueCrypt</a>.</p>
<p>For the experts, a useful command-line HOWTO on using LUKS: <a href="http://ubuntuforums.org/showthread.php?t=404346">http://ubuntuforums.org/showthread.php?t=404346</a>.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/11/26/karmic-and-luks-usb-drive-encryption-made-almost-easy/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Suspend/Resume in Karmic /2</title>
		<link>http://it.newinstance.it/2009/11/25/suspendresume-in-karmic-2/</link>
		<comments>http://it.newinstance.it/2009/11/25/suspendresume-in-karmic-2/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 23:30:29 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Hardware</category>
	<category>Mac</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/11/25/suspendresume-in-karmic-2/</guid>
		<description><![CDATA[Previously I wrote that suspend/resume was not working in Karmic on my MacBook Pro 5.1, and I posted a solution. Now I found a better solution from the Apple Users forum on Ubuntu. The advantage is that with this fix, the suspend/resume is much faster.
First you need to revert the change I suggested previously.
Then... (copied [...]]]></description>
			<content:encoded><![CDATA[<p>Previously I wrote that suspend/resume was not working in Karmic on my MacBook Pro 5.1, and I posted a solution. Now I found a <a href="http://ubuntuforums.org/showthread.php?t=1215928">better solution</a> from the Apple Users forum on Ubuntu. The advantage is that with this fix, the suspend/resume is much faster.<br />
First you need to revert the change I suggested previously.</p>
<p>Then... (copied from the forum)</p>
<p>install a package called uswsusp</p>
<pre>
sudo apt-get install uswsusp
</pre>
<p>the package carries two nice tools: s2ram and s2disk</p>
<p>First of all make sure they work launching</p>
<pre>
sudo s2ram --force
</pre>
<p>to suspend to ram or</p>
<pre>
sudo s2disk
</pre>
<p>to hibernate.</p>
<p>I personally don't care too much about hibernation. Nice thing about s2ram, though, is that it goes to sleep maintaining somehow the proper wifi settings so that when you open up the lid again the machine is immediately connected to the internet, exactly as it happens in OSX<strong style="color:red;"><sup>1</sup></strong>. The resume takes about 5 seconds and you are ready to go.</p>
<p>By default gnome prompts you with the password after resume. If you don't like this behaviour, you can change it running</p>
<pre>
gconftool -s /apps/gnome-power-manager/lock/suspend -t bool false
</pre>
<p>you can of course use s2ram and s2disk as default tools. to do so, you need to replace two of the existing scripts.</p>
<pre>
sudo cp /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux.bak
sudo cp /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux.bak
</pre>
<p>and then</p>
<pre>
 sudo gedit /usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux
</pre>
<p>replace what you find with:</p>
<pre>
#!/usr/bin/env bash
/usr/sbin/s2disk
</pre>
<pre>
 sudo gedit /usr/lib/hal/scripts/linux/hal-system-power-suspend-linux
</pre>
<p>replace what you find with:</p>
<pre>
#!/usr/bin/env bash
/usr/sbin/s2ram --force
</pre>
<p>Credits for this post: <a href="http://ubuntuforums.org/member.php?u=282112">crocowhile</a></p>
<p><strong>Luigi's notes on above post</strong><br />
<strong style="color:red;"><sup>1</sup></strong>: this doesn't happen to me, it seems that, before suspending the wifi connection is brought down, then it needs to be restarted on resume. There is an option in the Gnome Configuration Editor apps/gnome-power-manager/general/network_sleep which is described as <em>"Whether NetworkManager should disconnect before suspending or hibernating and connect on resume"</em>. By default this is disabled, which I think should mean to not disconnect/reconnect. I played a little bit with it; but it seems that is not taking any effect, and every time I resume the NetworkManager reconnects to the WIFI. Suspending with the command line, this doesn't happen, and the WIFI is immediately available; I need further investigations on this. I suspect the pm-utils is playing some quirk, and I cannot find a configuration variable for pm-utils to specify to avoid this.</p>
<h4>UPDATE: NetworkManager is fixed!</h4>
<p>I just found that the cause of the NetworkManager to disconnect/reconnect on suspend/resume was actually the pm-utils. So I modified the script located at <tt>/usr/lib/pm-utils/sleep.d/55NetworkManager</tt> to not manage the NetworkManager. I've commented the two lines in bold:</p>
<pre>
luigi@hal9000:~$ cat /usr/lib/pm-utils/sleep.d/55NetworkManager
#!/bin/sh
# If we are running NetworkManager, tell it we are going to sleep.
# TODO: Make NetworkManager smarter about how to handle sleep/resume
#       If we are asleep for less time than it takes for TCP to reset a
#       connection, and we are assigned the same IP on resume, we should
#       not break established connections.  Apple can do this, and it is
#       rather nifty.

. "${PM_FUNCTIONS}"

suspend_nm()
{
	# Tell NetworkManager to shut down networking
	dbus_send --print-reply --system                         
		--dest=org.freedesktop.NetworkManager  
		/org/freedesktop/NetworkManager        
		org.freedesktop.NetworkManager.sleep 2>&#038;1 > /dev/null
}

resume_nm()
{
	# Wake up NetworkManager and make it do a new connection
	dbus_send --print-reply --system                        
		--dest=org.freedesktop.NetworkManager 
		/org/freedesktop/NetworkManager       
		org.freedesktop.NetworkManager.wake 2>&#038;1 > /dev/null
}

case "$1" in
	hibernate|suspend)
		<strong><span style="color:red">#</span> suspend_nm</strong>
		;;
	thaw|resume)
		<strong><span style="color:red">#</span> resume_nm</strong>
		;;
	*) exit $NA
		;;
esac
</pre>
<p>With this change now, from the time I open the laptop lid, it takes 2-3 seconds to wake up and be online. Wow!</p>
<h4>UPDATE: Suspend-after-resume bug</h4>
<p>During the resume it could happen that the mac goes back into a suspend (see <a href="https://bugs.launchpad.net/ubuntu/karmic/+source/gnome-power-manager/+bug/425411">gnome-power-manager bug #425411</a>). This is resolved by the following:</p>
<ol>
<li>Run gconf-editor</li>
<li> Go to apps -> gnome-power-manager -> actions</li>
<li>Uncheck the box next to event_when_closed_battery.</li>
</ol>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/11/25/suspendresume-in-karmic-2/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Suspend/Resume problem in Ubuntu Karmic 9.10 running on MacBook Pro 5.1</title>
		<link>http://it.newinstance.it/2009/11/20/suspendresume-problem-in-ubuntu-karmic-910-running-on-macbook-pro-51/</link>
		<comments>http://it.newinstance.it/2009/11/20/suspendresume-problem-in-ubuntu-karmic-910-running-on-macbook-pro-51/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 21:40:58 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Hardware</category>
	<category>Mac</category>
	<category>Errors</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/11/20/suspendresume-problem-in-ubuntu-karmic-910-running-on-macbook-pro-51/</guid>
		<description><![CDATA[I updated today from Jaunty to Karmic and, as effect, I had Suspend/Resume/Hibernate broken. But reboot and shutdown works; before with Jaunty the reboot was frequently crashing.
To fix the Suspend/Resume, I modified /boot/grub/menu.lst to add the kernel option acpi=noirq
Example:

title		Ubuntu 9.10, kernel 2.6.31-14-generic
uuid		5daec709-2655-4d7c-9968-969143e31fbd
kernel		/boot/vmlinuz-2.6.31-14-generic root=UUID=5daec709-2655-4d7c-9968-969143e31fbd ro quiet splash acpi=noirq
initrd		/boot/initrd.img-2.6.31-14-generic
quiet

Other problem I found during the distro upgrade:

sound is [...]]]></description>
			<content:encoded><![CDATA[<p>I updated today from Jaunty to Karmic and, as effect, I had Suspend/Resume/Hibernate broken. But reboot and shutdown works; before with Jaunty the reboot was frequently crashing.</p>
<p>To fix the Suspend/Resume, I modified <tt>/boot/grub/menu.lst</tt> to add the kernel option <strong>acpi=noirq</strong></p>
<p>Example:</p>
<pre>
title		Ubuntu 9.10, kernel 2.6.31-14-generic
uuid		5daec709-2655-4d7c-9968-969143e31fbd
kernel		/boot/vmlinuz-2.6.31-14-generic root=UUID=5daec709-2655-4d7c-9968-969143e31fbd ro quiet splash <strong>acpi=noirq</strong>
initrd		/boot/initrd.img-2.6.31-14-generic
quiet
</pre>
<p>Other problem I found during the distro upgrade:</p>
<ul>
<li>sound is now working without needing to compile a <a href="https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/337314/comments/73">patched</a> alsa driver. But it made me crazy to make headphone work. The audio settings are now simplified, and that is a good thing, but they are hiding options needed to make things work. Hint: install gnome-alsamixer and unmute headphones. </li>
<li>infrared remote control stopped working. I have to investigate further on this.</li>
</ul>
<p>For now I notice that Nvidia GPU temperature looks lower now, but I still use mfc-daemon to automatically adapt fan speed to CPU temperature; but sometime it stops working and if you are not at the computer it may be risky (today I almost burned it while watching a video running in novell moonlight, which turns your laptop in a oven)</p>
<p>Sound works much better, it seems that the problem of the applications locking the sound resource exclusively is gone, or reduced. So now running vlc and a youtube video works fine. In the sound preferences now you can see the applications that are using the audio device:</p>
<p><img id="image391" src="http://en.newinstance.it/wp-content/uploads/2009/11/Screenshot-Sound%20Preferences.png" alt="Karmic Sound" /></p>
<p>Finally!</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/11/20/suspendresume-problem-in-ubuntu-karmic-910-running-on-macbook-pro-51/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>MacBook International Keyboard and Linux</title>
		<link>http://it.newinstance.it/2009/09/03/macbook-international-keyboard-and-linux/</link>
		<comments>http://it.newinstance.it/2009/09/03/macbook-international-keyboard-and-linux/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 20:05:34 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Hardware</category>
	<category>Mac</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/09/03/macbook-international-keyboard-and-linux/</guid>
		<description><![CDATA[I bought my Mac with the "International Keyboard". Which layout should you use on Linux? 
The keyboard layout looks like this one:

As far as I know the "USA Macintosh" is the one that fits better, but still you have the §± and `~ keys inverted. To fix this I've added to Gnome Session Startup this [...]]]></description>
			<content:encoded><![CDATA[<p>I bought my Mac with the "International Keyboard". Which layout should you use on Linux? </p>
<p>The keyboard layout looks like this one:</p>
<p><img id="image386" src="http://en.newinstance.it/wp-content/uploads/2009/09/mac-international-keyboard.png" alt="Macintosh International Keyboard" /></p>
<p>As far as I know the "USA Macintosh" is the one that fits better, but still you have the §± and `~ keys inverted. To fix this I've added to Gnome Session Startup this script:</p>
<pre>
#!/bin/bash

# fix keyboard layout switching §± and `~
xmodmap -e "keycode 49 = section plusminus section plusminus section plusminus"
xmodmap -e "keycode 94 = grave asciitilde grave asciitilde dead_grave dead_horn"
</pre>
<p>It doesn't replace that on the tty consoles, but works perfect in Xorg.</p>
<h4>UPDATE: ~/.xmodmaprc</h4>
<p>Another alternative is to create a file in your home folder: ~/.xmodmaprc with following content:</p>
<pre>
$ cat .xmodmaprc
keycode 94 = grave asciitilde grave asciitilde dead_grave dead_horn
keycode 49 = section plusminus section plusminus section plusminus
</pre>
<p>I don't like very much having ~/.files so I put those files under ~/etc folder and use symbolic links: </p>
<pre>
$ ls -lad .* | grep "\-&gt;"
lrwxrwxrwx  1 luigi luigi     18 2009-07-29 23:45 .manpath -&gt; etc/manpath.config
lrwxrwxrwx  1 luigi luigi     13 2009-11-20 16:52 .xmodmaprc -&gt; etc/xmodmaprc
</pre>
<p>I think it's an easier way to manage local configurations, even though I don't move every ~/.file to a link under ~/etc I still prefere to keep a more visible and explicit and "visible" configuration under a local etc folder. Under my home folder I also have folders bin,opt,src,tmp,var,etc...
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/09/03/macbook-international-keyboard-and-linux/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Mighty Mouse: reverse horizontal scrolling workaround on Ubuntu Linux 9.04</title>
		<link>http://it.newinstance.it/2009/09/01/mighty-mouse-reverse-horizontal-scrolling-workaround-on-ubuntu-linux-904/</link>
		<comments>http://it.newinstance.it/2009/09/01/mighty-mouse-reverse-horizontal-scrolling-workaround-on-ubuntu-linux-904/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 22:49:36 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Mac</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/09/01/mighty-mouse-reverse-horizontal-scrolling-workaround-on-ubuntu-linux-904/</guid>
		<description><![CDATA[The reverse horizontal scrolling problem is due to some old compatibility quirk on Apple's mouse that was using reversed scroll, and the problematic code is still there in newer kernels. See the bug: 291408.
If your mighty mouse scroll ball is horizontally reversed, it can be solved in this way:

- open file /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/did
- change yy:yy:yy:yy::yy:yy 0002 [...]]]></description>
			<content:encoded><![CDATA[<p>The reverse horizontal scrolling problem is due to some old compatibility quirk on Apple's mouse that was using reversed scroll, and the problematic code is still there in newer kernels. See the bug: <a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/291408">291408</a>.</p>
<p>If your mighty mouse scroll ball is horizontally reversed, it can be solved in this way:</p>
<pre>
- open file /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/did
- change yy:yy:yy:yy::yy:yy 0002 05AC 030C 0200
       into yy:yy:yy:yy::yy:yy FFFF 0000 0000 0000
- reboot
</pre>
<p>Original <a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/291408/comments/17">link</a>.</p>
<p>When/If the kernel will be patched to correctly address horizontal scrolling, you can restore back the original values, or you may choose to keep a backup for that file.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/09/01/mighty-mouse-reverse-horizontal-scrolling-workaround-on-ubuntu-linux-904/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Skype 2.1.0.47 beta released, and  amd64 packages available!</title>
		<link>http://it.newinstance.it/2009/08/31/skype-21047-beta-released-and-amd64-packages-available/</link>
		<comments>http://it.newinstance.it/2009/08/31/skype-21047-beta-released-and-amd64-packages-available/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:15:09 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
	<category>Software</category>
	<category>Mac</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/08/31/skype-21047-beta-released-and-amd64-packages-available/</guid>
		<description><![CDATA[Since the 24th of August a new beta of Skype is available.
Some little look and feel changes, contact groups support, nothing really new, except for the native 64bit support. And I hope it will be more stable.
Download it from here: http://www.skype.com/download/skype/linux/
I updated it because the old 32bit version recently is very unstable on my system. [...]]]></description>
			<content:encoded><![CDATA[<p>Since the 24th of August a new beta of Skype is available.</p>
<p>Some little look and feel changes, contact groups support, nothing really new, except for the native 64bit support. And I hope it will be more stable.</p>
<p>Download it from here: <a href="http://www.skype.com/download/skype/linux/">http://www.skype.com/download/skype/linux/</a></p>
<p>I updated it because the old 32bit version recently is very unstable on my system. Maybe due to some library and kernel update from Ubuntu. </p>
<p>After the update you'll need to reconfigure sound settings. And you know how tricky is it on Linux... but with some luck was quite easy on my macbook pro 5.1 running ubuntu: select "HDA NVidia, ALC885 Analog Front speakers (front:CARD=NVidia, DEV=0)" as device for everything, and if you have a system like mine it <em>could</em> work <img src='http://it.newinstance.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . Good luck!
</p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/08/31/skype-21047-beta-released-and-amd64-packages-available/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Linux RAM Disks</title>
		<link>http://it.newinstance.it/2009/08/28/linux-ram-disks/</link>
		<comments>http://it.newinstance.it/2009/08/28/linux-ram-disks/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 15:18:11 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
		
	<category>Linux</category>
		<guid isPermaLink="false">http://en.newinstance.it/2009/08/28/linux-ram-disks/</guid>
		<description><![CDATA[Ram disks are virtual disks that use RAM as super fast storage, with the "side effect" that they are not reboot persistent. Modern computers have a lot of RAM, and sometime one may need a super fast disk storage of a limited size to speed up some disk intensive tasks. On Linux you can mount [...]]]></description>
			<content:encoded><![CDATA[<p>Ram disks are virtual disks that use RAM as super fast storage, with the "side effect" that they are not reboot persistent. Modern computers have a lot of RAM, and sometime one may need a super fast disk storage of a limited size to speed up some disk intensive tasks. On Linux you can mount some ram into a folder, and this is very convenient for transparently using ramfs in places where nobody thought about it before.</p>
<p>My little quick reference:</p>
<p>Mount ramfs to a folder</p>
<pre>
$ sudo mount -t ramfs /dev/ram0  ~/tmp/ram
</pre>
<p>Remeber to chown and chmod to specify access permissions</p>
<p>Verify mounted ram disks (to check availability)</p>
<pre>
$ mount | grep ram
</pre>
<p>Check ramdisk details</p>
<pre>
$ sudo tune2fs -l /dev/ram0
</pre>
<p>And this is how the RAM disk will look like on your Ubuntu desktop once mounted:<br />
<img id="image383" src="http://en.newinstance.it/wp-content/uploads/2009/08/ramdisk.thumbnail.png" alt="Ram Disk" /></p>
<p>References:<br />
<a href="http://www.vanemery.com/Linux/Ramdisk/ramdisk.html">Linux Ramdisk mini-HOWTO</a><br />
<a href="http://www.vanemery.com/Linux/Ramdisk/ramdisk-kerneldoc.txt">Using the RAM disk block device with Linux</a></p>
]]></content:encoded>
			<wfw:commentRSS>http://it.newinstance.it/2009/08/28/linux-ram-disks/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
