September 07, 2010

Botched iPod Touch Repair

I guess I should keep this blog entry short as I essentially botched the repair (i.e. it’s literally now a brick not even good for a door stop). So what’s the point of me even writing this? Well I think it’s worth warning the world of what can happen when you try and play MacGyver.

So what was wrong with your iPod Touch? Well basically a great big grey blob on the screen:


How did that happen? I don’t know. I looked after it quite well I thought.

What did the Apple guys say? Well first it was a 1st generation so it being out of warranty, I didn’t expect much. Anyway I took it along to my local Apple Store on Zurich's Bahnhofstrasse and was told it couldn’t be repaired as the screen wasn’t removable. Not sure why as I later replaced it myself (albeit it's now a brick). They did however offer me 10% off a new one but at the time I thought nah, not paying 300 and odd francs for what is in effect going to be the cost of repair. To their defence, I later tought that's quite good of them. One thing I remember was how the guys Apple were quite bewildered about how big and perfectly round the blob was. Apparently they’d never seen anything like that before!


So what did you do next? Got back home and found DirectFix.com - a site offering replacement iPod components. They shipped me a replacement LCD screen for around $30 including postage. Great I thought. Should be easy enough. Apart from getting the cover off it was. There’s plenty of videos on YouTube. Photo below shows old and new side by side. Notice the funny coloured blob on the top (original) screen:


My conclusion: Don’t try it at home kids. One thing I liked about the 1st generation was its ability to charge over Firewire (using my Blaupunkt iPod adaptor in the car for example). It also looks like I won’t be watching any iTunes rented movies for a while on my television set. I used the Touch with an older, what’s labelled 'iPod' Universal Dock/model A1153 which has an S-Video connector. It worked well as I have an older CRT television and the Apple TV is no use with its HDMI and component outputs. Oh well. I enjoyed it.

Above: My iPod with the grey spot before I attempted a screen exchange.

June 06, 2010

Using Solaris 10/09 Virtual Appliance with VMWare ESXi

Sun have released Solaris 10/09 as Virtual Appliance. However it's not readily usable with VMWare ESXi Server 4.0 without a bit of tweaking. So in a nutshell, here's how to get it working:
  1. Use the VMWare vSphere client to create a Solaris 10 VM and export it as an OVF appliance. Modify the config file within this new appliance and replace the disk file with the one downloaded as part of the Solaris OVF appliance download from Sun's website here.
  2. Use the VMWare OVF Tool (available here) to convert the now modified OVF appliance to VMWare.
  3. Start the VM and modify some boot config files so that the VM can start correctly.
It was these two articles that got me going with this:
http://communities.vmware.com/message/907527
http://www.mail-archive.com/opensolaris-discuss@opensolaris.org/msg35493.html

Step 1 in detail

The OVF config that comes as part of the Solaris Virtual Appliance download throws up a bunch of errors when using VMWare OVF Tool:
- Line 8: Unsupported value 'http://www.vmware.com/specifications/vmdk.html#sparse' for attribute 'format' on element 'Disk'.
Give up trying to fix it. Within the VMWare vSphere Client tool, create a new Solaris 10 VM (with a tiny disk) and export it as an OVF appliance. Modify the OVF config file as part of this new appliance and replace the disk file with the one downloaded as part of the Solaris OVF appliance download. The config file is an XML file and it's not that difficult to work out what should be where.

I guess you could either move the Solaris disk file (downloaded as part of the Solaris OVF downloaded) to the directory containing newly create 'template' OVF, or replace the existing OVF config file with the 'template' OVF. I think I did the later. 

Step 2 in detail
Once you have a compatible OVF appliance ready you should be able to run the VMWare OVF Tool and have that migrate the appliance to your ESXi server. Something like the following should do it:
C:\Program Files\VMware\VMware OVF Tool>ovftool.exe --datastore="external_storage" --network="VM Network" "c:\TEMP\Solaris10_1009_virtual_image\solaris.ovf" "vi://root:password@myesxiserver"
If it worked then you should see the following:
Opening OVF source: c:\TEMP\Solaris10_1009_virtual_image\solaris.ovf
Warning: No manifest file
Opening VI target: vi://root@myesxiserver/
Target: vi://myesxiserver/
Disk Transfer Completed
Completed successfully
Step 3 in detail
Unfortunately starting the VMWare as is will produce the following:
The issue is that the boot device has changed and both /boot/solaris/bootenv.rc and /etc/vfstab need updating aswell as performing a reconfiguration boot.

