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