Skip to main content

cp /dev/null

I am always puzzled when people do

  $ mv file.txt /dev/null
...and get away with it. Well, they shouldn't, because it won't work and /dev/null will get overwritten with a plain file. However, I was suprised to see that cp really works that way, when used with the proper options:
$ cp /dev/null /var/tmp/foo 
$ ls -l /var/tmp/foo 
-rw-r--r-- 1 root root 0 May 27 19:02 /var/tmp/foo

$ cp -R /dev/null /var/tmp/foo 
$ ls -l /var/tmp/foo 
crw-r--r-- 1 root root 1, 3 May 27 19:03 /var/tmp/foo

$ cp /tmp/file.txt /var/tmp/foo 
$ ls -l /var/tmp/foo 
crw-r--r-- 1 root root 1, 3 May 27 19:03 /var/tmp/foo

$ cp -R /tmp/file.txt /var/tmp/foo 
$ ls -l /var/tmp/foo 
crw-r--r-- 1 root root 1, 3 May 27 19:03 /var/tmp/foo
On my way to this adventure I stumbled across this, introducing a new "feature" in busybox:
config FEATURE_NON_POSIX_CP
        bool "Non-POSIX, but safer, copying to special nodes"
        default y
        help
          With this option, "cp file symlink" will delete symlink
          and create a regular file. This does not conform to POSIX,
          but prevents a symlink attack.
          Similarly, "cp file device" will not send file's data
          to the device. (To do that, use "cat file >device")
Ouch :-(

gzip vs. bzip2 vs. pbzip2 vs. xz vs. lzma

Yes, another benchmark. And yes, YMMV - big time:

$ ls -lh file.tar
-rw-r--r-- 1 bob bob 80M May 27 12:36 file.tar

$ compress-test.sh file.tar
### gzip/9c:    6 seconds / 48.700% smaller
### bzip2/9c:   44 seconds / 50.300% smaller
### pbzip2/9c:  22 seconds / 50.200% smaller
### xz/9c:      79 seconds / 53.400% smaller
### lzma/9c:    120 seconds / 53.200% smaller
### gzip/1c:    4 seconds / 46.200% smaller
### bzip2/1c:   30 seconds / 48.100% smaller
### pbzip2/1c:  15 seconds / 48.000% smaller
### xz/1c:      35 seconds / 51.100% smaller
### lzma/1c:    18 seconds / 49.700% smaller
### gzip/dc:    0 seconds
### bzip2/dc:   7 seconds
### pbzip2/dc:  4 seconds
### xz/dc:      4 seconds
### lzma/dc:    5 seconds
Versions used:

WindowsPE on USB

Oh boy, what a mess. It all started when I noticed that my Ideapad S10 engages its fan quite often - too often, for no apparent reason. Luckily IBM relased a BIOS update, mentioning (and hopefully fixing) exactly this behaviour. Of course, flashing the BIOS was only possible by running some Win32 application. Although this Ideapad S10 came with MS Windows preinstalled, it was running Ubuntu/10.04.2 now. This is where the fun begins...

There's WindowsPE, which is basically a minimal of a Windows operating system. In our case, WindowsXP should be sufficient. (I guess Windows98SE would do too, but let's not get cocky). There are different approaches how to roll your own, bootable WindowsPE image, the most prominent one seems to be BartPE. This is a good start and the ISO was indeed bootable (in a virtual machine) - but not when I copied it to a USB stick. Yes, I know grml can do it and grml boots an ISO9660 image just fine when copied to USB. But BartPE would not.

After trying several things, experimenting with Syslinux black magic and avoiding overly crude tutorials I finally came across PE2USB. However, pe2usb could only handle USB drives with less than 2GB. Even when I found such a thing and pe2usb completed w/o any errors, it just wouldn't boot.

But then there was another PE2USB version - which formatted the USB drive with NTFS instead. And indeed, with BartPE and this version of pe2usb (and manually copying AUTORUN.INF) the Ideapad S10 would finally boot off this USB stick - yay!

Luckily I had a machine with WindowsXP available that allowed me to do all this. Mounting the USB stick in Windows again, filling it with zeros (fsutil can't do this, right? And SDelete did some magic, but I had to quit it at 817%), I can now compress the USB disk's image and save it to be reused again when another BIOS update is calling :-)

StarMoney & Microsoft DAO

Mit was man sich alles so herumschlagen kann/muss:

   Zum Ausführen von StarMoney 5.9 wird eine aktuellere Version der 
   "Microsoft DAO (Data Access Objects) Komponenten" benötigt. 
