LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What dd command do i use to convert a 1TB image file back to files/directories? (https://www.linuxquestions.org/questions/linux-newbie-8/what-dd-command-do-i-use-to-convert-a-1tb-image-file-back-to-files-directories-4175685866/)

blooperx3 11-26-2020 09:40 PM

What dd command do i use to convert a 1TB image file back to files/directories?
 
I know it should be the opposite of the command i used to create it, but that was a long time ago and i do not know which command was used.

rkelsen 11-26-2020 09:46 PM

It depends upon exactly what you want to achieve.

You can use dd to write the image back to disk, but you'd have to be careful to not overwrite partition boundaries, etc.

If you want to extract data from the image, you can mount it via loopback and then copy files across. Eg:
Code:

# mount -o loop ./imagefile.img /mnt/loop

berndbausch 11-26-2020 10:35 PM

Quote:

Originally Posted by blooperx3 (Post 6189158)
I know it should be the opposite of the command i used to create it, but that was a long time ago and i do not know which command was used.

In this case, first find out what kind of image it is. If it is a filesystem image, follow rkelsen's suggestion.

You could use the file command to guess what kind of file it is. The filename may also provide a clue. Once you have an idea of the file's format, you will know which tools to use to open it.

ondoho 11-27-2020 12:58 AM

Shouldn't mount just recognize the type in most cases?
I.e.
Code:

# mount -v ./imagefile.img /mnt/loop
should be enough, and give some diagnostic output about what sort of image this is.

blooperx3 11-27-2020 03:05 AM

I used something like

Code:

sudo dd if=/directory/filename bs=8M of=filepath/newfilename

sudo dd if=/dev/sde bs=8M of=/media

I copied a whole hdd that was fat formatted, but I copied it in linux to an ext4 formatted hdd as a single image.

I want to get all of the thousands of file/directories back in a NON image format and save it to a new directory on my hdd which does not take up the whole hdd or, ideally, have to create a new partition. rather, use the existing partition and just make a new directory to transfer the files to.

My guess is:
Code:

sudo dd if=/media/filename bs=8M of=/dev/sdx#/new.directory.name
or
Code:

sudo dd if=/media/directory.name/filename bs=8M of=/dev/sdx#/new.directory.name

berndbausch 11-27-2020 04:03 AM

Quote:

Originally Posted by blooperx3 (Post 6189218)
I used something like

Code:

sudo dd if=/dev/sde bs=8M of=/media

Since /media is a directory, that doesn't work.
Quote:

I copied a whole hdd that was fat formatted, but I copied it in linux to an ext4 formatted hdd as a single image.
Then that image contains a FAT filesystem. Use the above mount commands to try accessing it. You can add the option -t vfat, but mount should be able to figure out the filesystem type automatically.

Quote:

Code:

sudo dd if=/media/filename bs=8M of=/dev/sdx#/new.directory.name

If /dev/sdx# is a devicefile, this doesn't work. If it is a directory, you will just copy the image to another file under /dev. This will fill up the /dev filesystem almost immediately. In other words, don't do this.

If this is indeed a filesystem image, you don't need to copy it to a partition. Just mount it as suggested above.

michaelk 11-27-2020 07:50 AM

Quote:

sudo dd if=/dev/sde bs=8M of=/media
if you copied the entire drive to an image file the only way to restore via the dd command would be to another physical hard drive of the same size. By the way the file size of the entire drive would be 1 TB. As suggested you can mount a partition from the image file and then copy the desired files to an existing directory assuming you have enough free space.

Before you can mount an existing partition from the image file you need to know the byte offset of a partition from the beginning of the drive since you can not mount an entire drive image. The kpartx utility does all that for you and automatically creates the loop devices.
Code:

kpartx -a -v myfiles.img
mount /dev/mapper/loop0p1 /mnt/myfiles

To unmount and release loop devices.
umount /mnt/myfiles
kpartx -d -v myfiles.img


teckk 11-27-2020 08:23 AM

My 2 cents

man losetup
man mount
man dd

https://www.linuxquestions.org/quest...ommand-362506/
https://www.computerhope.com/unix/losetup.htm
https://www.thegeekdiary.com/how-to-...opback-images/
https://www.tecmint.com/extract-file...o-files-linux/

blooperx3 11-28-2020 06:14 PM

Quote:

Originally Posted by berndbausch (Post 6189163)
In this case, first find out what kind of image it is. If it is a filesystem image, follow rkelsen's suggestion.

You could use the file command to guess what kind of file it is. The filename may also provide a clue. Once you have an idea of the file's format, you will know which tools to use to open it.

the source (fat) hdd says "fuse" filesystem. i copied this hdd using following command: for sure
Code:

sudo dd if=/dev/sdx bs=8M of=/filepath/directory.name
The hdd was 1TB and the image created was 1TB.

blooperx3 11-28-2020 06:18 PM

Quote:

Originally Posted by berndbausch (Post 6189226)
Since /media is a directory, that doesn't work.

Then that image contains a FAT filesystem. Use the above mount commands to try accessing it.

I have full access to it - both the fat hdd and the image file created.

blooperx3 11-28-2020 06:20 PM

Quote:

Originally Posted by rkelsen (Post 6189160)
It depends upon exactly what you want to achieve.

You can use dd to write the image back to disk, but you'd have to be careful to not overwrite partition boundaries, etc.

If I write it back to disk, what dd command would I use? I have to check the reccs already given, but for the moment, i'll assume i'm not sure which one. thx

michaelk 11-28-2020 06:26 PM

/dev/sdx is the entire disk plus the partition table. Writing the file back to a physical disk would erase everything on that disk.

blooperx3 11-28-2020 06:27 PM

Quote:

Originally Posted by berndbausch (Post 6189226)
Since /media is a directory, that doesn't work.

Then that image contains a FAT filesystem. Use the above mount commands to try accessing it. You can add the option -t vfat, but mount should be able to figure out the filesystem type automatically.


If /dev/sdx# is a devicefile, this doesn't work. If it is a directory, you will just copy the image to another file under /dev. This will fill up the /dev filesystem almost immediately. In other words, don't do this.

If this is indeed a filesystem image, you don't need to copy it to a partition. Just mount it as suggested above.

correction: it was probably "/media/directory.name" and then it put the image in there with its former filename (name from source hdd)

blooperx3 11-28-2020 06:28 PM

Quote:

Originally Posted by michaelk (Post 6189775)
/dev/sdx is the entire disk plus the partition table. Writing the file back to a physical disk would erase everything on that disk.

Yes, using the reverse command would only work if i were putting onto a blank 1TB HDD.

michaelk 11-28-2020 06:31 PM

Missed your last post.

You can't use the dd command to restore the files and if you do not want to over write the drive then as suggested mount the filesystem image file and copy the files.


All times are GMT -5. The time now is 08:53 PM.