Saturday, February 23, 2013

How to create an iso of an existing Windows system using Ubuntu: what worked and what didn't

I have a Windows XP Media Center laptop that is dying, but want to keep the image around.  I've created vms before but not from existing systems, just as fresh installs.  Searching around I stumbled upon Clonezilla which allowed me to create just such an image without purchasing software.  Unfortunately Clonezilla only almost worked (probably because of something I didn't do correctly).   disk2vhd (a Microsoft product) ended up getting the job done in the end.

I'm using Ubuntu 12.10 as my main machine.   Taking an image of a Windows XP Home Media edition with an 80G hard drive. 

The disk2vhd approach

disk2vhd didn't turn up as one of the many options that were presented as I started down this path, but it   ended up being the easiest and quickest of those I tried. I followed these instructions to create the vhd.  Then I used VirtualBox to open the image.  The only thing I had to modify in VirtualBox was this: in System -> Motherboard check the Enable IO APIC box in the Extended Features setting.


The Clonezilla approach

I had space on my system's hard drive that is sufficient but not any flash drives so I backed up using Clonezilla's ssh option to my main box.  This was convenient since I'd be creating the image of the system on the main box anyway.

Before you reference the steps below, understand that I was only able to get to the point where the vm could boot to the safe mode prompt screen, but then hung on any attempt to move forward.  I've got a hunch that trying this with cloning a Linux box would have gone better.

There are several distinct units of work: 
  • prep the source machine
  • create media
  • prepare a repository location for the backup
  • create the clone
  • create a VM from the clone

Prep the source machine

Issues with the source machine

I loaded Clonezilla on a USB drive and ran fine for two partitions (boot and D:/), but not for the main partition where the OS files were installed.  After experiencing issues with booting SpinRite6 from a USB drive that cleared up when using a DVD, I burned the Clonezilla ISO to a physical DVD.  

I then decided to try and make the source image as 'clean' as possible by doing the following:
  • Removing unused files/dirs manually, running disk clean and emptying the recycle bin on the source machine
  • Defragging the source machine
  • Updating BIOS to the latest version provided for my source machine by the manufacturer
  • Running SpinRite on the source machine

Create media

Create Clonezilla disk

Create bootable Clonezilla ISO using Tuxboot.

Create Windows boot disk

I relied upon http://support.microsoft.com/kb/305595 for instructions.  My machine didn't come with any physical media so I needed to harvest the files from C:\.  ntldr and ntdetect.com were in C:/WINDOWS/ServicePackFiles/i386.  boot.ini.backup was in C:\Windows\pss which was good since I used it to confirm the boot.ini name of my operating system.

Tried boot-repair first since screen was blank when I restarted.  After boot-repair I got Windows boot screen, but it just hung part way through the process no matter which option.

Prepare a repository location for the backup

For me the repository location is an Ubuntu 12.10 machine.  It has more space than any external drives I have and it is where I'll be creating and hosting the VM.
  • Install/confirm openssh
  • Create directory /home/partimag on the destination machine and give said directory the appropriate permissions

Create the clone

  • Boot source machine with Clonezilla media
  • When prompted, enter connect info for your destination box
  • Give yourself a few hours if you have an old 80G box you're attempting to clone :)

Create a VM from the clone

  • Create a vm with the same amount (or more) of space
  • Start the vm with the Clonezilla ISO.  Follow the prompts and select restoredisk



Tuesday, February 19, 2013

Solved: Amazon Instant Video won't play on Firefox on Ubuntu 12.10

http://helpx.adobe.com/x-productkb/multi/flash-player-11-problems-playing.html

To summarize:
  1. Install hal
  2. Remove directories from ~/.adobe/Flash_Player
  3. Restart Firefox and watch a video

Wednesday, November 28, 2012

Working with Postgres on OS X Mountain Lion


Installation

