Wednesday, October 26, 2011

Cleaning your laptop fan

The other week I decided to open up my missus’ old Vaio laptop as it was having problems with some keys not typing and using pressurized air didn’t seem to do anything. 20 or so screws later, having to take the keyboard out, the keyboard cable, the touch-pad cable, some of frame, anyways a lot of work, I could see the fan at the back and said hey, I should have a look at that as well as I noticed it was struggling lately.

I thought at first that it wasn’t able to cope with today’s Flash applications and things like Yahoo Messenger and so forth – it’s an old 1.2 GHz Pentium M Mobile CPU – but man you should’ve seen the crap it collected in there over the years; dust burned to a black char got stuck in the radiator and the fan was struggling to push the air out without much success. I should’ve taken a few pictures, but it didn’t seem like something anyone would do, I said ok it had its years, it only happens to old laptops...

And I couldn’t be more wrong, cause the next day I said, ok how about my 2 years old Dell Vostro? Luckily Dell Vostro has a much better design where you can access the memory, fan and the CPU under this panel held by a couple of screws. Below you can see a couple shots with the crap in the radiator and fan blades.

To clean up, I use pressurized air and an old toothbrush for radiators, then for the fan blades cotton swabs with medicinal spirit, slowly going through the blades holding the fan so it doesn't rotate to make it easier - it’s not like I do it every day and 5 minutes later you’re done anyways.

It made quite a bit of difference to the old laptop, the fan doesn’t go on high as often and the one on my Vostro barely kicks in every now and then. For some reason I thought before blowing air (pressurized or human powered) through the vents was enough to get the stuff out of the fan, now I think I will do the real thing again every couple of years.




Sunday, October 16, 2011

Windows 8 Preview installation using Network Boot (PXE)

Having an older Vaio VGN-A115B laptop with not enough disk space on the system partition (running the setup.exe from the older OS it says it requires 16 GB  free, although it will happily install later on a 12 GB partition), a shot DVD drive that couldn’t read a DVD-RW disk with Windows 8 installer and on top of that didn’t seem to power the USB ports at boot, the only option I was left off was to do a network boot (PXE) – something I always wanted to try. So after two days and a lot of failed attempts, here it is.

Somehow I always thought booting through PXE would be easy (just as easy as the USB or DVD boot) – and how wrong I was, as it requires both a DHCP server that allows to specify a boot program and TFTP server, neither of which is easily found on the net (details on Intel Boot Agent).

Eventually I did stumble onto TFTPD32/64 and Serva32/64 – both looking fairly similar which is fair enough cause the second is based on code from the first one. They seemed to have done the job well for other people, but for me the embedded TFTPD server failed a lot on transferring the BCD store during tests with a local VM, so I finally stopped using that and eventually found SolarWind TFTP Server much more reliable.

To make things even more complicated, you have to prepare the boot image with Windows PE (Preinstallation Environment) – you can find a lot more information for that one the web, but it does require quite a large download of the Windows Automated Installation Kit (AIK) – in my case I downloaded version 3.0 for Windows 7.

A few things to note about my setup

Since I already have a router on the network with a DHCP server running, to avoid conflicts I used an Ethernet hub I had around to connect the two laptops directly. I manually setup the Ethernet adapter on my “server” to use 10.0.0.1 IP address (easier to type) and disabled the firewall as well as the wireless adapter for the duration of the exercise (you can probably just as easily add the server programs below as exceptions to the firewall) – if you do it like me, remember to re-enable the firewall back on when finished and to set the Ethernet adapter for automatic IP allocation later on.

You may also notice that I also configured the DHCP server to server IP addresses from the same private class (10.0.0.xxx).

To point out we will prepare a 32 bit WinPE image in C:\WinPE directory and then use the C:\TFPT-Root\Boot to place the boot files (SolarWind TFTP server defaults to C:\TFTP-Root, feel free to change).

Windows PE image preparation

Installing Windows Automated Installation Kit (AIK) is fairly straight forward so I’m not going to go into details on that. For preparing the WinPE image I started from this Microsoft Walkthrough: Deploy an Image by Using PXE although I’m not going to follow it to the letter, feel free to use that if you want.

Run Windows AIK Command prompt:


Run the copype.cmd command (will automatically change to the image directory and will use relative paths from then on) – remember I’m building an image for an x86 system :
copype.cmd x86 C:\WinPE

imagex /mountrw winpe.wim 1 mount

copy mount\Windows\Boot\PXE\*.* C:\TFTP-Root\Boot

Now for copying boot.sdi you can use the full path to AIK tools or simply close the console and run a new Deployment console and use relative paths.
copy x86\boot\boot.sdi C:\TFTP-Root\Boot


Back to the WinPE directory and unmount the image (cleanup).
cd /d C:\WinPE      
imagex /unmount mount


Copy winpe.wim in the TFTP boot directory as boot.wim (might just work as winpe.wim, but the BCD commands below will mention boot.wim).
copy winpe.wim C:\TFTP-Root\Boot\boot.wim


Now moving on to preparing the BCD store. You might notice that instead of specifying the full path to the BCD I will change directory to the Boot directory and do it from in there. Personally I reuse the previous command (press up arrow) and change the parts at the end.
cd /d C:\TFTP-Root\Boot      
bcdedit -createstore BCD

