Tuesday Mar 25, 2008

Automatic opening a USB disk on Sun Ray

One of my users today had a bit of a hissy fit today when she plugged in her USB thumb drive into the Sun Ray and it did nothing. That is it did nothing visible. Behind the scenes the drive had been mounted somewhere but there was no realistic way she could know this.

So I need a way to get the file browser to open when the drive is inserted. A quick google finds " "USB Drive" daemon for Sun Ray sessions" which looks like the answer. The problem I have with this is that it polls to see if there is something mounted. Given my users never log out this would mean this running on average every second. Also the 5 second delay just does not take into account the attention span of a teenager.

There has to be a better way.

My solution is to use dtrace to see when the file system has been mounted and then run nautilus with that directory.

The great thing about Solaris 10 and later is that I can give the script just the privilege that allows it to run dtrace without handing out access to the world. Then of course you can then give that privilege away.

So I came up with this script. Save it. Mine is in /usr/local which in turn is a symbolic link to /tank/fs/local. Then add an entry to /etc/security/exec_attr, subsisting the correct absolute (ie one with no symbolic links in it) path in the line.

Basic Solaris User:solaris:cmd:::/tank/fs/local/bin/utmountd:privs=dtrace_kernel

This gives the script just enough privileges to allow it to work. It then drops the extra privilege so that when it runs nautilus it has no extra privileges.

Then you just have to arrange for users to run the script when they login using:

pfexec /usr/local/bin/utmountd

I have done this by creating a file called /etc/dt/config/Xsession.d/utmountd that contains these lines:

pfexec /usr/local/bin/utmountd &
trap "kill $!" EXIT

I leave making this work for uses of CDE as an exercise for the reader.

Thursday Dec 06, 2007

Unable to mount the device? dtrace tells me why.

I had to copy a large movie file1 to work so rather then battle the corporate firewall, or pack my laptop in my pannier, I though I would just load it onto the USB pen drive I got at CEC.

When I inserted the pen drive instead of nautilus poping up with the contents I got a pop-up saying:

Unable to mount volume 'NO NAME'

No clue why though. A quick dtrace:

1192 # dtrace  -n 'syscall::mount:entry { printf("%s %s %s", copyinstr(arg0),>
dtrace  -n 'syscall::mount:entry { printf("%s %s %s", copyinstr(arg0), copyinstr(arg1), copyinstr(arg3)) } syscall::mount:return { printf("%s %d %d", execname, (int) arg1, errno) }'
dtrace: description 'syscall::mount:entry ' matched 2 probes
CPU     ID                    FUNCTION:NAME
  0  98800                      mount:entry /dev/dsk/c5t0d0p0:1 /media/NO NAME pcfs
  0  98801                     mount:return mount -1 30

and we have the answer. Who ever is calling mount assumes the file system is read-write but fails to try read-only when the mount fails. Flicking the switch on the side of the pen drive to read-write, something I was going to need anyway and reinserting it and I was away. Working out before dtrace would have been horrible this was so quick to do that it did not interfere with my breakfast.

Now I have to file the bug.

1The file was my first attempt at recording a presentation using http://www.screencast-o-matic.com/ from which I learned a number of things. First while I can talk to a room full of engineers or even a telephone without needing or wanting any form of script and not stutter or trip over my words when faced with a microphone that is recording I seem to have a problem. Secondly good though screencast-o-matic is it still took me over and hour to record 15 minutes of content and even that content is so bad I'm not putting it on the web. Clearly something I need to work on.

Saturday Apr 07, 2007

recovering my laptop using zfs send and receive

First I owe Windows and apology. It was not making itself the active partition, grub was due to me copying the wrong entry in there after Solaris deleted it.

