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.

computersavvy 11-28-2020 07:08 PM

If you can access the files in the image then attempting to do a restore with dd instead of copying them back would be a lot of wasted time and drive space as well as headaches. I wager you have considerably less space used by the files than the 1 TB in the image.

ondoho 11-29-2020 01:32 AM

Quote:

Originally Posted by blooperx3 (Post 6189771)
the source (fat) hdd says "fuse" filesystem.

This sentence does not make sense (to me).
I don't think you can work on fuse filesystems with dd.
Quote:

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.
In any case, your command copied the whole physical hard drive. Nothing to do with filesystems AT ALL.
You have an exact copy of the whole hard drive as a 1TB file.
Quote:

Originally Posted by blooperx3 (Post 6189774)
If I write it back to disk, what dd command would I use?

Code:

sudo dd if=/filepath/directory.name of=/dev/sdy
You can use any bs.

blooperx3 12-05-2020 05:18 PM

Quote:

Originally Posted by ondoho (Post 6189837)
This sentence does not make sense (to me).
I don't think you can work on fuse filesystems with dd.


In any case, your command copied the whole physical hard drive. Nothing to do with filesystems AT ALL.
You have an exact copy of the whole hard drive as a 1TB file.

Code:

sudo dd if=/filepath/directory.name of=/dev/sdy
You can use any bs.

Thanks for the command. If I want to write it to a specific 'empty' partition on the target hdd, would adding a number to "sdy" work?
Appreciate the help.

blooperx3 12-05-2020 05:19 PM

Quote:

Originally Posted by computersavvy (Post 6189788)
If you can access the files in the image then attempting to do a restore with dd instead of copying them back would be a lot of wasted time and drive space as well as headaches. I wager you have considerably less space used by the files than the 1 TB in the image.

No, almost a full 1TB.

blooperx3 12-05-2020 05:25 PM

Quote:

Originally Posted by michaelk (Post 6189779)
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.

How would i mount the 1TB (filesystem) image?

teckk 12-05-2020 05:52 PM

Quote:

How would i mount the 1TB (filesystem) image?
See:
Code:

man mount
The man pages are also online.
https://linux.die.net/man/8/mount

You can mount an .iso loopback

teckk 12-05-2020 05:59 PM

Also,

If you want to make a pdf/text from a man page for easier reading
Code:

man -t mount | ps2pdf - output.pdf
man -P cat mount > output.txt

You can also grep a man page
Code:

man mount | grep -- 'loop'
or
Code:

man mount | grep -A 10 'LOOP'

ondoho 12-06-2020 03:45 AM

Quote:

Originally Posted by blooperx3 (Post 6192143)
I want to write it to a specific 'empty' partition on the target hdd, would adding a number to "sdy" work?

Um.
Aren't we going in circles now?
Yes, the answer is yes, but it might not give the desired result.

Anyhow, I think I'm out.

rnturn 12-06-2020 11:04 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.

Wouldn't you mount the image file using the loopback option (mentioned earlier/above) and restore files from the image using regular file/directory tree commands (`rsync', for example)?
Code:

$ sudo mount <image-file> /mnt -o ro -o loop
$ ls /mnt/*

If this reveals the files you're looking for, you're all set to use `rsync', `cp', or whatever else tool you prefer. I doubt `dd' is the tool to be using for the restores.

I can only recall one instance where I've used `dd' in a backup/restore situation and that involved Oracle raw data partitions and magtape---not regular filesystems.

HTH...


All times are GMT -5. The time now is 06:06 AM.