External hard drive setup in Linux
Let's start with a few pre-statements:
1) I am using Mandrake 10.1 Community, this guide is based on that but should work on any distro.
2) I am using an external drive enclosure that is pretty generic and uses both a Firewire and a USB 2.0 interface. The choice is left to the user. I tried both and they work the same. In this enclosure I installed a 80GB Maxtor IDE 7200rpm IDE drive.
3) The guide is based both on my personnal ''hair ripping' acquired experience and also from me reading extensively on the subject around the Web.
Now here we go:
Fact: Linux partitionning tools, Command line or graphical, like DiskDrake are wonderful but THEY DO NOT LIKE EXTERNAL DRIVES OF ANY KIND when it comes to formating. Just remember that.
So... that means do not try to partition your external drive with them. It most probably won't work and you'll get errors.
First thing first...we need to get around that problem and partition our drive from somewhere else. I personnaly keep a Windows XP on dual boot to play games and give support to my Microshaft user friends and family members, so I booted into XP, my disk was connected with its Firewire cable and was detected on boot. I then used Partition Magic 8.0 to format my external drive in 2 separate partitions, one primary and one logical. I formated both in fat32 and chose not to assign any drive letters. (any good partioning software will do, you can even use the partitonning tool of Windows XP/2K located in admistrative tools)
Fact: Fat32 filesystem instead of ext3 or ReiserFs or any other makes your drive portable and compatible with any operating system because both Linux and Windows read and write fat32. (Linux only reads NTFS reliably and the writing is shaky at best. As for Windows, it doesn't read or write any unix filesystems)
If you don't dual boot Windows, the only alternative I see if you have an enclosure like me with an IDE drive is to take out the drive, plug it in one of your internal IDE ports, boot Linux, mount it and format it with DiskDrake or the command line. After , put it back in it's enclosure and go on with this guide.
If all is well and it should, when you boot Linux , you should see with the disk utility of your distro, in my case DiskDrake, that your external drive as been detected. It will most likely show up with your other harddisks as SDA. In my case on SDA I found 2 partitions named SDA1 and SDA5.
We want to mount these partitions so before we do, we create directories for each partitons. I created /bak1 and /bak2 in my /home directory, but anywhere will do. I used my /home directory because everything in it can be modified by me,the user. Use simple and short names without spaces.
Now the next step is the one that many user miss or don't do properly that makes all the difference between your external drive working or mot.
Log in as root and open the file 'fstab' that is located in /ETC with an editor like Kwrite.
Here we are going to setup the mounting properties of our external drive and fstab is the confifg file that does that. (a great simple guide to learn about fstab here: http://www.tuxfiles.org/linuxhelp/fstab.html#what
Fstab is a simple text file.
Her is a copy of my fstab and the lines that have to be added:
/dev/hda5 / ext3 defaults 1 1
Here are the 2 lines in my case: (the spaces are just to outline them)
/dev/sda1 /bak1 vfat noauto,user,rw,exec,sync 0 0
/dev/sda5 /bak2 vfat noauto,user,rw,exec,sync 0 0
none /dev/pts devpts mode=0620 0 0
/dev/hdc3 /home ext3 defaults 1 2
/dev/hdb /mnt/cdrom auto umask=0,user,iocharset=iso8859-1,codepage=850,noauto,ro,exec,users 0 0
/dev/hde /mnt/cdrom2 auto umask=0,user,iocharset=iso8859-1,codepage=850,noauto,ro,exec,users 0 0
none /mnt/floppy supermount dev=/dev/fd0,fs=ext2:vfat,--,umask=0,iocharset=iso8859-1,sync,codepage=850 0 0
/dev/hda1 /mnt/win_c ntfs umask=0,nls=iso8859-1,ro 0 0
/dev/hdc5 /mnt/win_c2 ntfs umask=0,nls=iso8859-1,ro 0 0
/dev/hdc6 /mnt/win_d ntfs umask=0,nls=iso8859-1,ro 0 0
none /proc proc defaults 0 0
/dev/hdd1 /shared ext3 defaults 1 2
none /tmp tmpfs defaults 0 0
/dev/hda6 /video_1 ext3 defaults 1 2
/dev/hdc4 /video_2 ext3 defaults 1 2
/dev/hdc2 swap swap defaults 0 0
If we take apart one of those lines (they are both almost identical) :
/dev/sda1 /bak1 vfat noauto,user,rw,exec,sync 0 0
It means mount /dev/sda1 to directory /bak1 witch is formated as fat32 (vfat), do not automount it on boot (noauto), allow users to mount it (user), allow read and write (rw), allow programs to be executed on it (exec), alllow operations on the media to be without delay (sync) . the 2 numbers at the end I won't get into, leave them like they are. They are related to filesystem check and integrity. (I suggest you read the guide I suggested above, it will make you understand a lot, trust me!)
After this, save the file and reboot. One or more icons should then be on your desk after reboot, links to your external drive. Right click on the icon(s) and choose' mount' . After that you will be able to read and write to them.
Notes : I dont't suggest that you automount your external drive, because automounting USB2.0 and Firewire, in my opinion is not stable enough. I could then keep your system from booting. If that ever happens you will have to boot in failsafe mode to console and edit the fstab file with an console editor like VI or VIM or the like and remove the line related to your ext. drive before you reboot. Another reason for not automounting is that ususaly an external drive, as in my case, is used for backup purposes and you want to keep your backups away from snoops, viruses , trojans or malicious users, even if those are pretty rare in Linux, ;-). It should be noted that I have never experienced a boot problem related to this myself.
Also I have read that some external drives (not enclosures) may not be compatible with Linux, but I don't see this as being true because USB and Firewire are both standard protocols supported by the newer Linux kernels.
Recap of all this:
1) Use Windows to partition your drive as you see fit in fat32.
2) Boot Linux and go check if your external drive as been detected, it will moslty be called SDA.
3) Create directories for each partitions you want to mount. Create them in /MNT or in /HOME. Use simple and short names without spaces.
4)Add the proper lines in your fstab config files
5) Reboot the system, (not just the session)
6) One or many icons of your external drive corresponding to each partition described in the fstab file should be on your desktop. Right click them and choose 'mount'. You will then be able to read and write to them.
Good luck to all of you open source maniacs out there!!!