Wednesday, 13 April 2022

Australian Energy Use

(very old incomplete draft) How much energy does Australia consume and where is it used? According to the Australian Bureau of Statistics ABS, Australia used 5,525 petajoules (PJ) in 2004-2005. A Peta Joule is 1,000,000,000,000,000 Joules (which isn't that helpful is it?) 1 PJ is 1,000,000,000 MJ. 3.6 MJ is 1kWHr so 1 PJ is 278 Million kWHr. The transport sector (including household transport) is the largest end-user of energy, using 1,340 ... The manufacturing sector was the second highest user of energy (1,247 PJ ...). The transport and manufacturing sectors together accounted for 68% of total energy end-use. Domestic energy consumption is 433 PJ (electricity, gas, etc.) So, if we want to make a difference in terms of our energy consumption - and therefore CO2 emissions - shouldn't we focus on transport and manufacturing rather than

SNMP to XML

(very old draft - may not be complete) I wanted to be able to query SNMP data from a device and turn it into XML so that it can be queried with XPath or XQuery. The idea is to be able to script something like this:
snmpget -v2c -c$community -OXf $host $oid | ./pc-snmp2xml.sh
eg.
snmpget -v2c -cpublic -OXf 10.0.0.1 ifInOctets.1 | ./pc-snmp2xml.sh
So,
snmpget -v2c -cpublic -OXf 10.0.0.1 ifInOctets.1
might return
.iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifInOctets[1] = Counter32: 2606713050
whereas this
snmpget -v2c -cpublic -OXf 10.0.0.1 ifInOctets.1 | ./pc-snmp2xml.sh
returns
snmpbulkwalk works just as well to convert the whole MIB to XML. I have tested this script with Apple Time-Capsule, Nortel 425 switch, MacBook Pro, and a Billion 7404 ADSL router. I had to pre-process the MacBook Pro and Billion router output to remove newline characters and duplicate output respectively. I wrote the SNMP to XML script in AWK because I thought AWK's pattern matching and parsing would simplify the task. I'm not convinced, but it was a good learning exercise. This is the clean-up script.
#!awk # This converts snmp output like this: # .iso.org.dod.internet.mgmt.mib-2.host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunName[4592] = Hex-STRING: 6A 61 76 61 00 00 00 00 00 00 00 00 00 00 00 00 # 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # into this: # .iso.org.dod.internet.mgmt.mib-2.host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunName[4592] = Hex-STRING: 6A 61 76 61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0 0 00 00 00 00 00 00 # where multiple lines of data are converted into a single line by eliminating the new-line characters # process expected OID lines that start with . /^(\.).*/{ if ( FNR > 1 ) printf "\n" # terminate last OID bu not the first line printf "%s", $0 # start this OID but don't write a new-line yet next } # process other lines that we assume are actually part of previous OID { printf "%s", $0 # continue previous line } # terminate the last OID END{ printf "\n" # terminate last OID }

Howto make Virtual Machines running in VirtualBox using Physical Partitions on OS-X

(very old draft - may not be complete)

My goal is to run Linux on my new MacBook Pro 9,1.

Whilst I can sort-of can run Linux, it is not really usable until all this new hardware is understood and drivers built to manage it.

So, next best is to run Linux in a VM. I like FOSS so I will use VirtualBox.

Unfortunately, this seems hard to do, so I have document my approach for others to improve upon.

Requirements

1. Run Linux in a VM using VirtualBox running on OS-X

2. Use real/physical disk partitions so that when this laptop is better supported, I will be able to boot into these physical partitions and drop my VirtualBox and OS-X layers

Procedure 

Before proceeding, you need to understand that if you or I make a mistake, OS-X partitions, EFI partitions, and any other recovery data on our hard drives could be lost or a pain to recover.

Your setup is likely to be different to mine so don't simply copy my detail and expect your system to work.

I have re-partitioned my hard drive as follows:


rex:~ phil$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            70.0 GB    disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4: 21686148-6449-6E6F-744E-656564454649               200.0 MB   disk0s4
   5:       Microsoft Basic Data                         20.0 GB    disk0s5
   6:       Microsoft Basic Data                         20.0 GB    disk0s6
   7:       Microsoft Basic Data                         350.0 GB   disk0s7
   8:                 Linux Swap                         19.8 GB    disk0s8

Partition 1 is my EFI partition - I don't want to touch this.
Partition 2 is my shrunk OS-X partition - again, I'd like to keep this in good working order.
Partition 3 is OS-X recovery files - probably a CD/DVD image that I also need to keep safe.
Partition 4 is something that OS-X disk manager created - I'll leave that alone too.
Partition 5 already has a mostly-working Linux root file system - I don't want to mess with this.
Partition 6 will be my new Virtual Machine root file system (and possibly swap area).
Partition 7 already is formatted ext4 and has my /home file system - I want to keep this.
Partition 8 is a Linux swap area I will look at using a bit later.


So, I only want to work with Partition 6 and 7.


rex:phys phil$ ls -la /dev/disk0*
brw-r-----  1 root  operator   14,   0 22 Jul 19:47 /dev/disk0
brw-r-----  1 root  operator   14,   2 22 Jul 19:47 /dev/disk0s1
brw-r-----  1 root  operator   14,   1 22 Jul 19:47 /dev/disk0s2
brw-r-----  1 root  operator   14,   3 22 Jul 19:47 /dev/disk0s3
brw-r-----  1 root  operator   14,   4 22 Jul 19:47 /dev/disk0s4
brw-r-----  1 root  operator   14,   5 22 Jul 19:47 /dev/disk0s5
brw-rw-rw-  1 root  operator   14,   6 26 Jul 22:37 /dev/disk0s6
brw-rw-rw-  1 root  operator   14,   7 26 Jul 21:51 /dev/disk0s7
brw-r-----  1 root  operator   14,   8 22 Jul 19:47 /dev/disk0s8

So that VirtualBox can access these partitions, I ran these commands to give everyone read and write access:

sudo chmod a+rw /dev/disk0s6
sudo chmod a+rw /dev/disk0s7

Note: I suspect that after a reboot, I will need to re-run these commands - I'll solve that later.

Create a new VM in VirtualBox.

I called mine phys, and told VB it will hold a 64-bit version of Ubuntu.
I gave it 2048 MB RAM, and told it not to worry about a start-up disk.

I now have a ~/VirtualBox/phys folder for this VM.

cd ~/VirtualBox/phys

VirtualBox needs a VMDK file to tell it how to manage each of these partitions.

sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0s6 -filename d0s6.vmdk
sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0s7 -filename d0s7.vmdk

Since these new files are owned by root, I ran chown to fix this - you would use your own account name here:

sudo chown phil:staff d0s6.vmdk
sudo chown phil:staff d0s7.vmdk

This makes 2 VMDK files in my current VM directory.


rex:phys phil$ ls -la
total 56
drwxr-xr-x  8 phil  staff   272 26 Jul 21:31 .
drwxr-xr-x  7 phil  staff   238 26 Jul 22:44 ..
-rw-r--r--  1 phil  staff   153 23 Jul 01:21 HOWTO.txt
drwx------  6 phil  staff   204 26 Jul 21:32 Logs
-rw-------  1 phil  staff   633 26 Jul 22:47 d0s6.vmdk
-rw-------  1 phil  staff   634 26 Jul 21:50 d0s7.vmdk
-rw-------  1 phil  staff  7524 26 Jul 21:31 phys.vbox
-rw-------  1 phil  staff  7524 26 Jul 21:28 phys.vbox-prev

Now I added these two physical disk descriptions to my VM.


You do this in Settings - Storage, select SATA, click 'Add Attachment' icon, select Hard Disk, and select your VMDK file. I did this for each VMDK file.

You will also need to add your Linux distribution ISO either using a real CD/DVD or using an ISO stored on your file system somewhere.

Don't forget to make your VM boot from CD/DVD first.

I have been terse here since those actions should be known by anyone who is experienced at creating VMs in VirtualBox.

You can make other changes to your VM if you like, or you can do it later.

You can now boot your VM.

This is where I ran into problems: I could not get Ubuntu to format my d0s6.vmdk partition during install. Instead, I ran Ubuntu's live CD and launched Ubuntu's Disk Utility. It showed 2 disks as expected. I added a GUID partition table to d0s6.vmdk, created a 4000 MB swap partition and a 16 GB ext4 root file system. I then formatted the file system.

Now I installed Ubuntu: I told it to use the swap partition, and to use my 16 GB partition for root. To do this I told Ubuntu NOT to format it again since I formatted it earlier.

I also told Ubuntu to use my existing home drive and again, to NOT format it since I want to keep its data.

My install took hours, so be patient.





Blue-Green Water - Follow up

(Very old draft)

After almost 4 weeks, our blue-green stain has not returned.

The addition of 500 mL of lime raised the pH to nearly 11. Over time this has reduced to below 10 since about 10,000 L of new rain has been collected.

I also noted that the rain water had a pH of about 6. This was a little surprising since our tank water was pH 4.5.

In monitoring the treated tank water I have found that the alkalinity of the water decreases to nearly 7 when left for 24 hours or more. I suspect that this is due to the water absorbing CO2 from the air and this may also explain why rain water has a higher pH compared to our tank water - if left, the pH increases as the water absorbs CO2.

To help confirm this theory, I left two containers of treated tank water to stand. One was over 300mL (pH=9.94) and the other was less than 60 mL (pH=9.83). Both containers had similar surface areas. The idea is that given the same surface area, the two systems would absorb CO2 at the same rate but due to the different amounts of water, the larger body would change pH more slowly. This is what I observed: the smaller decreased pH to 7.15 in less than 24 hours. The larger body had a pH of 7.49.

Note: Although the two samples should have started with the same pH I suspect the smaller sample had already absorbed significant CO2 before I measured it. I delayed measurement for 15 minutes.

Sunday, 20 December 2015

Howto upgrade Ubuntu that is no longer supported.

(very old draft - may not be complete)

Adapted from http://askubuntu.com/questions/501976/unable-to-upgrade-from-13-04-to-14-04/502029#502029

1) Edit apt sources to use "old releases" repositories.
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
But your sources.list file may contain other repositories that have, for me, prevented this process from working.

