Problems Mounting Drives Under Linux

Lately I have not being having much luck with mounting external usb drives in my Ubuntu 8.04 install. All that seems to happen, is that the drive will appear under “computer” but that is about as far as it goes. When I click on the external drive it just errors and does not open. So a solution that I discovered on the net uncovered part of the solution but I will attempt to put it together for you ๐Ÿ˜‰ .

First of all you have to work out where you drive is mounted and what it is called. Under the Ubuntu distro, they are located under eg. /dev/sdb or something similar to that. The only thing that will change is the letter on the end. If you are not sure of which one you external drive is, you can unplug the drive then run this command :

ls -la | grep sd

Then plug the drive back in and run that same command to see what drive appears. This will tell you what the drive identifier is. Another way you might be able to find this information is by running the command :

dmesg | tail -n 50

This command will show you the tail end of the error message log, so from this you may also be able to determine what the drive identifier is from the message :

[ 2159.443365] FAT: bogus number of reserved sectors
[ 2159.443371] VFS: Can't find a valid FAT filesystem on dev sdb1.
[ 2159.488509] FAT: bogus number of reserved sectors
[ 2159.488515] VFS: Can't find a valid FAT filesystem on dev sdb1.
[ 2159.661736] FAT: bogus number of reserved sectors
[ 2159.661742] VFS: Can't find a valid FAT filesystem on dev sdb1.

As you can see from this message, it is telling me that it is trying to mount my drive as a VFAT system which is incorrect as it is actually NTFS. Now that this has identified my problem I can run a few commands to see if I can get it mounted. First I will make sure it is unmounted before I try to remount the file system:

sudo umount /dev/sdb1
umount: /dev/sdb: not mounted

That was just telling me that is was not already mounted, now I will create a directory for the file system to be mounted into. This can be anywhere you like but the standard spot in ubuntu is “/media/”. So next I run the command :

sudo mkdir -p /media/external_drive

Then if I am lucky all I have to do is mount the drive using :

sudo mount -t ntfs /dev/sdb1 /media/external_drive

Now you should be able to navigate to the folder you just created and view/edit the contents of the drive. If this still failed, try running the original dmesg command and see if you can track down what the problem is.

Normalizing Your Music

Listening to un-normalized music can be a painfull thing, considering one second it will be a normal volume and the next you will be deaf :omg . Anyway, I had a bit of a look on the net for a solution and by using Mp3Gain this is actually a pretty simple solution to fix.

Basically, Mp3Gain has the ability to normalize the volumes of all music without actually editing the mp3 files. It does this by analysing the levels and applying tags to the files which lets the player know how much to increase/decrease the volumes. The good thing is that it can do this over albums, to make the files pretty generic in their levels. Another good thing is that this can be done with a one liner ๐Ÿ˜‰ . First install then run:

sudo apt-get install mp3gain
find . -iname '*.mp3' -execdir mp3gain -a -k "{}" + &

What that command is doing :

    find . -iname โ€˜*.mp3โ€ฒ
  • searches for all mp3 files.
  • -execdir
  • executes the command on a directory basis.
  • "-a"
  • tells mp3gain to use Album gain instead of Track gain (very important!)
  • "-k"
  • tells mp3gain not to increase the volume with no distortion.

For windows users this is a lot simples considering all you have to do is open the gui and tell it to run! ๐Ÿ˜› .

Using Oracle Regular Expressions

Something a little more simple this time, or so i thought ๐Ÿ˜‰ . Anyway, what I was trying to do was convert the first letter of every word into uppercase and the rest into lowercase. Immediatly I thought this would be a job for Oracle Regex. I started to have a look at some of the documentation and slowly noticed that this might not even be possible by directly using regular expressions, or more specifically, Oracle’s implementation of them.

Basically, the problem was that there are only 4 types that can be used and they are seperated info functions:


More info on this from the earlier link!!

To cut a long story short, oracle has not implemented all of the functionality of regular expressions, that is available to os’s like linux/unix. So my thought of just using regex_replace and doing an uppercase on the first letter group could not be done. However, there is a function provided by oracle which will do that automatically with no regex :

SELECT INITCAP('don talbert jones') FROM DUAL;

This solved my initial problem of uppercasing the names, but I was thinking what if you wanted to do something more complicated like initcap the names and re-arange as well:

                 (INITCAP (str),
                  '5, 1 3'
  FROM (SELECT 'first middle last' str FROM DUAL)

This will work for strings that are names only and no special characters eg “hyphen”. A more robust approach would be :

SELECT REGEXP_REPLACE( INITCAP (str), '([^a-zA-Z]*)([a-zA-Z]{1})([a-zA-Z]*)([^a-zA-Z]*)', '1' || '2' || '3' || '4' )  RESULT
FROM (SELECT '-,riyaz ahm:ad khan' AS str FROM DUAL)

This is the breakdown of what this version will be doing:

  • Search for anything that is not a character and any number of them: ([^a-zA-Z]*)
  • Followed by a single character: ([a-zA-Z]{1})
  • Then any character and any number of them: ([a-zA-Z]*)
  • Finally, anything other than a character and any number of them: ([^a-zA-Z]*)

These groupings represent the groupings in order from 1-4, so if you wanted to change the order of the characters or even remove the non characters then you would just manipulateย  the numbers.

Overall, I am a little disappointed that the functions like U “convert uppercase” was not included in the original implementation but all I can do is winge ๐Ÿ˜‰ .