Monday November 16, 2009 | Constantin's Blooog |
|
Useful stuff for your blog-reading pleasure.
All
|
General
Fun With DTrace: The Windows-Key PrankThe current episode of the German HELDENFunk podcast features an interview with Chris Gerhard about one of his favourite subjects: DTrace (in English, beginning at 14:58): After the interview, we hear a guy called "Konteener Kalle" express his love (in German) for DTrace by playing a prank on his boss: Whenever he presses the Windows key (on an OpenSolaris system, mind you), he's punished by watching the XScreensaver BSOD hack (of course not knowing that it's just a screensaver). That little joke challenged me to actually implement this prank. Here's how to do it. The IdeaThe idea of this prank is to start the XScreensaver Blue-Screen-of-Death screensaver (which simulates a Windows crash experience) on an OpenSolaris system whenever the user presses a certain key a certain number of times. This could be the Windows-Key (which doesn't have any real use on an OpenSolaris machine) or any other key. We count the number of key presses and only execute the BSOD after a certain number of key presses in order to make the prank less obvious. Step 1: Identify the Windows (or any other) KeyIf you have a Windows-Keyboard, this is easy: Run xev and press the Windows-Key. Take note of the keycode displayed in the xev output. Of course you can use any other key as well to play this prank. In this case, I'm using the left Control-Key, because I don't have a Windows-Key on the system I'm working on. The Control key has the keycode 37. Step 2: Configure XScreensaver for BSODXScreensaver comes with a great collection of "hacks" that do interesting stuff on the screen when the screensaver activates. Check out the This can be achieved by telling XScreensaver to demo the BSOD hack for us. It will then create a full-screen window and execute the BSOD hack inside the new window. The following command will tell XScreensaver to run a hack for us: xscreensaver-command -demo <number> The Let's put our entry at the top of the list so we can simply use the number "1" to execute the BSOD screensaver. Somewhere in our ... textFile: /etc/motd textProgram: date textURL: http://blogs.sun.com/roller/rss programs: \ - "BSOD Windoze" bsod -root -only nt \n\ - "Qix (solid)" qix -root -solid -segments 100 \n\ - "Qix (transparent)" qix -root -count 4 -solid -transparent \n\ ... You can test this by running Step 3: Write a DTrace Script That Sets Up the TrapNow it gets more interesting. How do we use DTrace to find out when a user presses a certain key? All we know is that the Xorg server processes the keystrokes for us. So let's start by watching Xorg in action. The following DTrace command will trace all function calls within Xorg: pfexec dtrace -n pid`pgrep Xorg`:::entry'{ @func[probefunc] = count(); }'
Let's start it, press the desired key 10 times, then stop it with CTRL-C. You'll see a long list of Xorg functions, sorted by the number of times they've been called. Since we pressed the key 10 times, it's a good idea to look for functions that have been called ca. 10 times. And here, we seem to be lucky: ... miUnionO 8 DeviceFocusInEvents 9 CommonAncestor 10 ComputeFreezes 10 CoreLeaveNotifies 10 key_is_down 11 FreeScratchPixmapHeader 12 GetScratchPixmapHeader 12 LookupIDByType 12 ProcShmDispatch 12 ProcShmPutImage 12 ... The Why do we see "11" and not "10" function calls to This gives us enough knowledge to create the following DTrace script: #!/usr/sbin/dtrace -s
/*
* BSODKey.d
*/
/*
* This D script will monitor a certain key in the system. When this key is
* pressed, a shell script will be executed that simulates a BSOD.
*
* The script needs the process id of the Xorg server to tap into as its
* first argument.
*
* One example of using this script is to punish a user pressing the
* Windows key on an OpenSolaris system by launching the BSOD screen saver.
*/
#pragma D option quiet
#pragma D option destructive
BEGIN
{
ctrlcount = 0;
keycode=37
}
pid$1::key_is_down:entry
/arg1 == keycode/
{
ctrlcount ++;
}
pid$1::key_is_down:return
/ctrlcount == 10/
{
ctrlcount = 0;
system("/usr/bin/xscreensaver-command -demo 1");
}
First, we need to enable DTrace's destructive mode (ever heard of a "constructive prank"?) otherwise we can't call the pfexec ./BSODKey.d `pgrep Xorg` It then sets up a probe that fires whenever After hitting the Control-Key 10 times, we're rewarded with our beloved BSOD:
ConclusionThat wasn't too difficult, was it? Yes, one could have done the same thing by writing a regular script that taps into So, have fun with this script and let me know in the comments what kind of pranks (or helpful actions) you can imagine with DTrace!
"Fun With DTrace: The Windows-Key Prank" has been brought to you by Constantin's Blooog.
This entry was created on 2009-11-16 08:32:14.0 PST and is associated with the following tags:
bsod
dtrace
fun
heldenfunk
scripting
windows
VirtualBox and ZFS: The Perfect TeamI've never installed Windows in my whole life. My computer history includes systems like the Dragon 32, the Commodore 128, then the Amiga, Apple PowerBook (68k and PPC) etc. plus the occasional Sun system at work. Even the laptop my company provided me with only runs Solaris Nevada, nothing else. Today, this has changed. A while ago, Sun announced the acquisition of Innotek, the makers of the open-source virtualization software VirtualBox. After having played a bit with it for a while, I'm convinced that this is one of the coolest innovations I've seen in a long time. And I'm proud to see that this is another innovative german company that joins the Sun family, Welcome Innotek! Here's why this is so cool.
After having upgraded my laptop to Nevada build 82, I had VirtualBox up and running in a matter of minutes. OpenSolaris Developer Preview 2 (Project Indiana) runs fine on VirtualBox, so does any recent Linux (I tried Ubuntu). But Windows just makes for a much cooler VirtualBox demo, so I did it: After 36 years of Windows freedom, I ended up installing it on my laptop, albeit on top of VirtualBox. Safer XP if you will. To the top, you see my VirtualBox running Windows XP in all its Tele-Tubby-ish glory. As you can see, this is a plain vanilla install, I just took the liberty of installing a virus scanner on top. Well, you never know... So far, so good. Now let's do something others can't. First of all, this virtual machine uses a .vdi disk image to provide hard disk space to Windows XP. On my system, the disk image sits on top of a ZFS filesystem:
Cool thing #1: You can do snapshots. In fact I have two snapshots here. The first is from this morning, right after the Windows XP installer went through, the second has been created just now, after installing the virus scanner. Yes, there has been some time between the two snapshots, with lots of testing, day job and the occasional rollback. But hey, that's why snapshots exist in the first place. Cool thing #2: This is a compressed filesystem:
ZFS has already saved me more than half a gigabyte of precious storage capacity already! Next, we'll try out Cool thing #3: Clones. Let's clone the virus free snapshot and try to create a second instance of Win XP from it:
The clone has inherited the mountpoint from the upper level ZFS filesystem (the winxp one) and so we have everything set up for VirtualBox to create a second Win XP instance from. I just renamed the new container file for clarity. But hey, what's this?
Damn! VirtualBox didn't fall for my sneaky little clone trick. Hmm, where is this UUID stored in the first place?
Ahh, it seems to be stored at byte 392, with varying degrees of byte and word-swapping. Some further research reveals that you better leave the first part of the UUID alone (I spare you the details...), instead, the last 6 bytes: 845c3a0e1c8d, sitting at byte 402-407 look like a great candidate for an arbitrary serial number. Let's try changing them (This is a hack for demo purposes only. Don't do this in production, please):
Who needs a hex editor if you have good old friends od and dd on board? The trick is in the "
Heureka, it works! Notice that the second instance is running with the freshly patched harddisk image as shown in the window above. Windows XP booted without any problem from the ZFS-cloned disk image. There was just the occasional popup message from Windows saying that it found a new harddisk (well observed, buddy!). Thanks to ZFS clones we can now create new virtual machine clones in just seconds without having to wait a long time for disk images to be copied. Great stuff. Now let's do what everybody should be doing to Windows once a virus scanner is installed: Install Firefox:
I must say that the performance of VirtualBox is stunning. It sure feels like the real thing, you just need to make sure to have enough memory in your real computer to support both OSes at once, otherwise you'll run into swapping hell... BTW: You can also use ZFS volumes (called ZVOLs) to provide storage space to virtual machines. You can snapshot and clone them just like regular file systems, plus you can export them as iSCSI devices, giving you the flexibility of a SAN for all your virtualized storage needs. The reason I chose files over ZVOLs was just so I can swap pre-installed disk images with colleagues. On second thought, you can dump/restore ZVOL snapshots with Anyway, let's see how we're doing storage-wise:
Watch the "USED" column for the winxp1 clone. That's right: Our second instance of Windows XP only cost us a meager 138 MB on top of the first instance's 1.22 GB! Both filesystems (and their .vdi containers with Windows XP installed) represent roughly a Gigabyte of storage each (the REFER column), but the actual physical space our clone consumes is just 138MB. Cool thing #4: ZFS clones save even more space, big time! How does this work? Well, when ZFS creates a snapshot, it only creates a new reference to the existing on-disk tree-like block structure, indicating where the entry point for the snapshot is. If the live filesystem changes, only the changed blocks need to be written to disk, the unchanged ones remain the same and are used for both the live filesystem and the snapshot. A clone is a snapshot that has been marked writable. Again, only the changed (or new) blocks consume additional disk space (in this case Firefox and some WinXP temporary data), everything that is unchanged (in this case nearly all of the WinXP installation) is shared between the clone and the original filesystem. This is de-duplication done right: Don't create redundant data in the first place! That was only one example of the tremenduous benefits Solaris can bring to the virtualization game. Imagine the power of ZFS, FMA, DTrace, Crossbow and whatnot for providing the best infrastructure possible to your virtualized guest operating systems, be they Windows, Linux, or Solaris. It works in the SPARC world (through LDOMs), and in the x86/x64 world through xVM server (based on the work of the Xen community) and now joined by VirtualBox. Oh, and it's free and open source, too. So with all that: Happy virtualizing, everyone. Especially to everybody near Stuttgart.
"VirtualBox and ZFS: The Perfect Team" has been brought to you by Constantin's Blooog.
This entry was created on 2008-02-19 13:18:18.0 PST and is associated with the following tags:
cool
hack
howto
innotek
open
opensolaris
opensource
solaris
virtualbox
virtualization
windows
zfs
X4500 + Solaris ZFS + iSCSI = Perfect Video Editing Storage
During the last couple of weeks I worked with a customer who bought a Sun Fire X4500 server (you know, Thumper). The plan is to run Solaris ZFS on it, then provide big iSCSI volumes to the video editing systems, which tend to be specialized Windows or Mac OS X machines. Wonderful idea: Just use But it didn't work. First, Windows wouldn't mount the iSCSI volume. After some trying, we discovered that there must be an upper limit of 2TB to the size of iSCSI volumes that Windows can mount (we initially tried something like 5 ot 10TB). So be it: Now it mounted ok, we formatted the disk with NTFS (yuck!) and started the editing system's speed test. Then came the real issue: The test reported a write performance of 8-10 MB/s, but the editing system needs something like 30 MB/s sustained to be able to record reliably! After some trying, we started the systematic approach:
Finally, Danilo pointed me into the right direction: Nagle's algorithm. What usually helps maximize network bandwidth turns out to be a killer for iSCSI performance. For Solaris iSCSI clients, we know this already, but how do we turn off Nagle on Windows? The answer is deeply buried inside the Microsoft's iSCSI Initiator user guide: The "Addressing Slow Performance with iSCSI Clusters" chapter mentions a similar issue (although they talk about read not write performance) and they do mention RFC 1122's delayed ACK feature, which is related to Nagle's algorithm. The Microsoft document suggests a workaround which involves setting a variable in the registry, so it was worth a try (and my vengeance for having to use mdb before). And low and behold, the speed test now yielded 90-100 MB/s (Close to a GBE's raw performance)! Yipee that was it! One little registry entry on the client side gave us a 10x improvement in iSCSI performance! Now, can someone explain to me, why on Windows 2000 you need to set "TcpAckDelTicks=0" while on Windows 2003 the same thing is accomplished by saying "TcpAckFrequency=1" (which is the same thing, only seen from the other side of the division sign)? So, to all you storage hungry video editors out there: The Sun Fire X4500 with Solaris ZFS and iSCSI is a great solution for reliable, fast, easy to use and inexpensive video storage. You just need to know how to tell your TCP/IP stack to not delay ACKs...
"X4500 + Solaris ZFS + iSCSI = Perfect Video Editing Storage" has been brought to you by Constantin's Blooog.
This entry was created on 2007-12-06 13:31:53.0 PST and is associated with the following tags:
editing
file
iscsi
nagle
opensolaris
performance
registry
solaris
system
tcp/ip
thumper
tuning
video
windows
x4500
zfs
|
|