Removing the MBR/partition information

Note: By running any of the following commands you may cause your system to become un-bootable. Best make backups of the MBR prior to trying anything within. Use at your own discretion.

URLs:

Ben Okopnik wrote a good article on the linux gazette site called “Clearing out the Master Boot Record”. I was wanting to clear the MBR/partition information so that I could reboot the system and re-intstall using DHCP/TFTP/bootp etc… The BIOS is set to boot of USB-CDROM->HDD->Net/None. So, unless the system failed to boot/find the MBR I couldn’t rebuild. (The system was remote and only reachable via the installed TCP/IP settings and respective OS’s).

It turns out it’s fairly simple to delete the MBR from within Linux:

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

The above dd command deletes both the MBR and disk partition information on device hda. Ideal for what I wanted. You could of course backed up your MBR with:

dd if=/dev/hda of=mbr.bin bs=512 count=1

So, after rebooting the linux system it started building off the build server.

Windows was a little bit harder to find information about deleting the MBR. On the Linux Gazette article it said:

DOS-based solution

Boot with a DOS floppy that has “debug” on it; run “debug”. At the ‘-‘ prompt, “block-fill” a 512-byte chunk of memory with zeroes:

f 9000:0 200 0

Start assembly mode with the ‘a’ command, and enter the following code:

mov dx,9000
mov es,dx
xor bx,bx
mov cx,0001
mov dx,0080
mov ax,0301
int 13
int 20

Press <Enter> to exit assembly mode, take a deep breath – and press “g” to execute, then “q” to quit “debug”. Your HD is now in a virgin state, and ready for partitioning and installation.

Although I could type in all the commands I kept hitting an exception when I pressed “g” to execute. Windows would send a popup box saying something along the lines of “NTVDM encountered a hard error”. After rebooting the system came up so the above doesn’t work unless you boot up using a boot disk.

After a bit more searching I found TestDisk which is:

TestDisk is a powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

Using this software on Windows it allowed the deletion of the MBR/partition table by simply downloading, extracting and running one command.

Rebooting the system now allowed me to get on with re-installing the machine over the net.

SQL Express

Had to migrate a site from a remote server onto a Windows virtual server (Virtuozzo) running Plesk. The site had a database running on SQL Server 2005, but, by default Windows Plesk virtual servers only run MSDE. The database also had stored procedures, which, MSDE doesn’t support. So, needed to install SQL Express 2005.

I was provided with a .bak file of the SQL 2005 database, so, I installed a temporary SQL 2005 server and imported/restored the database. For some reason I was not able to restore the database directly to a SQL Express 2005 server, hence, installing the full version as a go between.

On the Virtuozzo hardware node I installed a SQL Express 2005 application template (saved the .efd file to Vz\Templates\__cache and then ran vzpkgdeploy -i <pkgname>) supplied by SwSoft and then installed it into the VE via VZMC.

The new install of SQL Express didn’t:

  • Have sa access, although, was in authentication mixed mode (required by plesk). I had to enable the sa user through management studio and change password. Then, could add database server to plesk.
  • Support remote logins (over TCP) was note enabled. Had to open SQL Server Configuration Manager, drop down SQL Server 2005 Network Configuration and select Protocols for SQLEXPRESS. Enabled TCP/IP temporarily.

In Plesk I added the new database server… to have two MSSQL database servers I also needed to upgrade Plesk from 7.5.6 to some version of 8 (went to 8.2). The Plesk 8.2 application template didn’t install properly on the virtual server and need SwSoft technical support to fix it.

[ Days later ] … Now Plesk was fixed, database server was added, I could create the database under the clients site in Plesk.

On my temporary SQL 2005 server I ran SQL Server Management Studio and connected to both the full SQL server and the SQL Express server on the virtual server. The full version of SQL 2005 still had the database I previously restored onto it, so, I was able to click on the new SQL Express database and then select Import.

I used the data source “SQL Native Client” and specified the server name of the full SQL server and selected the database. Next, I was able to select the destination details which of course was SQL Express 2005 running on the virtual server.

Then selected “Copy data from one or more tables or views”. Selected all tables and then executed. Management studio told me that “The execution was successful”.

Edited the web applications Web.config to point the local database. I previewed the site with the Plesk site preview option: http://192.168.0.1/$sitepreview/site.co.uk/app/

Didn’t work as I hadn’t copied over the stored procedures and the site returned: Could not find stored procedure ‘dbo.usp_tblSetting_SelectAll’.

Going back to the Management Studio I selected the database on the full SQL server and selected Generate Scripts. Pretty much left defaults and then selected ‘Stored Procedures’ and selected ‘Script to new Query Window’. I selected the database on the SQL Express server and then copied the query window into a new query window (no doubt an easier/quicker way to do this) and executed it. The site started working.