bcdedit -store BCD -create {ramdiskoptions} /d "Ramdisk options"      
bcdedit -store BCD -set {ramdiskoptions} ramdisksdidevice boot       
bcdedit -store BCD -set {ramdiskoptions} ramdisksdipath \boot\boot.sdi

bcdedit -store BCD -create /d "MyWinPE Boot Image" /application osloader


Note the highlighted GUID value – you will need to copy that and use it in the subsequent commands (replace {guid} with the one generated for you).
bcdedit -store BCD -set {guid} systemroot \Windows      
bcdedit -store BCD -set {guid} detecthal Yes       
bcdedit -store BCD -set {guid} winpe Yes       
bcdedit -store BCD -set {guid} osdevice ramdisk=[boot]\Boot\boot.wim,{ramdiskoptions}      
bcdedit -store BCD -set {guid} device ramdisk=[boot]\Boot\boot.wim,{ramdiskoptions}

bcdedit -store BCD -create {bootmgr} /d "Windows BootManager"     
bcdedit -store BCD -set {bootmgr} timeout 30      
bcdedit -store BCD -displayorder {guid}

This is what I eventually got in the Boot folder.


Sharing Windows 8 installation files

    As you will see later on, when the remote computer will boot up and load the WinPE image it will take you to a command line where you need to map a network drive to the computer sharing the image files.

    In my case, I took the Windows 8 ISO image, mounted in Virtual Clone Drive and shared it as Windows8 folder. I also created a pxe user with pxe password (you can use an existing user if it has a password assigned to it), and you will see how you will need to map a network drive from the remote computer to the installation files in order to start the actual Windows setup.

    Serva32/64 DHCP server

      As noted below, I will configure Serva64 (in my case again, running Windows 7 x64) to only enable the DHCP server and disable the other services.
      IP pool / size : 10.0.0.100 / 100 (IP range .100 to .200)
      Boot file      : Boot\pxeboot.com
      Subnet mask    : 255.255.255.0

      SolarWinds TFTP server

        Not much to configure there, go to File > Configure and start the service (change the storage location to point to your files – note we’re not pointing to Boot, but the parent directory). Otherwise the software is smart enough to bind to the interface and allow to serve files.


        Test run with Windows Virtual PC

          Simply create a VM with a blank VM and it will try to automatically boot from the network – if everything works fine you will notice that it gets an IP in DHCP server console and it will start transferring files from the TFTP server.



            Old laptop (PXE booting)

              I should note that in the case of my VAIO I had to enable the Network Boot in BIOS (press F2 at boot) and then press ESC to get the boot devices listing and choose Network Boot. Then it will move to a screen similar to the above if everything is setup ok.

              Pressing F12 will continue the boot process, where it downloads the boot manager, WinPE image etc. Ignore the errors in the TFTP console about not finding boot.ini and wgl4_boot.ttf.


              Eventually the remote computer will start loading boot.wim and get you the setup background and a command line prompt. Now you will map that network drive to point to the installation files (remember I created a new user pxe/pxe and shared the Windows8 installation files – the net use command will fail if a user is not specified saying something about Server service not being started).

              From the remote computer console run the statements:
              net use y: \\10.0.0.1\Windows8 pxe /user:pxe
              y:\setup.exe
              And finally now you are running the Windows 8 setup and continue with the usual stuff… It only took me 2 days to figure it out and get it running, hopefully this is going to useful to someone else as well, I know I’ll definitely try it again, although I will be zipping up the boot files and keeping them for future use, what might change is the setup files on the share.

              Keep in mind that when we prepared the image in the first place it was for an x32 platform and you will probably need to go through the process again to build for an x64 platform, replacing all the x86 references with amd64.

              Wednesday, October 5, 2011

              CLR Profiler for .NET Framework 4

              You read all this documentation saying you should use StringBuilder instead of String.Concat() when doing a lot of string concatenations and you probably say huh, it’s all fine, what do these guys know...

              And then I ran my little app processing some application logs through the CLR Profiler - looking through the allocations a huge block of 259 MB allocations jumped at me! Looking at the app from outside with Process Explorer didn’t show much memory usage but that was probably the GC doing a lot of cleanup – the collections report shows it well.

              Changing the code to use a StringBuilder was not that complicated and it reduced the amount of GC work and cut the processing time in half from 20 seconds down to 10 seconds! Still more to be done, but we’re on the good track now...

              CLR Profiler for .NET Framework 4
              http://www.microsoft.com/download/en/details.aspx?id=16273

              * * *


              CLR Profiler (before)



              CLR Profiler (after)




              Tuesday, October 4, 2011

              Microsoft WMI Code Creator v1.0

              Want to query WMI for information on your system? Very easy with this tool Microsoft made available – pick the category, the fields and will generate the code for you, and even change it and run it to see how it works before you bring it into your program. Huge timesaver if you’re new to it (like me) – writing a program to query for certain services to get status, process id etc.



              WMI Code Creator v1.0
              http://www.microsoft.com/download/en/details.aspx?id=8572

              The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.