a) Manually edit /etc/apt/sources.list and comment out these entries


deb-src ...
deb http://archive.canonical.com...
deb http://extras.ubuntu.com...


and comment out any other repositories that were not converted to old-releases.ubuntu.com

b) Change any country specific URLs to 'US' versions

eg. au.old-releases.ubuntu.com to old-releases.ubuntu.com

2) Update packages


sudo apt-get update
sudo apt-get dist-upgrade


3) Upgrade Ubuntu version


sudo do-release-upgrade -d

Friday, 1 May 2015

Howto install smokeping on lighttpd on ubuntu 15.04 linux

Smokeping is a great network and service monitoring tool. But it only configures correctly if you are using apache.

I want to run a very light web server and therefore you need to do some manual configuration to make it work.

1. Install lighttpd.

sudo apt-get install lighttpd

2. Ensure that http://localhost works. You should get page like this:




3. Install smokeping

sudo apt-get install smokeping

4. Enable Lighttpd CGI module

sudo lighttpd-enable-mod cgi

5. Reload Lighttpd

sudo /etc/init.d/lighttpd force-reload

6. Ensure that this link brings up a semi-functional page

http://localhost/cgi-bin/smokeping.cgi

Icons and graphs probably do not work.



6. Create a directory link in /var/www/ as smokeping to smokeping static page files:

