LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-12-2008, 08:18 AM   #1
neocontrol
Member
 
Registered: Jul 2005
Posts: 273

Rep: Reputation: 31
dd command help needed here


Hi,

I'm trying to save usb drive that has a corrupted partition table. And here's my idea of how to get it fixed, but I'm not sure if what I want to do will work.

My plan is...

take a backup of the usb drive with this command.

dd if=/dev/sdb of=/tmp/dead_usb_file bs=512

And then I thought I would reformat / partition the usb drive - in windows....

And then put back the file I saved, skipping the first 512, since I believe that is what holds the mbr and partition layout.

dd if=/tmp/dead_usb_file of=/dev/sdb bs=512 skip=1..............

My issue comes from the last command, as looking at the dd documentation it looks like I can skip the first chunk out of the input file, but how do I also skip the first chunk of the usb device since it has a new mbr / partition.

I have also thought about just trying to repartition / rebuild a mbr but I haven't looked into that one enough yet.

Thanks for any insight.
 
Old 10-12-2008, 08:48 AM   #2
glalejos
LQ Newbie
 
Registered: Jan 2005
Distribution: Debian
Posts: 18

Rep: Reputation: 0
Hi,

I'm not sure whether the partition table occupies only the first 512 bytes of the device, but I think is a good guess. In this case I would try to backup up only the partition you want to recover (i.e. skip the first 512 bytes when dumping the contents of the USB drive to your hard drive) and then try to mount it using the loopback device.

If you succeed in doing this, all you have to do is format your USB drive properly, mount it and then copy the files from the mounted loopback device to the USB drive using cp (or whatever method you prefer).

Good luck!,

Guillermo
 
Old 10-12-2008, 09:45 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The partition probably starts on block 63. This is from a 2GB pendrive that I never reformatted.
Code:
sudo /sbin/fdisk -lu /dev/sdd

Disk /dev/sdd: 2020 MB, 2020539904 bytes
32 heads, 63 sectors/track, 1957 cylinders, total 3946367 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x44a84755

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1              63     3945311     1972624+   6  FAT16
Code:
dd --help
Usage: dd [OPERAND]...
  or:  dd OPTION
Copy a file, converting and formatting according to the operands.

  bs=BYTES        force ibs=BYTES and obs=BYTES
  cbs=BYTES       convert BYTES bytes at a time
  conv=CONVS      convert the file as per the comma separated symbol list
  count=BLOCKS    copy only BLOCKS input blocks
  ibs=BYTES       read BYTES bytes at a time
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list
  seek=BLOCKS     skip BLOCKS obs-sized blocks at start of output
  skip=BLOCKS     skip BLOCKS ibs-sized blocks at start of input
  status=noxfer   suppress transfer statistics
You use seek to change where the writing starts and skip to change where the reading starts. Working with a block size of 512 is a good idea.
If you have the room, then make a copy of the backup file. Use that file as the destination for restoring the mbr and see if you can mount it.

However, if the partition part of the image on the dead_usb_file file is OK, you could just try mounting it using losetup & mount. You don't need to mess with dd.
Code:
sudo /sbin/losetup -sf /temp/dead_usb_file.bu -o $((512*63))
mkdir /tmp/deadusb
sudo mount -t vfat /dev/loop0 /tmp/deadusb -o ro,loop
Use the loop device that losetup finds. I assumed loop0 in my example.

If you can mount the partition image part, then you can simply copy the files back to the reformatted pendrive.

Last edited by jschiwal; 10-12-2008 at 10:02 AM.
 
Old 10-12-2008, 10:18 AM   #4
neocontrol
Member
 
Registered: Jul 2005
Posts: 273

Original Poster
Rep: Reputation: 31
Thanks for the replies. Partition is toasted. That was the error I was getting when I was plugging in the usb drive. It is 2GB as well.

I'll try using seek to the same spot and fixing the mbr.

I'll let you know how it goes next.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed for find command ZAMO Linux - General 7 09-23-2008 04:15 AM
Help needed 1 command line. turalo Linux - Newbie 5 05-08-2007 02:27 AM
linux Command needed cherupop Linux - Newbie 4 07-05-2005 11:33 PM
command line help needed mykrob Linux - Software 5 10-08-2004 12:10 AM
Routing command needed carrellc Linux - Networking 6 05-28-2004 10:59 AM


All times are GMT -5. The time now is 02:20 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration