#!/bin/bash usage="Usage: $0 [-p] DEVICE FILE Try \`$0 --help' for more information." help="Usage: $0 [-p] DEVICE FILE Overwrite disk drive DEVICE with the image from FILE. The image is assumed to consist of the first 63 blocks of a disk device (which covers the master boot record and any boot loader code saved before the first partition) followed by an ntfsclone image of the first partition (assumed to be in NTFS format), all compressed with gzip. If the -p option is given, DEVICE refers to a partition rather than a whole disk, and only that partition (assumed NTFS) will be written; the MBR and boot code regions of the underlying disk device will not be changed. This is useful for re-imaging the main Windows partition on computers where other partitions (e.g. Linux partitions or spare data partitions) have been created, though care must be taken that the MBR in such cases is compatible with the partition being written. Examples: $0 /dev/sda /mnt0/image.gz $0 -p /dev/sda1 /mnt0/image.gz Author: Stephen Thomas 24-Mar-2006" if [ -z "$1" ] then echo "$usage" exit 1 fi if [ "$1" == "--help" -o "$1" == "-h" ] then echo "$help" exit 1 fi if [ "$1" == "-p" ] then mode=partition shift device="${1:-/dev/hda1}" dd_out=/dev/null ntfs_out="$device" else mode=disk device="$1" dd_out="$device" ntfs_out="$device"1 fi file="${2:-image.gz}" echo "About to overwrite $mode $device with image from $file." read -p "Is this OK? (y/n) " if [ "${REPLY:0:1}" != y -a "${REPLY:0:1}" != Y ] then exit 1 fi zcat "$file" | { dd of="$dd_out" bs=512 count=63 if [ $mode == disk ] then sfdisk --re-read "$device" fi ntfsclone --restore-image --overwrite "$ntfs_out" - }