sudo ln -s /usr/share/smokeping/www /var/www/smokeping
7. For some reason, lighttpd base directory is /var/www/html. This needs to be changed to /var/www (which I suspect other packages will be expecting).

Edit /etc/lighttpd/lighttpd.conf

Change this line:
server.document-root = "/var/www/html"

to:

server.document-root = "/var/www"

8. Restart lighttpd and smokeping

sudo /etc/init.d/lighttpd restart
sudo /etc/init.d/smokeping restart

Did you get this?



Update to enable fastcgi.

I don't know what fastcgi is, but compared to cgi is is fast.

On my laptop, it is 5 times faster!

1. Copy smokeping.fcgi.dist as smokeping.fcgi

sudo cp /var/www/smokeping/smokeping.fcgi.dist /var/www/smokeping/smokeping.fcgi

2. Edit smokeping.fcgi to point to your smokeping.cgi script

exec /usr/lib/cgi-bin/smokeping.cgi /etc/smokeping/config

NOTE: my file had smokeping_cgi. This seems to be wrong and must be changed to smokeping.cgi

3. Modify /etc/lighttpd/conf-available/10-fastcgi.conf

Add this:

fastcgi.server += ( 
  "smokeping.fcgi" => ((
    "socket"   => "/var/run/lighttpd/fcgi.socket", 
    "bin-path" => "/usr/share/smokeping/www/smokeping.fcgi"
  ))
)