Macs come with Postgres installed (9.1.4 for mine purchased in November 2012) (/usr/bin/psql), but I also installed the Postgres app, which appears to have installed 9.1.4 (downloaded in early November 2012).

  1. Install the Postgres app
  2. Start the Postgres app.  When I start the app, I get the Postgres elephant in my menu bar -- clicking it shows the port Postgres is running on.
  3. Use ps -ef | grep postgres to figure out where the path to the Postgres bin directory and the path to the Postgres data directory are.  The output will look something like this: 501 22332     1   0  9:28PM ??         0:00.25 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/hm1/Library/Application Support/Postgres/var -p5432 where /Applications/Postgres.app/Contents/MacOS/bin/postgres shows the bin directory plus the executable, -D /Users/hm1/Library/Application Support/Postgres/var shows the data directory and -p5432 shows the port Postgres is running on.  Sadly, you can see that there are spaces in the path which means you'll have to enclose this in quotes where you use it.
  4. Add the Postgres bin to your path in the current session or to your .bash_profile.  e.g., export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH

Troubleshooting

Even with the Postgres bin directory appearing first in my PATH, unless I run the Postgres commands (psql, postgres, etc.) from , I need to specify the data files or host location.  If this doesn't work for you, you can alias the commands, uninstall the base installation or use the base installation,  Sarting a new terminal session seems to get around this issue where just sourcing the updated .bash_profile doesn't.

If you get the following error when issuing postgres, your path is not correct and/or Postgres is not running:

postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
If you modified the PATH variable via .bash_profile don't forget to source it or start a new terminal session
Using ps above you can see what the -D argument needs to be, or or add the Postgres path section prior to the existing PATH elements.

If you get the following error when issuing psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
then you need to start with psql -h localhost, or add the Postgres path section prior to the existing PATH elements.


Resources

http://postgresapp.com/documentation
http://www.postgresql.org/docs/9.1/interactive/tutorial.html


Monday, October 1, 2012

JS Console

JS Console is a tool I enjoy for messing around with JavaScript without having to create a bunch of HTML (although you can work with the DOM in JS Console). This is proving very handy as I go through JavaScript books/tutorials and want to try code out quickly.  JS Console allows you to do remote JavaScript debugging as well.


How do I use JS Console?

Type or paste JavaScript into the text bar at the top.  You can also load JavaScript libraries (like JQuery) or DOM.

JS Console remote debugging

I don't do mobile development, but it looks like there's a neat way to use your computer's browser to debug JavaScript on your phone(!) or on another machine/session.  And there's a native iOS app.  I have not experimented with the remote debugging.


What can I access in JS Console?

DOM

Looks like you can get to everything in your browser.  If you type document in the text field, for example, you'll get the HTMLDocument object represented as a String.  


localStorage and sessionStorage

You can also view and manipulate localStorage and sessionStorage if supported by your browser (when I did this in IE7 I got undefined as these aren't supported until IE8).  

I added items to localStorage and remoteStorage, opened another Chrome window and verified that in Chrome and  Firefox separate tabs represent new sessions.  I also learned that JS Console uses sessionStorage to store your history.  And I saw that localStorage is browser-specific.  All Chrome windows and tabs saw what I'd added to localStorage in Chrome even after closing and reopening browsers.  Same thing with Firefox, but Chrome didn't see Firefox's localStorage and vice versa.

Sunday, September 30, 2012

JavaScript

I've been looking at JavaScript a bit over the past six months.  

Books
The most helpful titles I've read are:
Eloquent JavaScript
Intro to programming using JavaScript as the vehicle.  Covers programming fundamentals quite a bit.

JavaScript: The Good Parts
Less of a beginning programming guide and

Learning JavaScript (currently reading now)
Intro to JavaScript that assumes an understanding of programming fundamentals.

Tools
QUnit is what I've used to unit test my JavaScript (even if I'm not using JQuery's features in my JavaScript).  I find that unit tests are a great tool for helping me figure out how a language/framework works since they let me submit different scenarios easily, as well as helping me persist the questions I've asked and answered about a language/framework.
QUnit gave me some trouble around the setup, but it was worth the effort, especially once I got into writing more complex functions.

JSConsole is a tremendous tool that I just discovered (today!).  Those of you familiar with consoles for Ruby, Groovy, IO, etc. understand how helpful they can be for quickly answering implementation questions. For example, I wanted to know what would happen if I executed slice(-10) on an array with three members.  Instead of having to build the HTML, the JavaScript, connect the two and figure out how to view the results (alert, innerHTML, etc.) I used the console and it took me about a minute to create the array and try a bunch of slice overrides.

W3Schools Tryit Editor for JavaScript is a helpful tool if you want an easy way to experiment with DOM modification in JavaSript.  On the left side you have HTML and embedded JavaScript -- on the right side you have the output.  You can also use this to experiment with embedded CSS.

Browser debuggers/consoles are handy for debugging (using breakpoints) or monitoring DOM manipulation.  F12 on a PC keyboard (Windows or Ubuntu) will toggle the console for Chrome and Firefox (if you have Firebug installed for the latter).

Monday, September 10, 2012

dd-wrt for Linksys WRT54G v8

http://dd-wrt.com/wiki/index.php/Linksys_WRT54G_v8.0_%26_v8.2

My sister's WRTG54 v8 with stock firmware started hanging when distributing IPs so I decided to put dd-wrt on it.  I had done the same with my WRTG54 v1.1 with no problems so I assumed it would be a snap.  I was going to use it for a client bridge (see Andy Frank's post).