However before I went on holiday grub decided it would cease working. It could not find the menu.lst at all on this laptop. After a bit of investigation and failing to recover it (due I think to the laptop having two Solaris fdisk partitions, one had the zpool in it and the other the boot partitions, Installgrub and grub itself did not like this, though what pushed it over the edge I'm not sure. Perhaps some change in build 60.)

Anyway I decided to reinstall solaris without the extra fdsik partition which was a hangover from when the system had Linux on it as well. It should be simple. ufsdump the current boot environment (BE) and then install the system and let the zpool resilver from the external USB disk and ufsrestore the BE. The install would only need to be an end user install as I was going to restore from backup anyway. Strictly I did not need to do the install at all. All would have been fine had I not decided to detach the internal disk from the zpool (after scrubing the pool) prior to the install but the install would sort out grub for me without me having to do to much fiddling.

Once I had reinstalled the system I could not attach the new partition to the pool as it was to small. This was all thanks to my “thinking ahead” when I created the USB partition. Since eventually the partition will grow to be 30Gb that was how big the external disk partition was. As soon as I detached the smaller partition it “grew” to fill the partition it had. Doh.

So now I had to fit a 30Gb pool into a 10Gb partition. Next time I won't detach the mirror first! Being in a hurry, to go on holiday, I just knocked together a short script that would take a source file system and using zfs send and zfs receive copy all of it's snapshots to the target file system. So first doing a recursive snapshot of the pool I then ran the script which and copied the file systems into the new pool I created on the laptop. I then had to fix up a few of the attributes of the file systems that were copied. I'm not immediately sure how to handle this in a script since some attributes are obvious (compression, sharenfs etc) but others are less so (mountpoint). Even with attributes like compression you have a problem in that the zfs receive creates the file system with inherited attributes so there is no way to set them before the file system is populated unless the inherited file system attribute is correct. When I say no way, I mean, no simple way. There clearly are ways by using temporary container filesystems which you create with the right options for the file system to inherit and then use zfs rename to move the file system to the correct location. However that was not required by me and would cease to be a simple short script.


Friday Apr 21, 2006

External usb disk drive

If I had not got caught out again by the M2 hanging during boot this would have been a breeze. Instead I was to struggle off and on for hours before finding the answer on my own blog. Doh.

Anyway I have bought a 160G USB 2.0 disk drive so that I can backup my laptops and have some extra space for things that it would be nice to keep but not on the cramped internal drives. Looks like a nice bit of kit in it's fanless enclosure.

Plugged the drive in and pointed zpool at the device as seen by volume manager and I now have a pool that lives on this disk with lots of file systems on it. I can see a need for a script to run zfs backup on each local file system redirected to a file system on the external box.

1846 # zfs list -r removable
removable             20.7G   131G  12.5K  /removable
removable/bike        4.88G   131G  4.88G  /removable/bike
removable/nv           137M   131G   137M  /removable/nv
removable/principia   9.50K   131G  9.50K  /removable/principia
removable/scratch        9K   131G     9K  /removable/scratch
removable/sigma       5.14G   131G  9.50K  /removable/sigma
removable/sigma/home  5.14G   131G  9.50K  /removable/sigma/home
removable/sigma/home/cjg  5.14G   131G   597M  /removable/sigma/home/cjg
removable/sigma/home/cjg/pics  4.55G   131G  4.55G  /removable/sigma/home/cjg/pics
removable/sigma_backup   556M   141G   556M  -
removable/users        586M   131G  9.50K  /removable/users
removable/users/cjg    586M   131G   586M  /removable/users/cjg
1847 #

Exporting the pool and then reimporting it on the other laptop all works as expected which is good and I hope is going to allow me to do the live upgrade from the OS image on that drive so it does not have to get slurped over the internet twice.

I did over achieve and manage to crash one system as plan A was to have a zvol for each laptop on the disk and use that as a backup mirror for the internal drive which could be offlined when not in use. Alas this just hung and appears to be known issue with putting zpools inside zpools. However the talk that USB storage and zfs don't work together does not appear to be close to the truth.



This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com


« August 2016