4. Enable Lighttpd FastCGI module

sudo lighttpd-enable-mod fastcgi

5. Reload Lighttpd

sudo /etc/init.d/lighttpd force-reload

6. This link should now work

http://localhost/smokeping/smokeping.fcgi

Sunday, 8 March 2015

Asus Transformer TX201 - Android + Ubuntu 14.10 Linux

  The Good and the gooder (and some bad points)

GOODER:

2 computers in 1. Keyboard is a dual core i5 and tablet is an intel Z2560 (x86)

#Android and  8 and  and whatever else you can install on a x86 PC.

Using android  you don't need a cable.

Once you manage to boot from USB,  14.10 is trivial to install.

UPDATE: I upgraded kernel to 3.18 and then 3.19.

Fast switching between Android and Linux (or Windows). Both run at same time or you can shut down one and use other.

Chargers are small and well designed Asus plug-packs - not bricks.

Easy to open Keyboard to change HDD.

Under Linux, everything seems to work. Screen brightness is not working properly, but it does work. 

UPDATE: Thanks to Viktar Vaŭčkievič and #ArchLinux, I compiled and installed an ALS module which automatically adjusts screen backlight. See https://github.com/victorenator/als.git

Running linux in  mode.

GOOD:

11.6" screen. Could be an inch bigger based on bezel.
Tablet and keyboard have WiFi and Bluetooth.

Tablet  is possible. http://forum.xda-developers.com/showpost.php?p=57341475&postcount=27

SD card on tablet mounts in Windows/Linux. But Ubuntu keeps opening a file manager every time I switch back from Android.

UPDATE: Fixed by Control Panel - Details - Removable Media - Tick 'Never prompt or start programs on media insertion'

Linux kernel modules to support device.

Aluminium tablet and keyboard backs.


BAD:

Matt screen might be better.

No 3G or LTE.

Can not connect 3G modem to tablet (so far).

No Android update from Asus.

No keyboard backlight nor fluorescent key labels.

When screen is open, tablet/screen hinge opens lower than base of keyboard which makes it uncomfortable as a lap-top.

A bit heavy for it's size at 1.7 kg (tablet and keyboard)

Only 2.4GHz WiFi.

UPDATE: But syslog indicates PC might support 5 GHz.

Rear camera does not work on PC.

WiFi (RTL8821) occasionally locks-up. To fix, remove module, put keyboard to sleep (Fn+f2), wake (power button) and load module. Module is rtl8821ae in my case.

UPDATE: This only seems to happen (now) when I tether to an iPhone 5s.

UPDATE: #ArchLinux also had a solution to this - too early for me to confirm that it is fixed. Does not seem to fix.

Thursday, 3 July 2014

Howto install OpenWRT on Netgear DG834 or DG834G (v1 or v2)

Got a spare Netgear DG834 or DG834G? Want to try OpenWRT? Want an easy process?

This assume you are running Ubuntu.


Try this:



0. Before you start...

0.1 Ensure router power plug is secure.
0.2 Ensure LAN cable is clicked into both router and computer.
0.3 Ensure your router is working by opening http://192.168.0.1 (or whatever IP address you have changed it to)

1. Backup router config in case you want to restore factory firmware.

2. Factory default router to ensure it's IP address is 192.168.0.1

2.1 Power on router.
2.2 Hold in reset button until test light (tick) flashes.
2.3 Wait for router to reboot (I think - might have to power cycle it).

3. Run my script to turn on telnet, backup partitions, extract environment file, patch ADAM2 to turn off checksum test, download OpenWRT, split into 2 parts, install patched ADAM2 and OpenWRT parts...

Note: This is not conventional and may not work. But unless you have some hardware fault or power failure, you can fairly easily recover your Netgear using a Netgear image and a small C program called nftp. I'll add instructions below.

3.1 mkdir
3.2 cd
3.3 save my script here
3.4 Run my script like this: 

bash ./pc-setup-wrt-v2.bash

... and follow my instructions.

4. Boot into OpenWRT

4.1 Power cycle router.
4.2 Connect ethernet port - may take 1-2 minutes first time.
4.3 Browse to http://192.168.1.1
4.4 Follow instructions to set password.

Done.

My Script

Save as pc-setup-wrt-v2.bash

#!/bin/bash

# Factory default router
#   Power on. Hold in reset button until test light (tick) turns on.

# Setup PC ethernet interface use DHCP. Disconnect. Connect - should get 192.168.0.2?
#   router should be 192.168.0.1

# test by pointing browser to 192.168.0.1 - should get Netgear Setup Wizard screen
# route del default

# info stuff here

# MTDx partitions using 3.??.32? - seems to have 5 mtdx
# mtd0  0x900d0000,0x903e0000  ROOTFS
# mtd1  0x90020000,0x900d0000  Kernel
# mtd2  0x90000000,0x90020000  ADAM2
# mtd3  0x903e0000,0x903f0000  Probably Netgear firmware config
# mtd4  0x903f0000,0x90400000  Probably ADAM2 config

# Ordered
# mtd2  0x90000000,0x90020000  ADAM2
# mtd1  0x90020000,0x900d0000  Kernel
# mtd0  0x900d0000,0x903e0000  ROOTFS
# mtd3  0x903e0000,0x903f0000  Probably Netgear firmware config
# mtd4  0x903f0000,0x90400000  Prob. ADAM2 config

echo "Install needed packages..."
sudo apt-get install wget
sudo apt-get install expect
sudo apt-get install mini-httpd

echo "Get openwrt image - this is for mtd0 and mtd1 so it needs to be split..."

which wget || { echo "ERROR: wget not installed"; exit 1; }

OPENWRT="openwrt-ar7-squashfs.bin"

[[ -f ${OPENWRT} ]] \
  || wget "http://downloads.openwrt.org/backfire/10.03.1/ar7/${OPENWRT}"

echo "Configure this script..."

# ip address of router - should be 192.168.0.1 after factory reboot
ROUTER="192.168.0.1"

# ip address on this host - should not need to change
HOST="192.168.0.10"

# port on this host that has ethernet cable to router plugged in - should be same
ETH="eth0"

echo "Configure this script (ROUTER, HOST, and ETH) variables."
echo "Disconnect from all other networks."
echo "Next time you run this it will reconfigure your ETH port and "
echo "connect to your router."
echo
echo "If you have configured variables correctly, comment out next line."
exit 0

echo "Split OpenWRT image file..."

OPEN0="ow-mtd0.bin"
OPEN1="ow-mtd1.bin"

which dd || { echo "ERROR: dd not installed"; exit 1; }

dd if=${OPENWRT} of=${OPEN1} count=720896 bs=1
dd if=${OPENWRT} of=${OPEN0}  skip=720896 bs=1

echo "Reconfigure ETH port..."

which ifconfig || { echo "ERROR: ifconfig not installed"; exit 1; }

sudo ifconfig ${ETH} ${HOST} netmask 255.255.255.0

echo "Turn on telnet - assumes your reouter has been factory defaulted..."

