0

I tried to copy all the files from my USB drive using the "dd" command. Output shows success, equal in and out# of records, and less total GB available on HDD where I saved them to, but files are nowhere to be found. Ubuntu os.

dd if=/dev/sdx bs=16M of=/home/directory/foldername

where sdx = sdb = files to copy from USB; of =destination on hdd. directory = comp name; I created folder to put image in.

I mounted usb as "read-only".

I found my files, the image. How can I tell if it is corrupt?

  • 1
    cp (or rsync) should be used unless you need a dd specific feature, what exact command did you use? – user1133275 Aug 11 '19 at 15:36
  • 1
    There is not enough info in the question. Tell us the dd command that you used. And/or do you know the names of the files? – ctrl-alt-delor Aug 11 '19 at 15:44
  • @KM no. /home/comp-name/foldername, but folder is empty. – hddfsck777 Aug 11 '19 at 15:59
  • I mounted USB as "read-only". I think that's why not finding, though output said success – hddfsck777 Aug 11 '19 at 16:12
  • @km Its correct what I wrote above. It was on the desktop. When I right-clicked inside desktop directory, it showed "/home/comp-name/Desktop". I replaced "desktop" with a folder name for the folder I put there. If I change foldername to "Desktop", you are saying that won't work b/c Desktop is a directory? Maybe I need to write "/home/comp-name/Desktop/foldername...? I could also just use "of=/sda"? – hddfsck777 Aug 11 '19 at 16:31
  • ...correction: when I clicked on the destination "folder" inside desktop directory, it said "/home/comp/Desktop". – hddfsck777 Aug 11 '19 at 16:39
  • 1
    If you use of=/dev/sda (as mentioned in a previous comment), you would overwrite your machine's filesystem with that of the USB drive. Don't do that. It would lead to not being able to boot, and to loss of data. You seem to not know the difference between a device file and a file on a device. – Kusalananda Aug 11 '19 at 16:49
  • @km That is a folder I created before using dd. She'll says: "rw,r,r" "1 root root 8019509248 Aug 11 10:49 /home/comp-name/foldername" – hddfsck777 Aug 11 '19 at 17:01
  • @km when I run "ls -l" it seems to show it as file. It shows other files I can't find too. – hddfsck777 Aug 11 '19 at 17:22
  • @ka The file only shows in shell, apparently under downloads. But it is not in downloads, just like the other missing files. – hddfsck777 Aug 11 '19 at 17:36
  • @ka I found it as a hidden file in nano. I had "hidden files" checked in the directories, but it didn't show there. Nano says it's reading the file, but no output yet. – hddfsck777 Aug 11 '19 at 17:48
  • I found the file as a hidden file. There is no .iso or .img anywhere in the directories. I just want to move it off hdd to a new flash drive. – hddfsck777 Aug 11 '19 at 18:08
  • I re-did it, this time adding the desktop directory before adding a filename. "dd if=/dev/sdb bs=16M of=/home/whoami/Desktop/newfilename". Now I have an 8 GB encrypted file on the desktop. – hddfsck777 Aug 11 '19 at 18:35
  • It's not encrypted; it's an image file of the USB stick. If you mounted the filesystem and then copied the device you could easily have a file containing corrupted data. If you don't understand what Kusalananda and I are telling you then please ask for an explanation. – Chris Davies Aug 11 '19 at 20:37
  • @roaima Thanks. Why might it have corrupt data? Since we are on the topic ..with the "image", I get the feeling I can not access those files the same way I would if I had copied and pasted, yes? I imagine I would have to do something with the image first . – hddfsck777 Aug 12 '19 at 10:02
  • @roaima Are you saying b/c I used "sdb" instead of "sdb1", there is a greater risk for corrupt data? Either way, how can I tell if the new image is corrupted? Thx. – hddfsck777 Aug 12 '19 at 10:13
  • 1
    You are copying a USB image, not the files on the USB. Do you understand the difference? – Chris Davies Aug 12 '19 at 15:11
  • 1
    You've got the filesystem mounted and you're copying the live filesystem from the raw device. This is a really bad idea because the filesystem as written on the USB itself can be changed while you're still copying it, meaning you end up with an inconsistent view of the filesystem, which can lead to corruption in the copied image. Simple answer: stop copying the USB image and instead copy the files on the USB. – Chris Davies Aug 12 '19 at 15:12
  • The question is now unclear. It asks "How can I find..." in the title, then says "I found them". Then it goes on to ask a new question. I'm closing this question as unclear. – Kusalananda Aug 12 '19 at 20:37
  • @roaima Yes, I know the difference; I want the usb image in case I need to put the image back on the usb should the usb get corrupted when trying to recover deleted and/or stolen files. So how would you recommend copying the image? Thanks. – hddfsck777 Aug 13 '19 at 08:48

