Score:1

.img file restore to disk partition

by flag

I had created a backup.img file from a hard disk having two partitions. Now I want to write these partitions to another hard disk. But the problem is I don't know how? If I use dd than it write the complete backup.img file to one partition and then I see nothing there. Please help.

Edit 1 dd if = /XXX/backup.img of = /dev/sdb1

Actually sdb have many partitions so I can not write backup.img to complete disk.

ChanganAuto avatar
us flag
Which dd command are you using?
Score:2
jp flag
  • If you made the image of the whole drive for example /dev/sdb then you should restore it to a whole drive.

  • But if you made the image of a partition for example /dev/sdb1, then you should restore it to a partition.

You can check for the content of the image file with kpartx. It can see directory structure, if there is one (and not only a file system sitting at the head end of the image). See this example,

Map:

$ sudo kpartx -av t-3.5g.img
add map loop0p1 (253:0): 0 6293372 linear 7:0 503907
add map loop0p2 (253:1): 0 1954 linear 7:0 1953
add map loop0p3 (253:2): 0 500000 linear 7:0 3907

Delete map:

$ sudo kpartx -d template-3.5GB.img

Please notice that the devices for partitions will probably look like this, when seen by other tools:

/dev/mapper/loop0p1
...

Another example,

$ sudo kpartx -av lubuntu-18.04.5-desktop-amd64.iso
add map loop0p1 (253:0): 0 2345472 linear 7:0 0
add map loop0p2 (253:1): 0 4928 linear 7:0 2314176

$ lsblk -f /dev/loop0
NAME      FSTYPE  LABEL                     UUID                                 MOUNTPOINT
loop0     iso9660 Lubuntu 18.04.5 LTS amd64 2020-08-06-23-08-05-00               
├─loop0p1 iso9660 Lubuntu 18.04.5 LTS amd64 2020-08-06-23-08-05-00               
└─loop0p2 vfat                              EC34-71CF                            

$ lsblk -f /dev/mapper/loop0p1
NAME    FSTYPE  LABEL                     UUID                                 MOUNTPOINT
loop0p1 iso9660 Lubuntu 18.04.5 LTS amd64 2020-08-06-23-08-05-00               

When you know what you have, you will also know how to clone the content. But it is also possible to mount a mapped source partition and the target partition and extract files (copy them with rsync or some other program).

Ajay avatar
by flag
image have two partitions
sudodus avatar
jp flag
If you have an image of a partition it is straightforward to clone like you suggest in Edit 1 of your question (but of course to the correct target partition. If there are several partitions in the image, you can clone a partition for example `/dev/mapper/loop0p1` to a suitable target partition. But you can also mount the source and target partitions and copy files, for example with `rsync`. Please notice that the target partition must be at least as big as the source partition.
Ajay avatar
by flag
Well thanks It cleared my concept about mounting too. i was struggling for last few hours.
sudodus avatar
jp flag
You are welcome and good luck finding the correct source and target for your cloning operation :-) Please remember to douple-check that the command line is correct before pressing the Enter key.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.