1. Start the VM and at the grub prompt, enter fail-safe mode and allow the root file system to be mounted as read/write under /a.

2. Identify the new device name using the format command and get ready to use vi. You can brush up your vi skills here. Mine was /pci@0,0/pci15ad,1976@10/sd@0,0--so replace where necessary from now on. Also vi may not display correctly so fix the terminal type with the following command:
# TERM=sun-color; export TERM
3. Now edit /a/boot/solaris/bootenv.rc and update the line that starts with setprob boothpath so that it reads:
setprop bootpath '/pci@0,0/pci15ad,1976@10/sd@0,0:a'
4. Once you've done that update the boot archive:
# bootadm update-archive -R /a
5. Then edit /a/etc/vfstab (making a copy first) and modify the line mounting the root file system so instead of /dev/dsk/c0d0s0 and /dev/rdsk/c0d0s0 it reads the following absolute paths. Do not forget to suffix a: and ,raw respectively.
/devices/pci@0,0/pci15ad,1976@10/sd@0,0:a /devices/pci@0,0/pci15ad,1976@10/sd@0,0:a,raw / ufs 1 no -
6. Now we need to force a reconfiguration boot so that the system recreates the /etc/path_to_inst file that contains physical device to logical instance mappings.
# touch /a/reconfigure
# reboot
7. The system should now reboot and selecting the default grub option (i.e. non fail-safe) should perform a reconfiguration boot before bringing you to the graphical X login. If it doesn't then something went wrong :-(. Trace-back your steps.

8. Login and edit /etc/vfstab again so that you can replace those absolute paths. If you made a backup of this file before the last update, it would be easier to start with this. Before you do this use ls -l /dev/dsk to determine the new disks and update this file as appropriate. For example mine now reads:
/dev/dsk/c3t0d0s1 - - swap - no -
/dev/dsk/c3t0d0s0 /dev/rdsk/c3t0d0s0 / ufs 1 no -
/dev/dsk/c3t0d0s7 /dev/rdsk/c3t0d0s7 /export/home ufs 2 yes -
9. Reboot again and that should be it. System is now ready for use.

March 19, 2010

Use gawk to convert fixed width files to delimited

I had a bunch of fixed-width text files that I needed to be convert to CSV. Each file was different and determining the start and end of each field would be time consuming so this needed to be done dynamically. Fortunately the second line of each file could be used to do exactly that and I was able to run the script unmodified against each file.

An example of the input file:
empno ,ename    ,job        ,hiredate  ,sal
------,---------,-----------,----------,---------
7782  ,CLARK    ,MANAGER    ,09-JUN-81 ,2450.00
7839  ,KING     ,PRESIDENT  ,17-NOV-81 ,5000.00
7934  ,MILLER   ,CLERK      ,23-JAN-82 ,1300.00

The script looks at the second line of each file (i.e. the hyphenated line) to dynamically determine the start and end of each field:
#!/usr/local/bin/gawk -f
BEGIN {
 FS=","
 RS="\n"
 OFS=","
}

# Determine fixed length positions of each field by
# looking at second record (i.e. header row) and output
# each field separated by chosen delimiter.
NR==1{
 widthstring = (length($1)+1)
 for(i=2; i < NF; i++) {
    widthstring = widthstring " " (length($i)+1)
    if(i!=(NF-1))
     printf("%s",OFS ltrim(rtrim(rmlastcomma($i))))
 }
 i=NF-1
 print(OFS ltrim(rtrim(rmlastcomma($i))))
 FIELDWIDTHS = widthstring
}

# Now read from line 3 (skipping first two rows) using newly
# determined field lengths and remove whitespaces. Output
# each field separated by chosen delimiter.
NR>2{
 for(i=2; i < NF; i++)
    printf("%s",OFS ltrim(rtrim(rmlastcomma($i))))
 print(OFS ltrim(rtrim(rmlastcomma($NF))))
}

function ltrim(v) { gsub(/^[ ]+/, "", v); return v}
function rtrim(v) { gsub(/[ ]+$/, "", v); return v}
function rmlastcomma(v) { sub(/[,]+$/, "", v); return v}

The resulting output will be a regular CSV file:
7782,CLARK,MANAGER,09-JUN-81,2450.00
7839,KING,PRESIDENT,17-NOV-81,5000.00
7934,MILLER,CLERK,23-JAN-82,1300.00

Example command  to start gawk in Windows (reading in all files):
for %n in (*.txt) do gawk -f fixed2csv.awk %n >%n.csv

Yes, I did this in Windows!