I can see partitions but not even one harddisk.
How can I see my harddisks and clone them?
You clearly cannot clone a larger partition to a smaller partition (using
dd and the like) since there is simply not enough space.
However, if the files that are on the larger partition would also fit on the smaller partition, you could use
rsync to copy those files. The exact options to use depend on your particular use case, but to simply copy all the files the following should do:
rsync -av /mount/point/of/large/partition/ /mount/point/of/small/partition
Edit: Once again: You cannot clone a larger partition onto a smaller partition. (But do read on, your problem can be solved yet.)
The reason is simple: your source partition is bigger than your target partition. What do you expect? Should some blocks just be dropped? Which ones? And how should
dd know? Of course, you could use
count= options to only copy the first so-and-so-many blocks of your source partition such that it fits onto your target partition, but you will end up with a broken partition. That is certainly not what you want.
So, since you cannot clone a larger partition onto a smaller partition, the only thing you could do is to first reduce the size of your source partition to a size smaller or equal to that of your target partition with something like
gparted which is aware of the filesystem specifics, such that you do not lose data. And only then could you use
dd to clone the partition. Ideally, the new size of your source partition should be equal to the size of your target partition (and not just smaller or equal), or else you will end up with some unallocated space on your target partition after the cloning.
Please also note that you should not simply copy an MBR of a larger drive onto the MBR of a smaller drive (or vice versa, for that matter). The MBR, which has a size of 512 bytes and is the first section of your hard drive, contains information on the layout of the harddrive:
If you insist on cloning the MBR, then only clone the first 446 bytes like so:
dd if=/dev/source of=/tmp/mbr.bak bs=512 count=1 dd if=/tmp/mbr.bak of=/dev/target bs=446 count=1
/dev/target with the device names of the source and target harddrives, e.g.,
/dev/sdb, respectively. (More information is available here.)
However, the proper way to do it would be to do a clean Grub reinstall (or whatever you have on your MBR) on the new harddrive.
Summing up, if you want to clone a larger drive onto a smaller drive, proceed as follows:
Lay out a partition table on the target drive with as many partitions as on the source drive. There should be a one-to-one correspondence between the partitions on your source drive and the partitions on your target drive, except that (some of) the partitions on the target drive can be smaller than their corresponding partitions on the source drive. Use a tool such as
cfdisk for that.
For each partition on the target drive which is smaller than its corresponding partition on the source drive, reduce the size of this corresponding partition on the source drive to match the size of the partition on the target drive. Use a tool such as
gparted for that.
For each partition on the source drive, issue the command
dd if=/dev/sdaX of=/dev/sdbY
... to clone the partition
/dev/sdaX from the source drive to the corresponding partition
/dev/sdbY on the target drive (replace the device names appropriately, of course.)
If you insist on also cloning the MBR, use the two
dd commands written further above in this post (those with the
/tmp/mbr.bak stuff). However, keep in mind that a clean Grub re-install would be better.
As first you need to find out data about your HDD, you can do this by typing in terminal:
sudo fdisk -l
You should get an output like this:
Disk /dev/sda: 149,1 GiB, 160041885696 bytes, 312581808 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 Disklabel type: dos Disk identifier: 0x06bd4abe Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 230055935 230053888 109,7G 83 Linux /dev/sda2 292970494 312580095 19609602 9,4G 5 Extended /dev/sda3 230055936 292968447 62912512 30G 83 Linux /dev/sda5 292970496 312580095 19609600 9,4G 82 Linux swap / Solaris Partition table entries are not in disk order.
So lets say /dev/sda3 is the drive you want to clone, then you can do:
dd bs=512 if=/dev/sda of=/dev/sdb1/partition.ddfile seek=230055936 count=$(expr 292968447 - 230055936)
Remind this here are only examples you would need to fit that to your situation.