I need to clone (replica) entire HD "A" to HD "B".
Remove HD "B" from your NAS and attach it directly to the system where HD "A" is. Then you can clone with pv
or dd
, ddrescue
, or even with cp
or cat
I think, and it can be as straightforward as
sudo dd if=/dev/sda of=/dev/sdb
Use the options you need. (BTW, in your example conv=notrunc,noerror
makes no sense. It would make sense with the first dd
.)
And it's true you shouldn't do this when any filesystem from /dev/sda
is mounted with write access or /dev/sdb
is mounted in any way. This is what happens when your source can change during sequential cloning.
Your target disk (its partitions, filesystems and files) may or may not be seen by the NAS when you reinstall the disk there. The NAS may write some changes and spoil the clone (e.g. it may or may not change bootloader data in MBR and following sectors).
I know you want a solution where the target disk sits inside the NAS all the time. This is hard because your NAS doesn't expose the disk (the device) for you nor its partition(s), nor filesystem(s). It exposes files (existing in EXT3 filesystem) using CIFS/SMB, NFS, AFP or HTTP/HTTPS. To clone to the disk you need to be able to write to it on a sector level – I think your NAS won't let you do it just like that.
I said "this is hard", not "impossible", because if you could gain SSH access (or telnet, or so) to your NAS then you might be able to write to the disk on a sector level. You might find a Linux(?) shell with standard tools and maybe you could do something similar to this (from live Linux distro on a PC where the HD "A" is):
sudo dd if=/dev/sda bs=1M conv=notrunc,noerror | pv | ssh root@192.168.1.2 "dd of=/dev/your_target_disk bs=1M"
Or use nc
to stream your data.
Edit 1. Although I'm not convinced this will work with the NAS in question (or any other NAS), I'm adding the nc
-based solution because the OP explicitly requested it (in comments). The following solution will work for sure for "NAS" that is a regular computer with Linux.
Before you tell your NAS to listen for incoming data and pass it to the device, you should make sure no other process writes to the target disk; umount
it if you can or at least unshare the device in the NAS configuration. Then:
# log in to NAS
nc -l 3210 | dd of=/dev/sda
The number 3210
is a port number, you can choose it from the range 1024..65535
. Replace /dev/sda
string with the right device. From now on your NAS awaits incoming connection. If somebody else connects to it on the chosen port then their data will be written to the device, but in a home environment this is hardly a concern. However if you are concerned about this then you should know nc
will accept one connection only (one at a time and one in total i.e. it will exit when the first connection terminates). So if you successfully connect in the next step then you will know nobody else did.
Next tell your OS with the source disk (HD "A") to read it and push the data to the listening nc
on your NAS. As /dev/sda
should not be mounted (strictly: it can be mounted, but read-only only), you'd better perform this step from within some live Linux distro.
# where HD "A" is
dd if=/dev/sda | nc 192.168.1.2 3210
Use the dd
options you need (like conv=notrunc,noerror
). Note the 3210
is the listening port number I chose in the previous step.
In practice you may want to monitor the progress, so the better command may be:
dd if=/dev/sda | pv | nc 192.168.1.2 3210
Or you can request dd
to report its progress by passing the USR1
signal to it. Run the following in another terminal:
kill -s USR1 $(pidof dd)
and the information will appear in the terminal where dd
runs.
After dd
finishes and there's no error (on neither side), you should reboot the NAS gracefully. It's very important to let it sync
the target disk so don't just cut the power. Use whatever way of proper reboot or shutdown your NAS offers you.
Edit 1 ends here.
If you succeed in doing this then normal NAS operations may or may not spoil something in the clone, just as if you reinstalled the disk directly cloned to.
Few comments suggested to mount the share and write to it on a file level. You have at least two options:
- you copy files (e.g. with
rsync
);
- or you write the entire image of your HD "A" as a file placed in a filesystem on HD "B".
Both methods may be useful but neither is cloning. You won't be able to replace HD "A" simply with HD "B" as you want. Moreover the latter method won't work at all in your particular case because it needs free space on HD "B" filesystem to be bigger than the whole HD "A" (this restriction may not stand if you use sparse file, but you cannot use one with NFS, SMB etc., can you?). You may write a compressed file and it may fit, yet this is even further from cloning.
rsync
to copy the content, while leaving of the destination disks filesystem type, geometry, etc to the NAS. that way you get resumability if the process needs restarted and file-level integrity checking.rsync -axHAWXS --numeric-ids --info=progress2 /path/to/src /path/to/share/mount/
superuser.com/questions/307541/…