Saturday, May 21, 2011

Image backup of Windows XP with diskdump - dd

Today I set up a Thinkpad T60 with a clean install of Windows XP SP3. Because there ar no real nice built-in features for backing up the whole disk as an image file in XP, I used the famous dd for that. I took an gparted live cd, but any live linux should do the trick.
First mount the media where the image should be copied to
me@linux:~>mount /dev/sdb1 /mnt
and create a folder where you want to store the image file
me@linux:~>mkdir /mnt/Backup
and now copy the whole disk with dd
me@linux:~>dd if=/dev/sda1 bs=1M | gzip -c > /mnt/Backup/sda1.gz
To save a lot of disk space I piped the dd output through gzip. This stored the image of an 60GB hard disk with 14GB of used space into a 10GB image file. Without zipping one would store the whole 60GB. To restore the backup to the disk you could use
me@linux:~>cat /mnt/Backup/sda1.gz | gzip -d | dd of=/dev/sda bs=1M
Finally just out of precaution I also saved the MBR of the hard disk to a file
me@linux:~>dd if=/dev/sda of=/mnt/Backup/mbr.img bs=512 count=1
In case of emergency I would copy it back with
me@linux:~>dd if=/mnt/Backup/mbr.img of=/dev/sda bs=512 count=1

As always, be very careful if you don't know what you're doing and RTFM. Messing with dd and hard disks can easily kill your weekend.

cheers

Thursday, May 19, 2011

Open / Close firewall on Windows 7 via Batch script

Because I am a paranoid SOB I normally lock down my Windows 7 firewall for any kind of incoming and outgoing traffic. Only for programs that really need to connect to the big bad web I define custom firewall rules.
But sometimes I need to allow outgoing traffic for getting program updates or using a service that requires an internet connection. To click throuth the GUI in Windows to finally get to the firewall settings is kind of annoying. So I wrote two little batch scripts (each is a one-liner ;-) ) and put links to them into my start menue. And voilá...I can easily allow / block outgoing connections.
For opening the firewall for outgoing traffic you can simply put
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound
into a file wich you can name FWallowOUT.cmd for instance. Save this somewhere on you machine and create a link to the file in your start menue. Don't forget to give administrative privileges to it. The same thing you can do for blocking the outgoing traffic again
netsh advfirewall set allprofiles firewallpolicy blockinbound,blockoutbound
Easy and simple. For detailed information about netsh and advfirewall read the man-pages or check Microsofts Technet.

cheers

TAR and GZIP or the command I always forget

As simple as it may seem I always forget the command line options for tar to unpack a tgz-file. And to avoid 'googling' I will put them here once and for all...

For creating one can use:
tar cfvz [file].tgz [path] [file]
and for extracting:
tar xfvz [file].tgz
cheers

Saturday, February 5, 2011

Cloning a VirtualBox vdi-file

OK,
this will be a short one. I did this with VirtualBox 4.0 on a Windows 7 64bit machine.
I had and still have a vdi-file which is simply a virtual disk that contains a virtual operating system. For me this is a virtual Windows XP SP3. I have to point out that my virtual machine did not contain any snapshots. So I don't know what happens if you try this with a virtual machine that contains one or more snapshots.
To try different software in a kind of safe environment I use virtual machines a lot. But one can not simply copy a virtual disk to another folder and use it as another virtual system because VirtualBox internaly registers the vdi-files with its UUID which is unique for every vdi-file. So you can not use two virtual systems with the same UUID with VirtualBox. The solution is to change the UUID of the copied vdi-file the following way.
First I copied the original "winxp.vdi" to "winxp-clone.vdi". Then I opened a command prompt and changed to the location "D:\Virtualdisks" where my virtual disks are stored. There I issued the command:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands sethduuid "d:\Virtualdisks\winxp-clone.vdi"
I gave the full path to be sure that everything behaves as expected. And after generating a new virtual system in VirtualBox with the same settings as the original one, I could assign the cloned vdi-file to it.

cheers