Wie man im Forum nachlesen kann:
   "Die Ursache für die Meldung beim Start von StarMoney liegt am fehlerhaften bzw.
    fehlenden Eintrag für die DAO's in der Registry."
Nicht klar ist mir, warum das "einfach so" passiert, aber vielleicht will ich das auch gar nicht wissen. Der vorgeschlagene Fix hat auch hier geholfen:
  $ runas /user:Administrator cmd.exe
  # cd "%CommonProgramFiles%\Microsoft Shared\DAO"
  # regsvr32 dao360.dll
And magically it worked again :-\

Authentication tried for root with correct key but not from a permitted host

Syslog tells me, for every key-based SSH login attempt (OpenSSH_5.5p1 Debian-6):

Authentication tried for root with correct key but not from a permitted host (host=foo.ex.com, ip=10.0.0.3).
Authentication tried for root with correct key but not from a permitted host (host=foo.ex.com, ip=10.0.0.3).
Accepted publickey for root from 10.0.0.3 port 53187 ssh2
pam_unix(sshd:session): session opened for user root by (uid=0)
Received disconnect from 10.0.0.3: 11: disconnected by user
pam_unix(sshd:session): session closed for user root
Yet the login succeeds, despite these warnings. This has been posted on debian-security a while ago, but nobody replied. (or will be able to reply now). So, I wonder what's going on here...

Shell prompt with timestamps

I just needed a my shell prompt to display the current time, with a bit more precision than seconds, but I did not need all the nanoseconds GNU/date offered me:

  PS1='$(date +%H:%M:%S.%N | sed "s/.\{5\}$//") \u@\h$ '
Of course with bash-v3 there's HISTTIMEFORMAT, which will save timestamps to HISTFILE anyway, but this time I wanted it to be displayed as I typed.

Windows7: CDBOOT cannot boot from CD code:5

Installing Windows7 turned out to be not so easy as previous versions. Booting the DVD within a VirtualBox virtual machine barfed with:

  CDBOOT cannot boot from CD code:5 
The solutions on the interwebs mentioned something about ETFSBOOT.COM or using Gujin (a boot loader) to boot from the CD. But the thing that worked for me was: At this point we should be able to remove the Windows Vista DVD from our virtual machine and replace it with the Windows7 DVD. On the command prompt in the virtual machine again:
  • Select your CD drive, e.g. type "D:" if your drive is listed as drive ''D:''
  • type "cd sources"
  • type "setup.exe"
Now Windows7 setup should come up. The Windows Vista setup window might still be active and can just be minimized.

Fedora 15 Alpha

It's been a while since my last post on Fedora 13. So, one year later, let's see if I can finally install & use it on this MacBookPro5,5. Installation went OK, I only had to rerun rEFIt once more in MacOS X, so that Fedora's GRUB is loaded correctly. After installation, quite a few things came up and after 2 days of fiddling, it's still far from being excellent:

So, that and the usual 3rd party showstoppers (Flash and Java plugins, Picasa anyone?) make it really hard for me to use for serious business. Let's hope they'll iron out a few bugs before its final release.

Update:

nagios.log with readable timestamps

Usually, the nagios.log is logged with Unix timestamps. This is neat and all, but I too like to be able to read these timestamps once in a while. And because I always forget about this, here's how:

$ tail -1 nagios.log 
[1299847717] Auto-save of retention data completed successfully.

$ tail -1 nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
[Fri Mar 11 13:48:37 2011] Auto-save of retention data completed successfully.
Or, the long & ugly version of this:
$ sed 's/\[//;s/\]//' nagios.log | awk '{printf strftime("%c ", $1); print }' | \
  sed 's/CET [0-9]* /CET /' | tail -1
Fri 11 Mar 2011 01:48:37 PM CET Auto-save of retention data completed successfully.
MacOS 10.6 doesn't even support the latter and barfs with:
  awk: calling undefined function strftime
  input record number 1, file 
  source line number 1
So yeah, Perl is clearly the winner here :-)

As a bonus, here's how to convert epoch timestamps into YYYY-MM-DD (ISO 8601):
$ alias e2i='perl -MPOSIX -pe "s/(\d+)/strftime(\"%Y-%m-%d %H:%M:%S\", localtime(\$1))/e"'
$ tail -3 nagios.log | e2i
[2011-07-05 09:18:00] SERVICE NOTIFICATION ...
[2011-07-05 09:18:10] SERVICE EVENT HANDLER ...
[2011-07-05 09:20:20] EXTERNAL COMMAND ...