The most info was described in previous inserted recipies, but not all was described.
Under linux you can clone hard drive or partition by dd command.
Attention, when you'll make a mistake, you will lost all your data.
At first, destination should not be in use, secondly source should be not used, or remounted into read only mode. Otherwise copy will be damaged.
If remounting is impossible, please make bootable drive (hdd/ssd/pendrive) any linux live distro. I prever knoppix, but this is your choose. If it is possible, you can boot or change system level into 1, for single user mode, or you can directly reboot system into single user mode, it is distro depended.
If you'll clone only one partition, this partition should be unmounted or remounted into RO:
remount -o,ro /mountpoint_or_device
If you want clone entire hard drive, you must umount or remount all partitions.
You must identify source and destination device. please look at the dmesg, here is stored all needed info about device, with vendor etc. alternatively identifying can be based on device size, if it is different.
Next, destination should be the same or bigger than source. you must calculate source, for example:
fdisk -l /dev/sda
except partition geometry (there can be GPT), you will fetch:
1. total disk size wigh GB and bytes
2. historical geometry and total sector number, very important info
3. block size in bytes, usually it is 512.
# fdisk -l /dev/sda
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f1d1e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 40136703 20067328 83 Linux
/dev/sda2 40138750 41940991 901121 5 Extended
/dev/sda5 40138752 41940991 901120 82 Linux swap / Solaris
next let's try bigger than 512 divider, we have 41943040 physical sectors:
41943040 / 256 = 163840 , very good, we can do bulk copy of 256 sectors. can we more? let's try:
41943040 / 1024 = 40960 , I think this is enough, we will select this one.
Let's count size of sector group:
512(sector size) * 1024 = 524288 bytes eq 512K . Then we can use parameter bs=512K or less, but divide this by 2^x. For modern hard drives with big internal cache, this is practical enough. for older drives with much smaller cache, value 32K or less is enough.
Then after preparation we can do a copy:
dd if=/dev/source_devide of=/dev/destination_device bs=32K and copy will be done. Pay attention, any mistake will overwrite your importand data.
On destination all will be overwritten.
If you try rescue data on damaged source disk, better use native sector size, usually this is 512 bytes, and add option conv=notrunc . otherwise holes in source dropped by bad sectors will be joined by sector shifting on destination. This will damage copy with few chance for repair. then command will be:
dd if=/dev/source of=/dev/destination bs=512 conv=notrunc
, and wait long time when drive and system will give up and will walk sector by sector to the end.
dd is usefull tool for moving partition into new place. Simply create partition, make dd to new partition (this can be bigger, much bigger), and if it is possible, expand copied file system for filling all new partition, ext3/ext4/xfs/zfs/btrfs have this facility. Finally you must change /etc/fstab , then umount/mount if it is possible, or reboot system.
Of course you can clone any type of partition. dd command doesn't look into file system type, it do nothing with its structure. then this command can be usable for cloning NTFS or other partition types.
There is any trick. When you didn't set of parameter, then dd will put output into its stdout. then you can make compressed raw copy of disk or partition, for example:
dd if=/dev/sda bs=512 | gzip >/any/place/computerOne_sda.gz
Of course this should be done offline. you can restore this by:
zcat /any/place/computerOne_sda.gz| dd of=/dev/sda bs=512
, then all sda hard drive will be overwritten by this backup, and all current data will be lost. You can do this also with NTFS windows partition and hard drive used by this. Of course you can use other compression command, depended by your choose.
ddoptions for skipping bad blocks - which is essential when cloning disks for recovery. I added a better answer, which can clone disks having bad blocks:
dd if=/dev/sda of=/dev/sdb bs=4096 conv=sync,noerror
dd, or pipe the data through
head -c …for anything else; but I'm not sure how to find the exact number of bytes yet, or at least a good upper bound)
ddprogram is unnecessary. You can use
catfor reading from a block device, and write to a regular file using a redirect. And you can write to a block device with
tee. Then you won't have to guess a good block size, and it's likely going to be faster too. And if the source disk is in bad condition, then
ddisn't a really good option too, use
ddrescueto save data from damaged disks instead.