LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-26-2020, 09:40 PM   #1
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Rep: Reputation: Disabled
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.
 
Old 11-26-2020, 09:46 PM   #2
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,454
Blog Entries: 7

Rep: Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559Reputation: 2559
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
 
Old 11-26-2020, 10:35 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by blooperx3 View Post
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.
 
Old 11-27-2020, 12:58 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
Old 11-27-2020, 03:05 AM   #5
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
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

Last edited by blooperx3; 11-27-2020 at 03:33 AM.
 
Old 11-27-2020, 04:03 AM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by blooperx3 View Post
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.

Last edited by berndbausch; 11-27-2020 at 04:06 AM. Reason: typos
 
Old 11-27-2020, 07:50 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,717

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
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

Last edited by michaelk; 11-27-2020 at 07:54 AM.
 
Old 11-28-2020, 06:14 PM   #9
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
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.

Last edited by blooperx3; 11-28-2020 at 06:27 PM. Reason: correction: not filename, but directory name
 
Old 11-28-2020, 06:18 PM   #10
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
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.
 
Old 11-28-2020, 06:20 PM   #11
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rkelsen View Post
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
 
Old 11-28-2020, 06:26 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,717

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
/dev/sdx is the entire disk plus the partition table. Writing the file back to a physical disk would erase everything on that disk.
 
1 members found this post helpful.
Old 11-28-2020, 06:27 PM   #13
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
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)
 
Old 11-28-2020, 06:28 PM   #14
blooperx3
Member
 
Registered: Nov 2020
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
/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.
 
Old 11-28-2020, 06:31 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,717

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
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.

Last edited by michaelk; 11-28-2020 at 06:46 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I have a 1TB Seagate Hard Drive that is failing I can read small files but can't drag big files off doramzy Linux - Hardware 43 05-23-2016 08:43 AM
Samba - Problem viewing directories on Buffalo 1TB disc zdun Debian 2 08-22-2009 03:47 AM
Samba - Problem viewing directories on Buffalo 1TB disc zdun Linux - Networking 1 08-21-2009 03:41 AM
Can I Convert DVD image to CD image? bnchakraborty Linux - Software 1 07-22-2005 01:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration