February 2008 Archive

Overwrite MBR from Linux

February 21st, 2008

If, like me, you are experimenting setting up usb drives as bootable Linux devices then you’ll find that after installing grub on the drive just deleting all the files will not remove grub. You need to completely wipe the Master Boot Record (MBR). Assuming your drive is located at /dev/sdb use this command as root:

dd if=/dev/zero of=/dev/sdb bs=512 count=1

Be very careful to do this on the correct drive! One error and you will wipe the MBR on your main hard drive leaving your computer unable to boot.

MS Access problems with fields of data type byte

February 13th, 2008

I was writing some VBA code in MS Access today and discovered some strange behaviour when inserting values into a table field when the data type of the field is set to byte (Byte variables are stored as single, unsigned, 8-bit (1-byte) numbers ranging in value from 0-255).

To recreate the problem simply create a new table with one field of type byte, this can be done by running the following SQL statement:

create table test (id byte)

Next run the following code:

insert into test values (1000)

If you look at the value actually inserted into the table it shows the value 232. There is no warning of invalid data type or out of range warnings, it just goes ahead and inserts the result of the VBA Mod function on 1000 mod 256. The Mod function is defined as ‘Divides two numbers and returns only the remainder’. If you try it with the value 513 it will insert the value 1.

It can be of no coincidence that a VBA byte can have a maximum value of 255. The most worrying thing here is that it converts my integer to a byte result and inserts the value without any warning. If you were trapping errors at this point to trying to catch someone inserting an integer or long value into the field then you’ll never know an error has occurred as no error is thrown.

Even more strangely in VBA code if you open a recordset on the table and add an integer using AddNew method then an error IS thrown, but if you execute the equivalent SQL statement using a command object NO error is thrown. The AddNew behaviour is shown below.

Dim rs As New ADODB.recordset
Dim cn As CurrentProject.Connection
With rs
	.Open "select id from test", cn, adOpenForwardOnly
	.AddNew
	.Fields("id")=1000	'throws an error
	.Update
	.Close
End With

The next code using the command object does not throw an error.

Dim cmd As New ADODB.Command
Dim cn As CurrentProject.Connection
With cmd
	.ActiveConnection = cn
	.CommandText="insert into test values (1000)"
	.Execute      'no error
End With

It seems to me that running an SQL statement from either a query window or through the ADODB command object uses some different method whereas the AddNew method bypasses this thereby raising the correct error.

Of course the lesson here is to check your data before trying to insert it into the database rather than catching errors caused by invalid data.

Damn Small Linux on a bootable USB drive

February 6th, 2008

I’ve tried a few times to create a bootable USB drive, usually from within Linux, and every time it’s failed. Lately I’ve started to put a bit more effort in as I think the need to have a portable sysadmin toolkit that I can run on any computer (if it will boot from USB) is invaluable.

How many times are you sitting in front of a friends computer trying to diagnose a problem wishing you had another computer available to use as an independent check. With a bootable USB containing a minimal Linux install this is exactly what you have.

Simply insert the stick, reboot and have all your favorite Linux tools available without touching the hard drive. And if you do need to access the hard drive you can, fixing a corrupted Windows MBR is one example that comes to mind.

Anyway the method that finally worked is documented here:

http://damnsmalllinux.org/wiki/index.php/Installing_to_a_USB_Flash_Drive#Method_I

It’s ironic that I needed to use Windows to get a Linux based USB drive to work, even using Linux tools in the process (syslinux). It’s a situation I’m not that happy about so I’ll keep trying other methods from within Linux.

But in the meantime I’m happy it worked and DSL seems fine, it boots pretty fast, even from USB, and is very snappy to use. My main gripe at first glance is lack of NTFS support.

More Vista Network Problems

February 6th, 2008

After my recent problems with networking in Vista I’ve come across even more serious issues.

Last weekend we visited my girlfriends brothers who bought a new computer last year but have never been able to get it connected to the internet. It’s common in many flats in Denmark that the building has it’s own internet connection that is then shared amongst the flats; basically creating a LAN in the building. It’s fast, cheap and if it fails then it’s not your problem to fix.

I was trying to get a connection (they have Vista Home Premium) but all it kept saying was that the LAN connection could not be identified. I tried every possible fix but nothing would get me a valid IP address. Her brother told me that they had been warned that the buildings LAN didn’t work with Vista and they should get a router to connect through so they had bough one just in case.

Sure enough as soon as I connected the router everything worked without a hitch, they router was assigned an IP address and the router gave out an IP address to the computer.

The sheer fact they they were forced to spend money on a router that should be totally unnecessary amazes me. It basically means that everyone in their building buying a new computer will have to also buy a router, unbelievable!

This exercise in futility also made me think more about carrying around a bootable USB with some Linux distribution installed, or maybe a Linux Live CD to be used for testing and diagnostic tasks. One of the problems I had was that I couldn’t easily tell if the problem lay with Vista or maybe there was no internet connection at all. If I could have booted into Linux I could have easily diagnosed the problem and been sure it was with Vista from the start.