LOGIN="--user=admin --password=password"

wget -v -O debug.log ${LOGIN} "http://${ROUTER}/setup.cgi?todo=debug"

echo "Telnet to router, and do some heavy stuff - but nothing dangerous...yet..."

# Assign an IP address to ADAM2 (patch)
# Backup each MTD Block to RAM
# Spawn a HTTP Daemon to download MTD Backups
which expect || { echo "ERROR: expect not installed"; exit 1; }
which telnet || { echo "ERROR: telnet not installed"; exit 1; }

expect >telnet.log <
set timeout 30
set send_human {.1 .3 1 .05 2}
spawn telnet ${ROUTER};                             expect "# "; sleep 1;
send_error "Telnet script\n";
send -h "cat /proc/sys/dev/adam2/environment | grep -v \"^my\" > /proc/sys/dev/adam2/environment\r";
                                                     expect "# "; sleep 1;
send -h "echo \"my_ipaddress ${ROUTER}\" > /proc/sys/dev/adam2/environment\r";
                                                     expect "# "; sleep 1;
send_error "Cat environment file...\n";
send -h "cat /proc/sys/dev/adam2/environment\r";    expect "# "; sleep 1;
send_error "Copy partitions to tmp...\n";
send -h "dd if=/dev/mtdblock/0 of=/tmp/mtd0.bin\r"; expect "# "; sleep 1;
send -h "dd if=/dev/mtdblock/1 of=/tmp/mtd1.bin\r"; expect "# "; sleep 1;
send -h "dd if=/dev/mtdblock/2 of=/tmp/mtd2.bin\r"; expect "# "; sleep 1;
send -h "dd if=/dev/mtdblock/3 of=/tmp/mtd3.bin\r"; expect "# "; sleep 1;
send -h "dd if=/dev/mtdblock/4 of=/tmp/mtd4.bin\r"; expect "# "; sleep 1;
send_error "Copy environment file...\n";
send -h "cat /proc/sys/dev/adam2/environment > /tmp/environment.bak\r";                                                     expect "# "; sleep 1;
send -h "cd /tmp\r";                                expect "# "; sleep 1;
send_error "Start web server...\n";send -h "mini_httpd -p 1080\r";                     expect "# "; sleep 1;
send -h "exit\r";
EOF

echo "Pull files from router..."
wget ${LOGIN} -O mtd0.bin        "http://${ROUTER}:1080/mtd0.bin"
wget ${LOGIN} -O mtd1.bin        "http://${ROUTER}:1080/mtd1.bin"
wget ${LOGIN} -O mtd2.bin        "http://${ROUTER}:1080/mtd2.bin"
wget ${LOGIN} -O mtd3.bin        "http://${ROUTER}:1080/mtd3.bin"
wget ${LOGIN} -O mtd4.bin        "http://${ROUTER}:1080/mtd4.bin"
wget ${LOGIN} -O environment.bak "http://${ROUTER}:1080/environment.bak"

echo "See if correct ADAM2 versio is installed..."

which grep || { echo "ERROR: grep not installed"; exit 1; }

grep "bootloaderVersion.*0.18.01" environment.bak \
  || { echo "HALT: Boot loader version is not 0.18.01"; exit 1; }

echo "See if ADAM2 is already patched..."

ADAM2NEW="mtd2.bin.new"

which md5sum || { echo "ERROR: md5sum not installed"; exit 1; }

MDS2=$( md5sum mtd2.bin | cut -d' ' -f1 )

if [[ "$MDS2" == "d8a2f4623bf6f64b7427812f0e849aa7" ]]; then
  echo "mtd2.bin already patched"
  cp mtd2.bin ${ADAM2NEW}
