Unix based rescue disks can be used to efficiently move an existing NTFS file system to a new disk using the common utility ntfsclone. ntfsclone only copies individual partitions, not the entire disk, so additional utilities will need to be used. Reasons for using this setup are:
Note: With all these procedures, it is best to start with a clean file system. Run a scan disk (from inside Windows, or using chkdsk C: /f /r before you do anything, if possible.
Note: After any of these procedures, the NTFS partitions should be marked as dirty, meaning Windows will automatically perform a chkdsk on them. Do not bypass this; let Windows perform a disk scan and attempt to fix errors. If by some chance this is not initiated automatically, manually perform a scandisk on the file systems.
You will need the following tools, generally available on all Linux distributions.
All of these tools can be found on several “live” image distributions which can be burned to a CD or USB. Two of my favorites are systemrescuecd and Knoppix, but just about any live Linux CD will have them.
Following example assumes your old disk is /dev/sda, with two partitions, /dev/sda1 and /dev/sda2. We have a new disk, /dev/sdb, which is the same size or larger than the sum of space used by /dev/sda1 and /dev/sda2.
Be Very Careful forgetting which disk is the target and which is the source can result in loss of data. Make backups, and read each command carefully before executing. This is especially important with the command ntfsclone, which is counter-intuitive.
# copy MBR, first 446 bytes in disk dd if=/dev/sda of=/dev/sdb bs=446 count=1 # copy the partition table to the new device. # New device MUST be same size or larger than original one sfdisk -d /dev/sda | sfdisk sdb # optional, set DMA on both drives to speed access hdparm -d 1 /dev/sda hdparm -d 1 /dev/sdb # use ntfsclone to copy from /dev/sda1 to /dev/sdb1 in rescue mode ntfsclone --rescue --force --overwrite /dev/sdb1 /dev/sda1 # copy second partition ntfsclone --rescue --force --overwrite /dev/sdb2 /dev/sda2
ntfsclone is also very good for making an efficient backup of an NTFS partition. Save the output to a file instead of a partition; it will create an output file only large enough to store the data on the partition. Adding compression will further reduce storage requirements
ntfsclone --output - /path/to/partition | pbzip2 -c > /path/to/image/file
Note that pbzip2 uses a nice threaded setup that will max out all of your processor cores, resulting in an amazing space reduction. In one test, a 500G partition image with 172G used space, including all programs and the operating system, was compressed into a 25 gigabyte file. Since ntfsclone “zero fills” unallocated sectors, compression gives you fantastic results.
Disk images can be a single file or an LVM2 logical partition or something that is not a physical device. In this case, you need to work with the partitions embedded in the image.
There are some older ways of directly accessing the partitions, but if you have the command
kpartx (available on most Linux systems), it can be used to tell mapper to “break apart” the image and make an entry in /dev/mapper with the partitions.
# display what will happen first kpartx -lv /path/to/lv/or/diskimage # now, actually add the partitions to /dev/mapper kpartx -av /path/to/lv/or/diskimage ######## do your work ########## # unmap the partitions kpartx -dv /path/to/lv/or/diskimage
In this case, kpartx -av will create the mapping and show you the resulting paths to the partitions. They are generally the same as the device itself, with the partition number at the end. You can now work with the partitions as if you were working with a disk partition; cloning and restoring.
I use gparted to do my resizing because it is so simple. The only problem is that it is GUI based, so requires an X-Windows interface to run. gparted can extend, contract or move an NTFS partition without data loss. This is included in many live cd images, or you can download a live cd specifically for gparted.
That being said, here is how to manually resize without resorting to gparted, so no GUI.
# manually reduce /dev/sda2 to 100G. # /dev/sda2 has less than 100G of data on it. ntfsresize --size 100G /dev/sda2 fdisk /dev/sda2 # in fdisk, use the "p" option to display the current partition scheme # then delete /dev/sda2 # Add /dev/sda2 starting point # and extending it to 100G
The opposite, enlarging a partition, is done just backwards from reducing
fdisk /dev/sda # use the 'p' command # delete /dev/sda2 # recreate it from the same starting point # and extending it out to whatever size you want ntfsresize /dev/sdb # with no size parameters, ntfsresize will grow # to the size of the partition
While there are no known issues with either ntfsresize or fdisk, there is always the chance you'll mess up and trash something you didn't want to, so it is definitely good to make a backup.
You'll see why I like gparted! The authors have done a great job bringing together the ntfs-progs toolbox and partition tools. Makes it less likely to mess up.