The time now is Sun 01 Feb 2015, 15:55
All times are UTC - 4
Joined: 06 Dec 2006
Location: Queensland, Australia
|Posted: Tue 29 Jun 2010, 21:56 Post subject:
mounting external drives and flash drives the easy way
Subject description: use disk labels... except they don't work by default in Puppy... here's how to fix it
I got fed up with the almost random way external drives' device names are assigned in Linux. It makes it very difficult to run scripts to do automated jobs on those drives because you have to be very careful that it is talking to the correct device -- a problem when the device name changes in different sessions.
When I used to use the Amiga (I still do from time to time) I could refer to drives via their device names, but it was simpler and easier to use a human-oriented label. That way the machine found the correct drive no matter where it was plugged in. I felt sure Linux must have such a capability. It does, but for some reason almost nobody seems to use it.
It is a special problem in Puppy because the mount command uses busybox by default. I've had a lot of problems with busybox in the past and have come to detest it. Oddly, Puppy also contains the full mount command (as mount-FULL) and this is how we can fix it.
NOTE: In the examples below I use my own external drive formatted to ext3 format, on /dev/sdb1 and my own label wd00. You should substitute your own particular device, its format, and a label of your own choosing. I find writing it this way is easier for people to follow.
I mounted the drive for a moment to check its device address first. Once I knew that I unmounted it again. You can use pmount to get that info without mounting and unmounting anything though.
Now that I know where the drive is connected, I can label it:
NOTE: e2label can't be used on vfat or ntfs drives. I don't know what command to use in that case. I'll add an item here when I find out.
|e2label /dev/sdb1 wd00 |
Next I verified the labelIt returned this:
Be careful to note the format of your drive (commonly ext2/ext3/ext4 for linux, or vfat/ntfs for MSWindows -- thumbdrives generally come preformatted to vfat). You can reformat external hard drives or thumbdrives using gparted, which also lets you label them. Note that e2label labels drives and partitions without problem, but gparted wants to delete the partition's contents in order to do so (at least in older versions).
|/dev/sdb1: UUID="f3683b08-4b9b-4dc0-8a7a-817f40ce8dfe" SEC_TYPE="ext2" TYPE="ext3" LABEL="wd00" |
Make a folder somewhere convenient. Use the command line or right-click the filelist in rox to make a new directory. (I choose to put it in /mnt, though you can use / if you want, and I notice Ubuntu has started using a new place called /media for mounting usb drives.) It can be named whatever I want, but it's best to give it the same name as the disklabel to simplify matters
Now I can mount the drive by its label instead of the device name, but I can't use the normal Puppy "mount" because it uses busybox's mount, which doesn't recognise disklabels. Fortunately, as I mentioned earlier, Puppy also includes the full version of mount called appropriately, mount-FULL. Why doesn't Puppy use the full mount instead of busybox's broken one? I don't know. Can anybody answer this for me? Anyway, now I can mount the drive like this:
|mount-FULL -t ext3 -L wd00 /mnt/wd00 |
Now I can easily access the drive by its label no matter what its device name:Yay!
One problem remains though. I'd like the drive to be recognised automatically without having to give the long mount command every time I want to mount it. This requires adding an entry in the /etc/fstab file. Here is the line I added for mine:
You will need to read up on fstab to understand all the possibilities, but the LABEL=wd00 is obvious -- substitute whatever label you choose, then for the next part /mnt/wd00 substitute where you choose to mount it. The next bit gives the format type of the drive -- mine is ext3. You can give auto here and it should autodetect the type, but be careful, because if it is vfat it will try to mount it as old-style fat without long filenames, which is annoying, so if vfat you'll have to specify vfat.
|LABEL=wd00 /mnt/wd00 ext3 defaults 0 0 |
Now I have to change Puppy's mount command to be able to use labels. This is pretty easy because in Puppy it is actually a script. You can do it one of 2 ways:
In case of problems make a backup of the mount script (call it mount-script). Load /bin/mount into a text editor (e.g. geany). Do not use a word processor! I edited the 3 places (two near the beginning and one near the end of the file) that refer to busybox so instead of saying busybox mount it says mount-FULL. The 3 lines I changed are:
So now they look like
|[ ! $1 ] && exec busybox mount
busybox mount $@
busybox mount -r -t ntfs $CMDPRMS
(I'm not sure if that last line should be changed, but I don't have any ntfs drives so am unable to test it.)
|[ ! $1 ] && exec mount-FULL
mount-FULL -r -t ntfs $CMDPRMS
(My preferred choice.) If you don't have any Microsoft Windows ntfs drives you could simply rename the mount script as mount-script and make a link to mount-FULL called mount (easiest way is to right-click on mount-FULL, choose Link from the popup menu and call it mount). Now Puppy will use the proper mount program which avoids the mess of editing the mount script, but loses the nice ntfs handling done by Puppy programmers. It may still work fine with ntfs, but as I mentioned, I don't have any ntfs drives so can't test it.
Now after the change to fstab and the mount command I can simply click on the icon /mnt/wd00 and it will mount and open the disk no matter what USB port it is connected to. I've dragged the icon to my desktop for convenience.
I know it sounds like a lot to do, but that's only because I've discussed in detail each step. If you are advanced then it is simply a matter of
* giving your drive a label with e2label <device> <label>
* making a mount-point for the drive, perhaps in /mnt/<label>
* mounting the drive using mount-FULL -t <format-type> -L <label> <mount-point>
adding a line in fstab, in which case /bin/mount must be altered to use the proper mount command instead of busybox.
A life! Cool! Where can I download one of those from?
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Powered by phpBB © 2001, 2005 phpBB Group