1

Is it possible to use img file of my entire disk to only recover some of the partitions?

I have a dual-boot system with Ubuntu and Windows. Each system has its partition on the disk and I have one more partition for shared storage. I made an img file of my entire disk using the application Disks and now I only want to restore the Ubuntu and shared storage partition with no changes to Windows partition or any Boot sector.

Is there any application (or commands) that can help me do that?

  • I do not know anything about an application called "Disks". Is it a raw image file? You should be able to setup a loop-device via udisksctl loop-setup -f imagefile. The partitions should become visible as /dev/loopXpY. – Hermann Jul 25 '22 at 23:39
  • @Hermann It is .img file. The application is in GNOME, Wikipedia says it's a graphical front for udisks. I am not sure what can I do after I mount partitions in loop devices. Maybe I wasn't clear enough but I want to restore some partitions from my disk so they look exactly like when I made the image. – Martin Vít Vavřík Jul 25 '22 at 23:52
  • https://askubuntu.com/questions/986684/how-would-i-extract-a-img-file – gapsf Jul 26 '22 at 00:37
  • @MartinVítVavřík After you setup the loop device, you can easily access the partitions while they are still stored in the image file. What you do with the partitions (mount filesystem, view contents, copy somewhere else) is up to you. – Hermann Jul 26 '22 at 22:12

1 Answers1

0

Searching reveals 'Disks' is a 'GNOME Disk Utility'. 'img' file created by it is just a block-level copy of partition or whole disk (whatever you choose when backup), created with dd utility.

You need to download and burn Ubuntu live-cd/dvd/usb, boot your computer with it and restore partition from .img file with 'GNOME Disk Utility'.

If 'GNOME Disk Utility' can't restore selected partition from whole disk image (it's not well documented) then you may use dd as your last resort.

To use restore with dd boot from live-cd, open shell and execute

losetup -P -f --show filename_of_your_img_file

It creates loop- aka 'virtual' device partitions, one /dev/loopXpY per partition (/dev/loop0p1, /dev/loop0p2...), from your 'img' file where X is disk number, Y - partition number.

You should identify visually what of /dev/loopXpY is your Ubuntu backup partition with

lsblk

and

file /dev/loopXpY

Or yo may mount those loop partitions one by one

mount /mnt /dev/loopXpY

and check filesystem's content with ls o midnight commander.

After you figured out which partition is the your ubuntu backup you may copy partition from backup .img file like

dd if=/dev/loopXpY of=/dev/sdZN

where is /dev/loopXpY is backuped Ubuntu partition and /dev/sdZN is yor Ubuntu partition on hard drive.

Check https://askubuntu.com/questions/1356134/img-file-restore-to-disk-partition

https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device

https://askubuntu.com/questions/768876/what-is-the-format-of-img-files-created-by-gnome-disk-utility

http://comfilewiki.co.kr/en/doku.php?id=cupc:backup_restore:index

gapsf
  • 606
  • Unless I am missing something, this doesn't answer my question. All these tell me is how I can use my image of the whole disk (one file) to restore the entire disk. I only want to restore some partitions while leaving others untouched. – Martin Vít Vavřík Jul 26 '22 at 01:27
  • If gnome disks dont have option to restore partitotion from whole disk image you should use dd utility. https://superuser.com/questions/117136/how-can-i-mount-a-partition-from-dd-created-image-of-a-block-device-e-g-hdd-u – gapsf Jul 26 '22 at 01:37
  • Any way you need to boot from livecd and use losetup and dd like here https://unix.stackexchange.com/questions/9099/how-to-read-one-filesystem-from-a-whole-disk-image-file Exact list of your actions depends on yours skills – gapsf Jul 26 '22 at 01:44