else
  echo "mtd2.bin not patched"
  echo "Verify ADAM2 file..."
  MDS=$( md5sum mtd2.bin | cut -d' ' -f1 )
  if [[ "$MDS" != "0530bfdf00ec155f4182afd70da028c1" ]]; then
    echo "HALT: ADAM2 (mtd2.bin) MD5 sum does not match"
    exit 1
  fi
  echo "Patch ADAM2..."
  cp mtd2.bin ${ADAM2NEW}
  printf '\x00\x00\x00\x00' | dd of=${ADAM2NEW} bs=1 seek=14660 count=4 conv=notrunc 
  echo "Verify patched ADAM2..."
  MDS2=$( md5sum ${ADAM2NEW} | cut -d' ' -f1 )
  if [[ "$MDS2" != "d8a2f4623bf6f64b7427812f0e849aa7" ]]; then
    echo "HALT: Modified ADAM2 (${ADAM2NEW}) MD5 sum does not match"
    exit 1
  fi
fi

echo "Kill off any legacy http servers (if we have somehow left them running)..."
killall mini-httpd

echo "Start local web server..."
sudo mini-httpd -p 8000 || { echo "ERROR: mini-httpd did not start"; exit 1; }

echo "Download modified ADAM2 and OpenWRT files to router and install them..."

expect >flash.log <
set timeout 30
set send_human {.1 .3 1 .05 2}
spawn telnet ${ROUTER};                           expect "# "; sleep 1;
send_error "Telnet script to install modified ${ADAM2NEW}\n";
send -h "cd /tmp\r";                              expect "# "; sleep 1;
send -h "rm mtd0.bin\r";                          expect "# "; sleep 1;
send -h "rm mtd1.bin\r";                          expect "# "; sleep 1;
send -h "rm mtd2.bin\r";                          expect "# "; sleep 1;
send -h "rm mtd3.bin\r";                          expect "# "; sleep 1;
send -h "rm mtd4.bin\r";                          expect "# "; sleep 1;
send -h "rm ${ADAM2NEW}\r";                       expect "# "; sleep 1;
send_error "Download modified ${ADAM2NEW} from ${HOST}...\n";
send -h "wget http://${HOST}:8000/${ADAM2NEW}\r"; expect "# "; sleep 10;
send -h "dd if=${ADAM2NEW} bs=1 skip=110747 count=5\r";
expect {
  "DG834" { send_error "GOOD: ${ADAM2NEW} contains DG834 string\n"; };
  timeout { send_error "ERROR: TIMEOUT: Did not get DG834\n"; exit;  };
  "# "    { send_error "ERROR: Got prompt instead of DG834\n"; exit; };
}
sleep 1;
send_error "Install modified ${ADAM2NEW}...\n";
send -h "dd if=${ADAM2NEW} of=/dev/mtdblock/2\r"; expect "# "; sleep 20;
send -h "rm ${ADAM2NEW}\r";                       expect "# "; sleep 1;
send -h "rm ${OPEN0}\r";                          expect "# "; sleep 1;
send_error "Download ${OPEN0} from ${HOST}...\n";
send -h "wget http://${HOST}:8000/${OPEN0}\r";    expect "# "; sleep 10;
send_error "Install ${OPEN0}...\n";
send -h "dd if=${OPEN0} of=/dev/mtdblock/0\r";    expect "# "; sleep 20;
send -h "rm ${OPEN0}\r";                          expect "# "; sleep 1;
send -h "rm ${OPEN1}\r";                          expect "# "; sleep 1;
send_error "Download ${OPEN1} from ${HOST}...\n";
send -h "wget http://${HOST}:8000/${OPEN1}\r";    expect "# "; sleep 10;
send_error "Install ${OPEN1}...\n";
send -h "dd if=${OPEN1} of=/dev/mtdblock/1\r";    expect "# "; sleep 20;
send -h "rm ${OPEN1}\r";                          expect "# "; sleep 1;
send -h "reboot\r";
EOF

echo "Shutdown local web server..."
killall mini-httpd

echo "All done."
echo
echo "Power cycle router."
echo "Reconnect ethernet interface - may take 1-2 minutes"
echo "Browse to http://192.168.1.1"
exit 0

Basic Configuration Steps


Save and Apply after each change.

If unsure, power cycle router.

Set password
Set timezone
Set dropbear (ssh) interface to lan

