view image files make with dd command

zapeador

Member
Joined
Jan 15, 2022
Messages
44
Reaction score
13
Credits
401
hello

Is there a way to see the content of an image made with the dd command? and to extract a part?

I made a backup copy of the sda disk and I don't want to restore it in its entirety, I only want to see if there is X file and if I can see that I can know if I can extract that file without restoring the entire image
 


captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,862
Reaction score
1,932
Credits
17,722
well when i was playing with Ventoy persistence it involved running a ventoy script, to produce a .img file of around one gig.

Now for different OS on the basis of booting live from a usb , they require different labelling of file system.

For instance to get live ubuntu from a usb working with persistence the label of the .img needs to be casper-rw ,whereas Arch needs it to be vtoycow

So i started to look at first producing an .img myself then trying to look inside- i wil show you some of the commands i ended up using

eg
Code:
  fallocate -l 1G persistence.img
//then to get access to that file first, find avaialble 
# losetup -f
//above finds available loop 

# losetup  /dev/loop0 persistence.img
 // mounts img 

  
 # fdisk -l 
 
 //show if /dev/loop0 exists 
 
  #  cfdisk /dev/loop0
  //use cfdisk to add partition and format 
  
  # umount /dev/loop0
//umount it 
//no above didn't work to detach use:

# losetup -d /dev/loop0


I think you can convert between iso and .img not to sure only really palyed with .img files

Also Slackware has fallocate and losetup installed as default , that was one of the great things about it , other OS you will probably need to install
 
Last edited:

forester

Active Member
Joined
Mar 5, 2022
Messages
319
Reaction score
176
Credits
2,317
Isomaster, if the dd of=*.iso; iisomaster is usually in a repo, at least for many distros.
No, I do not believe only part of the file may be extracted. Use GIMP to crop or whatever and save again, as one suggestion; another suggestion is to explore Clonezilla and its usage as a backup/restore utility.
 
N

NorthWest

Guest
zapeador wrote:
Is there a way to see the content of an image made with the dd command? and to extract a part?
I made a backup copy of the sda disk and I don't want to restore it in its entirety, I only want to see if there is X file and if I can see that I can know if I can extract that file without restoring the entire image
The answer to your question "Is there a way to see the content of an image made with the dd command?" is yes, but it depends.
If the image file is a .iso or a block file that can be treated as a device, then you can mount the image on a loop device and inspect it and copy out any files from it to elsewhere on your filesystem so that you have the bits you want.

There are several ways of doing this. Here is one example for an image file called imagefile.iso. You may need to be root to run these commands.
Check to see if you have a /dev/loop0 file in the /dev directory.
If you don't have a file /dev/loop0 on your system, you can create it:
Code:
losetup -f
Check that /dev/loop0 now exists.
Mount the image file on /mnt:
Code:
mount -t auto -o loop=/dev/loop0 imagefile.iso /mnt
Navigate to /mnt and list the files. If the mount was successful, the filesystem of the image will appear for you to inspect and copy at will. If mount was unsuccessful it will give an error message telling you why.
 
OP
Z

zapeador

Member
Joined
Jan 15, 2022
Messages
44
Reaction score
13
Credits
401
zapeador wrote:

The answer to your question "Is there a way to see the content of an image made with the dd command?" is yes, but it depends.
If the image file is a .iso or a block file that can be treated as a device, then you can mount the image on a loop device and inspect it and copy out any files from it to elsewhere on your filesystem so that you have the bits you want.

There are several ways of doing this. Here is one example for an image file called imagefile.iso. You may need to be root to run these commands.
Check to see if you have a /dev/loop0 file in the /dev directory.
If you don't have a file /dev/loop0 on your system, you can create it:
Code:
losetup -f
Check that /dev/loop0 now exists.
Mount the image file on /mnt:
Code:
mount -t auto -o loop=/dev/loop0 imagefile.iso /mnt
Navigate to /mnt and list the files. If the mount was successful, the filesystem of the image will appear for you to inspect and copy at will. If mount was unsuccessful it will give an error message telling you why.



Thanks a lot!

I managed it thanks to your help but I had to do some more steps (in systems almost never works without extra steps) and I'll comment here in case someone wants to do the same

The command you gave me " mount -t auto -o loop=/dev/loop0 imagefile.iso /mnt" as expected didn't work, it told me "wrong filesystem type" so I assumed that since it was an imagefile. a whole disk and not just a partition that could be a problem, I did a:

file bak-sda.img
bak-sda.img: DOS/MBR boot sector

I looked for some information and I saw that being a whole disk you have to specify where it starts so I did this other:

# fdisk -l bak-sda.img
Disk bak-sda.img: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: 1 * 512 sectors = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/best): 512 bytes / 512 bytes
Disc Label Type: Two
Disk Identifier: 0x3ff5ff2f

Device Start Start End Sectors Size Id Type
bak-sda.img1 * 2048 58720255 58718208 28G 83 Linux
bak-sda.img2 58722302 62912511 4190210 2G 5 Extended
bak-sda.img5 58722304 62912511 4190208 2G 82 Linux swap / Solaris

so since the partition was the linux one and it started in sector 2048 and each sector has 512 bytes execute the following and I mount it without problems

mount -o loop,offset=$((512*2048)) bak-sda.img /mnt/midisk

I hope this can help someone
 
N

NorthWest

Guest
Thanks zapeador. That's an elegant piece of work on your part and certainly helpful.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top