Formatting an External Hard Disk with Ext4

Recently, I bought an external hard disk formatted with NTFS. Not that there is something really wrong with NTFS but I prefer using ext4.

First, I deleted the existing partition and created a new Linux partition using fdisk:

# fdisk /dev/sdb

Assuming /dev/sdb is the external hard disk. Use d to delete the partition and use n to create a new partition. 83 is the ID of the native Linux partition.

Them, I use mkfs.ext4 to format the partition with ext4:

# mkfs.ext4 /dev/sdb1

Note that mkfs.ext4 expects a partition as its argument.

Finally, I use tune2fs to adjust some parameters:

# tune2fs -m 0 /dev/sdb1
# tune2fs -L bakap01 /dev/sdb1

The -m option is for adjusting the percentage of reserved blocks. The reserved blocks are used by privileged processes which is by default 5% of the hard disk size. Since I’m using the external hard disk solely as a storage, I set this to 0 so I can also use those 5% for storage. The -L option is for labeling the filesystem.

Adding an Ubuntu Repository Key Behind a Firewall

When you want to add an Ubuntu PPA repository using add-apt-repository and you’re behind a firewall. more often than not, you will receive a nasty error saying “Error reading <some PPA URL here>: <urlopen error [Errno 111] Connection refused>“. And when you tried to install something, you will get a GPG warning.

What happened is that add-apt-repository failed to download the keys of the PPA repo because the PPA key server uses 11371 as its port which is usually blocked when you’re behind a firewall. To solve this, you need to find the PPA repo key manually. For example, the key in https://launchpad.net/~bzr/+archive/ppa is 8C6C1EFD. It can be found under the “Signing key” when you click “Technical details about this PPA”. Only the numbers and letters after the slash are considered.

After finding the key of the PPA repo, just execute this command:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys <the key here>

You will not be bothered again by a GPG warning when installing from the PPA repo. This is tested using Ubuntu 10.04 (Lucid Lynx).

Enabling Nvidia Legacy Driver on Ubuntu 10.10

The release of X.Org Server 1.9 brought upon an incompatibility issue with the legacy driver of Nvidia (nvidia-96 package in Ubuntu) resulting in a non-working driver which forces users to use the nv or the nouveau driver. While the mentioned two drivers do work, 3D support is not good. Fortunately (unfortunately?), the legacy driver has now been updated.

To enable the legacy driver on Ubuntu 10.10 (Maverick Meerkat), add the maverick-proposed repository in /etc/apt/sources.list:

deb http://jp.archive.ubuntu.com/ubuntu/ maverick-proposed restricted main multiverse universe

Then, update the package listing:

$ sudo apt-get update

Then, install the driver by going to System->Administration->Additional Drivers.

Reboot and enjoy.

Converting WAV to MP3 using LAME

If you have a bunch of .wav files, say from ripping a CD, and want to convert it to .mp3, here is a simple way to do it using LAME.

$ for i in *.wav; do basename=`basename "$i" .wav`; `lame --preset insane "$i" "$basename".mp3`; done

Inside the for loop that iterates through all .wav files, we execute two commands. First is the “basename” command which let us extract the file name minus its extension. For example, “Track 01.wav” will become “Track 01″. We will use this in the output file name of LAME. The second command is “lame” which does the converting from .wav too .mp3. We set the preset option to insane. Other options can be found by running “lame –preset help” in the command line. The first parameter is just the .wav file name given by “$i” and the second parameter is the extracted file name from the “basename” command earlier appended by “.mp3″ since the output file we are expecting is a .mp3 file.

That’s it. Run the command, wait, and enjoy.

Creating PostgreSQL Database with a Different Encoding

To create a database in PostgreSQL with a different encoding, let’s try doing this:

postgres=# CREATE DATABASE db ENCODING 'LATIN9';

But an error will occur.

ERROR:  encoding LATIN9 does not match locale en_PH.utf8
DETAIL:  The chosen LC_CTYPE setting requires encoding UTF8.

So let’s try creating with a template. By default, the template used in creating database is template1. Let’s try template0 instead.