2 Answers2

3

You have copied an image of your USB stick. Instead, just copy the files:

cp -a /media/... ~/foldername  # Replace "..." with the rest of the path to the mounted USB stick

If you're not sure where your system has mounted the USB stick you can find out with either of these commands

df -h                          # List all the mounted filesystems; look for the one you want

mount | awk '/sdx/ {print $4}' # List of mounted filesystems, match "sdx", print mountpoint

I would strongly recommend that until become more familiar with UNIX/Linux systems you forget you have ever heard of the dd command. Really. (Why? Because there are very few situations where it's actually needed. Often for a raw copy cat is actually faster - and certainly no slower. And here, cp is the correct command to use.)

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
-2

Must use correct path to get the image accessible after it is copied over. /home/John/Desktop/anyfilename worked. However, file seems to be encrypted (101010). If I need to transfer the image back to flash drive, should the original flash drive image get damaged, don't know if the encryption will be an issue. Thanks to all who contributed.

  • 2
    I have no clue what you are talking about. It's not an encrypted file. It's an image of your USB stick. – Kusalananda Aug 11 '19 at 20:10
  • @kusa well, when it copied over to the hdd, the file was locked, and had 1's and 0's on 'face' of the file as it sat in desktop folder (I did not try to open the file), I thought that stood for encryption. – hddfsck777 Aug 12 '19 at 10:46
  • I'm assuming that icon just meant "binary file", which would be correct. I don't know what you mean by "locked". If you had wanted to copy the files from the USB stick, you would have mounted it and copied them with cp as ordinary files. – Kusalananda Aug 12 '19 at 10:58
  • @kusa Well, I need to use a data recovery tool and was told to copy by blocks. Will a binary file open with root password? – hddfsck777 Aug 12 '19 at 11:12
  • Your question never mentions anything about data recovery. It say "I want to copy all files". The image file that you created with dd is not locked or encrypted and I don't know where you got that idea from. I still don't know what it is you're actually wanting to do. – Kusalananda Aug 12 '19 at 11:22
  • @kusa I want an identical backup to the flash drive files, bit by bit. If I use a recovery tool on the original flash drive, and it gets damaged, I want a replica backup I can put back on it and use a different recovery tool and try again. Originally, when I copied the files, they were nowhere to be found ony comp, so that's where the original question originates from. After copying them again with a different path name, I got the backup to my desktop. Thx. – hddfsck777 Aug 12 '19 at 11:36
  • @kusa At this point, I need to know if the backup I just created is corrupt or not. Roaimo seems to think it might. How can I tell? Thx. – hddfsck777 Aug 12 '19 at 11:44
  • If not for the sake of politeness, then for the sake of successfully pinging me, use my full name in comments. Your question is not telling us what you'd want to do. I suggest that you edit it to describe what it is you want to achieve. – Kusalananda Aug 12 '19 at 11:50
  • @kusalananda Sure. I thought admin did not want changes to questions after comments posted, only additional points there. I'll edit it. Thx. – hddfsck777 Aug 12 '19 at 12:08