Wednesday, 4 March 2009

Accessing External Drives on Unix Terminal

My friend just installed OpenBSD on my recommendation, but when he went to copy his music from his external HDD, he found he didn't have a clue what to do, since OpenBSD doesn't have a /media directory or a auto mounter, and Gnome won't show non root drives up until they are manually mounted. So after I shown him how to do it, I decided to write a brief tutorial on it. This technique will probably work on most other Unix OSs around (Including Mac OSes that are based on Mach/BSD) , but it may differ a lot on Linux, since Linux uses a easier system now on most distros.

When typing in commands I give you the commands in quotation marks.... Don't put the quotation marks into the commands =)

Plug in your external drive.
Wait about 6 seconds, for Unix to find and initialize the drive.
Open up a terminal. I doesn't matter which shell it is using.
Type 'dmesg' and press enter.
Look at the bottom of the output 'dmesg' gave you.

When I plugged my iPod Mini in, this is the information 'dmesg' gave me at the bottom.

inumass0 at uhub0 port 1 configuration 1 interface 0 "Apple iPod mini" rev 2.00/0.01 addr 2
umass0: using SCSI over Bulk-Only
scsibus1 at umass0: 2 targets, initiator 0
sd0 at scsibus1 targ 1 lun 0: SCSI0 0/direct removable
sd0: 3906MB, 497 cyl, 255 head, 63 sec, 512 bytes/sec, 7999488 sec total


From reading this, I learned that my iPod was 'sd0'. I gathered this information from the last two lines. It should be similar for you.

Now type 'disklabel XXX'. replace XXX with whatever your drive is called by BSD. For me, it was called 'sd0'. For you it may be different.

Now, you will see the partitions on the drive. You need to spot the partition you want to mount. For example, if you want to access a 40GB iPod, you should probably look for the partition that is using FAT32 and has around 32GB in size. I will show a example below. You may see some partitions that you weren't aware of, don't worry about this.

This is the 'disklabel' output for my iPod.

# size offset fstype [fsize bsize cpg]
c: 7999488 0 unused 0 0
i: 32067 63 unused 0 0
j: 7903980 80325 MSDOS
k: 48195 32130 ext2fs

The partition I payed attention to was 'j:' because it had a large size and it says it is using a MSDOS filesystem (FAT32), which common sense tells me its the partition I want. The reason for the other partitions is due to BSD and hidden partitions on iPods.

So I now know that my iPod is sd0 and the partition I want is 'j'.

Now you need to create a directory to access your drive from. So, if you want it in /home/user/ipod you would have to create that directory by typing 'mkdir -p /home/user/ipod' into the terminal and pressing enter. For this example I created a directory in /mnt/iPod by typing 'mkdir -p /mnt/iPod' into the terminal and pressing enter. Now you have your directory you want to access the drive from.

Now, let's mount the drive.

My iPod is sd0, and I want to mount partition j. I want to mount it into /mnt/iPod. So, this is what I would type.

mount /dev/sda0j /mnt/iPod

This is the syntax...

mount /dev/XY Z

X=The drive name (For me it was sda0)
Y=The partition letter (For me it was j. This comes straight after the drive name with no space)
Z=The directory you want to access the drive from.

So, if I wanted to mount the drive 'hda1' partition 'e', and access it from directory /root/External_HDD I would type this...

mount /dev/hda1e /root/External_HDD

That's it. This should really only be used on servers and stuff. Sane people would install an auto mounter on a workstation PC, making their lives a lot easier. Hope that helped some of you out. =D

0 comments:

Post a Comment