postgres=# CREATE DATABASE db ENCODING 'LATIN9' TEMPLATE template0;

But the same error as last time happened.

Let’s try adding more options like LC_COLLATE and LC_CTYPE. The values for these two options can be derived by doing this in the terminal.

$ locale -a

Here are the results.

C
en_AG
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_NG
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX

Let’s try C since en_XX.utf8 gives us the error.

postgres=# CREATE DATABASE db ENCODING 'LATIN9' TEMPLATE template0 LC_COLLATE 'C' LC_CTYPE 'C';

And yes, the database is successfully created. Yay!

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding | Collation  |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 db        | postgres | LATIN9   | C          | C          |
 postgres  | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 |
 template0 | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | =c/postgres
                                                           : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | =c/postgres
                                                           : postgres=CTc/postgres
 test      | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 |
(5 rows)

This is tested on Ubuntu 10.04 (Lucid Lynx).

Installing Sun … Oracle Java on Ubuntu 10.04

To install Sun … Oracle Java on Ubuntu 10.04, simply uncomment the following lines from /etc/apt/sources.list.

#deb http://archive.canonical.com/ubuntu lucid partner
#deb-src http://archive.canonical.com/ubuntu lucid partner

Then do a sudo apt-get update and sudo apt-get install sun-java6-jdk and you’re ready to go.

In previous versions of Ubuntu, Sun … Oracle Java is in the multiverse repository, I think. So this can confuse borap people like me.

Sun Broadband on Ubuntu 10.04

If you are using Sun Broadband Wireless (tested on Huawei E1550) and want it to work on Ubuntu 10.04 (Lucid Lynx), just install the linux-backports-modules-headers-lucid-generic package and the usb-modeswitch package.

$ sudo apt-get install linux-backports-modules-headers-lucid-generic usb-modeswitch

After installing, reboot.

Plug in the Sun Broadband. Then, a notification “New Mobile Broadband Connection” should appear. Follow the wizard dialog (you can just click next since the default values should be alright). Then, you should be connected now. Yay!

Thanks to kuya JM!

CodeIgniter Email Preferences When Using Gmail As Mail Server

If you are developing web applications using CodeIgniter and you need to test an email feature but you don’t have a mail server, you can use your Gmail account or you can create a Gmail account specifically for your testing needs. You can then use the following preferences to successfully send an email using Gmail in your CodeIgniter applications.

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'username@gmail.com';
$config['smtp_pass'] = 'password';
$config['smtp_port'] = 465;
$config['newline'] = "\r\n";

Make sure to replace username with your real username and password with your real password.

Changing Yahoo! Profiles in Yahoo! Groups

Let’s have the following scenario:

  • user has two Yahoo! Profiles: ilovegoogle and iloveyahoo
  • user belongs to several Yahoo! Groups using the iloveyahoo profile
  • user wishes to transfer her membership to several groups from iloveyahoo to ilovegoogle

Here are the steps to follow:

  1. Make sure that both ilovegoogle and iloveyahoo profiles have the same primary email address say, emailaddress@gmail.com. You can verify it by logging in to Yahoo! and visiting http://profiles.yahoo.com/. It’s under Account Info.
  2. Make sure that all group messages are being sent to the primary email address, emailaddress@gmail.com. Verify by visiting http://groups.yahoo.com/mygroups. All email addresses under the Email Address column should be emailaddress@gmail.com.
  3. Sign in as ilovegoogle. This is the profile which is in the receiving end of the transfer.
  4. Visit a group where iloveyahoo is a member and click the Join This Group! button.
  5. A page will be presented and somewhere there is a text which reads “The following email addresses from Account Info are not available for this membership: emailaddress@gmail.com (Already a member with another Yahoo! ID. Edit this Membership)”
  6. Click the Edit this Membership link and another page will be presented.
  7. Click the Save Changes button. Be aware that iloveyahoo can no longer access the membership transferred to ilovegoogle.
  8. Repeat until all memberships have been transferred.

I think that’s it. If something is wrong, please notify me.