Device listing

dan_c00per

Registered
Hi,

I need to list all drives attached to my machine, especially the ones that aren't mounted, I came across the command that did it a while ago when I didn't need it, now I do I just can't find it anywhere, can someone refresh my memory?
 
Not sure what you're trying to do here, but I'm guessing maybe diskutil is what you're after.

The catch is that while diskutil, like its GUI counterpart, Disk Utility, can show disks that have been unmounted, it cannot show disks that have been ejected. There's a distinction between having a disk in the filesystem table, and in the mount table. Traditionally, this is something like vfstab/fstab (filesystem table) vs. mnttab (mounts table). With MacOSX, this is all managed by the automounter, so I'm not sure where it keeps knowledge of these states.

The problem is, unmounting a disk in this way seems to require the use of diskutil/Disk Utility in the first place. Dragging the volume to the eject button (on the dock) or hitting CMD+e will eject the disk, making it inaccessable to diskutil. At that point, I don't believe that there is a way to see them. There would need to be a way for them to signal the system that they're there.

For FireWire drives, this can simply be a powercycle or detach/reattach. Neither method is recommended for ATA/SCSI drives though... ;)

(Disclaimer: please don't take my word as gospel here. The question got me curious about it and I've just spent 10 minutes playing with this on my iPod/TiBook to understand the behaviour. If someone has some cunning scheme that would work here, please do tell... :D )
 
I needed it to display the device name of an unmounted firewire drive, I am keeping a drive unmounted as an offline backup, but I need it to re-mount at a certain time and copy the contents of another drive to it and then unmount it.

Finally found that 'disktool -l' worked perfectly with the output piped to grep and awk, I found the device name and mounted the device mounts fine, even if the device name changes in the /dev folder
 
That's cool. I didn't know about disktool -l... But I still don't see my ejected (but still attached) iPod. I'll bet that the iPod is being a little smarter about this, appearing disconnected on the FW bus, than the normal FW drive..

It's a useful trick, though. I just lost 37GB of mp3's to a failed drive last weekend, so I'm thinking about how to do this sort of backup (in addition to mirrored volumes) myself before I start re-ripping everything...
 
We lost 30gb from a crashed RAID at work, we have replaced it with 2 200gb Firewire drives, one online, the other offline backup, I am running a cron task to backup every night with a simple shell-script, here's the script if you need to use it:

#!/bin/sh

DATE=`date +%b%d`
DEVICE=`disktool -l | grep 'Backup' | awk '/disk/{print substr($3, 3, 7); }'`

function exit_error
{
rc=$?
echo "$DATE - ${*}" >> /backup.log
exit
}

mkdir /Volumes/Backup
echo <password> | sudo -S mount -t hfs /dev/$DEVICE /Volumes/Backup || exit_error "Could not mount device"
echo <password> | sudo -S ditto /Volumes/Firewire1/New_RAID /Volumes/Backup || exit_error "Could not backup data"
echo <password> | sudo -S umount /Volumes/Backup || exit_error "Could not unmount backup device"
echo <password> | sudo -S rm -R /Volumes/Backup || exit_error || "Could not remove mount point"
echo "$DATE - Backup ran successfully" >> /backup.log

The Volume name on the offline drive is 'Backup' which is what it search's for in the line near the top

I know this script is not the best written script, if anyone would like to correct it, please feel free
 
Cool! This is exactly the sort of thing I was working on putting together... You just saved me a bunch of work... ;)

Thanks!
 
Originally posted by dan_c00per
We lost 30gb from a crashed RAID at work, we have replaced it with 2 200gb Firewire drives, one online, the other offline backup, I am running a cron task to backup every night with a simple shell-script, here's the script if you need to use it:

#!/bin/sh

DATE=`date +%b%d`
DEVICE=`disktool -l | grep 'Backup' | awk '/disk/{print substr($3, 3, 7); }'`

function exit_error
{
rc=$?
echo "$DATE - ${*}" >> /backup.log
exit
}

mkdir /Volumes/Backup
echo <password> | sudo -S mount -t hfs /dev/$DEVICE /Volumes/Backup || exit_error "Could not mount device"
echo <password> | sudo -S ditto /Volumes/Firewire1/New_RAID /Volumes/Backup || exit_error "Could not backup data"
echo <password> | sudo -S umount /Volumes/Backup || exit_error "Could not unmount backup device"
echo <password> | sudo -S rm -R /Volumes/Backup || exit_error || "Could not remove mount point"
echo "$DATE - Backup ran successfully" >> /backup.log

The Volume name on the offline drive is 'Backup' which is what it search's for in the line near the top

I know this script is not the best written script, if anyone would like to correct it, please feel free


Perhaps and applescript solution may be better?
 
Why Applescript?

The script would be more complex ("tell finder this, tell finder that, tell finder the other thing"), and would not be nearly as flexible, or portable, or fast. In fact, wouldn't an Applescript version of this require that someone be logged in (so that Finder could run)? The shell script can run in a cron job without anyone logged in at all...

Define "better".... :)
 
Back
Top