# Minimizing Hard Disk Drive Failure and Data Loss/Popdisk
## Cloning NTFS file systems (and others too)

Backup and restore of NTFS partitions with knoppix to/from a windows share

## Example scripts

Before making a backup, a folder can be prepared with the foldername being the hostname of the PC to backup. The backup script should be copied to the folder and customized to match the partitions to backup. Then to create a backup the share is mounted from knoppix and the user moves into the directory and executes the script. The backup is completed.
The restore script should then be copied to the directory and customized to match the partitions (like the backup script) After the backup is made, the backup script can be deleted or moved to a new folder inside the directory for reference. To restore, the same process of mounting the share - navagating to the folder - then executing the restore script will complete the restore.
Backup of sda2 (ntfs partition)
Restore of sda2 (ntfs partition, disk must be the same size as the original)
Backup of linux partitions
Restore of linux partitions (also re-create swap partition sda3)
Note: Fat32 and other partition types can also be backed up efficiently using partimage. NTFS is one partition type that partimage does not work well with yet (AFAIK), therefore ntfsclone is used above.

## Limitations

* Can only restore to the same size disk, because of the dd and sfdisk method of restoring the master boot record and partitions. There are some ways to overcome this limitation but I have not tested and fine tuned them yet.
* When restoring a complete linux system, the grub config may have to be adjusted to point to the partitions by number, instead of by name, which many newer linux distributions tend to do nowdays.

## Other Thoughts - Wish list

* The scripts will work on other destination types besides windows shares. That is the beauty of using knoppix type boot disks. Maybe some howtos on mounting file systems would be in order here. Live linux CDs can mount at least the following File systems... to send the backups to:
** Local partitions (NTFS,FAT32,EXT2,EXT3 are the main ones)
** USB drives
** NFS shares
* Would like to create a script generator, that examines the local disks and interactively creates a backup and restore script to match. This will be fun and maybe very useful :)
* Create some scripts to backup to a local CD/DVD drive, and make them bootable.
* create a stripped down, fast booting live linux CD that only has the tools for disk imaging

## Misc. Tips

Reseting the bad sectors list after cloning
When you clone a partition from a disk with bad sectors to a new disk, Windows still reports bad sectors on the new disk. This is because, by design, ntfsclone copies everything, including the bad sector list.
While this is not strictly ntfsclone-related, some people may use the following procedure to reset the bad sector list after cloning:
* Back up important data from partition just in case
* Find out size of '$Bad' attribute in $Badclus using ntfsinfo with ntfsinfo -i 8 <partition>. It will be the “Allocated size” value in the “Dumping attribute $DATA (0×80)” (there will be two 0×80 attributes. Only one has an “Allocated size” line).
* Use ntfstruncate <partition> 8 0x80 '$Bad' 0 to set $Bad's attribute length to zero.
* Use ntfstruncate <partition> 8 0x80 '$Bad' <ntfs_size> to set $Bad's attribute length back to proper value which was recorded in step 2.
* Boot into Windows and run chkdsk. It will find errors and should fix them.
Unless you're certain that the bad clusters were just an error, It is recommended to do a full surface scan using either your hard disk manufacturer's tools or chkdsk /r after doing this. This paragraph copied from http://www.linux-ntfs.org/doku.php?id=ntfsclone

## Further reading

* UNIX Computing Security/Data security