Edit LAN interface
  IP address (WARNING: This gives me most headaches - perhaps leave it alone for a while)
  (When you save and apply, you may need to disconnect/reconnect ethernet interface on pc)
  I set MTU to 1474

Add new (PPPoATM) interface
Set username and password
Set custom DNS servers to OpenDNS 208.67.222.222 and 208.67.220.220
Assign ADSL interface to WAN

Edit Wifi
  Enable
  Set SSID etc.
  Set to WEP and generate WEP hex key somehow.

No WPA???


Sunday, 12 January 2014

Virtualize an old Windows XP disk partition (howto convert disk partition to virtual disk for VirtualBox)

I dug out an old hard disk. I was curious: what gems are stored here?

Turns out there was nothing, but it was in interesting exercise in converting a single disk partition into a VM - something that is not trivial.

I plugged my old drive into a USB hard disk docking station and had a look. It contained Windows XP and Linux from an old PC dating from 2004-2007 I believe.

"Hey!" I thought. I could virtualize this for no good reason and show how easy it is using free and open source software.

Ubuntu Packages

I installed VirtualBox and mbr.

Create VirtualBox VM

  • Select New
  • Name your VM (say TEST)
  • Select Windows and Windows XP
  • Set memory size (default is ok)
  • Select 'do not add a virtual hard drive' - we will create this later in tis VM's directory.

Create Virtual Disk Drive

Open a terminal and change to your ~/VirtualBox\ VM/TEST directory for this example.

Copy and paste my script into your editor.

#!/bin/bash

DISK=/dev/sdd
PART=1

printf "Copy boot sector image...\n"
sudo dd if=$DISK of=mbr.img bs=512 count=1 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

# put 'normal' mbr incase grub or something was used
printf "Replace MBR code..."
sudo install-mbr mbr.img -t 36 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

printf "Copy disk (%s) partition %d...(at 10MB/s 1GB will take 100s)...\n" "$DISK" $PART
PARTIMG=part${PART}.img
sudo dd if=${DISK}${PART} of=$PARTIMG bs=512 || { printf "FAILED\n"; exit 1; }
sudo chown $USER:$USER $PARTIMG
printf "Done\n"

printf "Make VirtualBox VMDK image with MBR...\n"
sudo VBoxManage internalcommands createrawvmdk -filename ./disk.vmdk -rawdisk $DISK -partitions $PART -mbr ./mbr.img || { printf "FAILED\n"; exit 1; }
# VB needs this owned by user
sudo chown $USER:$USER disk-pt.vmdk
printf "Done\n"

# switch to partition image and zero starting offset
# eg.
# from this: RW 8514387 FLAT "/dev/sdd" 63
# to this: RW 8514387 FLAT "/home/phil/Development/pc-part2disk/part1.img" 0
 
printf "Modify VMDK files to use disk partition image...\n"
sudo cat disk.vmdk | sed "s@\"$DISK.*@\"./$PARTIMG\" 0@" > diskimage.vmdk
sudo chown $USER:$USER diskimage.vmdk
printf "Done\n"

# remove VB vmdk that points to physical drive - no longer required
sudo rm disk.vmdk

exit 0
 Change DISK and PART to suit your case. This example uses disk /dev/sdd and partition 1.

Also, run chmod +x

Saturday, 15 June 2013

Howto enable AHCI Mode MacBookPro1,2 and MacBookPro4,1

I added this after insmod ext2 in grub:

setpci -s 0:1f.2 90.b=40

This sets Intel ICH7 (page 509) or ICH8 (page 486) controller into AHCI mode.

A similar command will probably work for other ICHx devices.

I got my bus:slot.function from running lspci - take value from line that states SATA IDE mode

eg.

00:1f.2 SATA controller: Intel Corporation 82801GBM/GHM (ICH7-M Family) SATA Controller [IDE mode] (rev 02)

Both MBP1,2 and MBP4,1 have same bus:slot.function and use same value (40h) to put controller into AHCI mode.

UPDATE: Should be MacBookPro1,2 not MacBookPro2,1