Ubuntu needed for tftp
Using tftp to upload dd-wrt.v24_micro_generic.bin didn't work from my Windows XP box, so I gave it a shot from an Ubuntu 12.x box and that worked.

Brick
Then I got myself into a jam since the primary subnet was non-standard.  I tried to change the secondary router (the one I just flashed), but couldn't connect to the web interface at all.  I did the 30-30-30 reset a few times and thought I bricked it.  The Power and WLAN lights no longer glowed, but the light corresponding to the port connected to my computer glowed.  I did the 30-30-30 reset a few times with no luck.

Wait, then unbrick
Then I let the whole thing sit overnight.  Next evening I was able to connect to to the dd-wrt web interface, and then found that it was serving IPs just fine.  

Whew...

Create client bridge
I gave the now-working WRTG54 v8 back to my sister.  I still didn't have what I was looking for: a client bridge for my ancient Pentium IV running CentOS.  I want the box close to me instead of close to the router behind the TV where it gets hot and is hard to reach.

I ran into issues with a primary (Belkin) broadcasting in N and a secondary (Linksys) only capable of B and G.  Also, the primary has different WPA2 options than the secondary.  And the secondary wouldn't let me select a channel in client bridge mode.  This whole thing is probably easier with two identical routers both running dd-wrt.

Success with compromises
Setting the primary to B and G mode, changing channel selection from Auto to a fixed value and moving from WPA-PSK+WPA2-PSK/TKIP+AES to WPA2-PSK/AES did the trick.  Plugged in Ubuntu laptop connected to the internet when I disconnected from the wired connection I'd set up per the dd-wrt instructions and connected using the Auto Ethernet option.

Back out compromises
Then I began backing out the changes I'd made to the primary.  Moving back to B, G and N worked fine.  Setting channel selection back to Auto didn't affect the secondary's ability to connect to the internet either.  Reverted primary to WPA-PSK+WPA2-PSK/TKIP+AES and still was able to connect to the internet through the secondary.  Seems like this is kind of what  Andy Frank did, but he may have found it possible to go back to WPA2 on the secondary.

Monday, June 18, 2012

cygwin windows processes and ps: the W option

http://cygwin.com/cygwin-ug-net/using-utils.html


Hard to believe I haven't been bothered by this before: if one runs ps in cygwin Windows processes are not displayed unless the W option is used.



$ ps -ef | grep post*
-- nothing



$ ps -efW | grep post*
       0    3220       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe
       0    5684       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe
       0    3808       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe
       0    3072       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe
       0    3620       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe
       0     412       0 ?          Jun 17 D:\PostgreSQL\9.1\bin\postgres.exe

Unfortunately I've not found a cygwin way to kill the Windows processes.  I'm stuck with the Windows way:

$ kill -9 1600
-bash: kill: (1600) - No such process



$ taskkill /F /PID  1600

SUCCESS: The process with PID 1600 has been terminated.