LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 07-09-2014, 11:34 PM   #1
manscher
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Rep: Reputation: Disabled
dd to smaller partition gives corrupt superblock or partition table


An external hard disk recently started failing, so I bought a new one and partitioned it at approximately the same sizes, although a few turned out slightly smaller. The old partitions were nowhere near full.

I copied the old partitions one by one using dd:

Quote:
dd if=/dev/sda2 of=/dev/sdb2 bs=4096 conv=noerror,notrunc,sync
(and same for sda3 etc.). For the partitions that were slightly smaller (including sbd2) I got a "no space left on device" error at the end. After this, running fsck on sdb2 gives an error:

Quote:
The filesystem size (according to the superblock) is 1310720 blocks
The physical size of the device is 1308929 blocks
Either the superblock or the partition table is likely to be corrupt!
I assume this is because dd writes data including the old superblocks to the new partition, which means that I probably want to regenerate the superblocks. When searching for solutions to the error above, all seem to use resize2fs to resize the partitions. Will this recreate the superblocks etc. but keep the partition table intact?

Another option seems to be to start over and simply copy the whole disk with dd if=/dev/sda of=/dev/sdb; will this work even if the new disk is a different brand (but approx. same size) and has different sector sizes etc.?

Last edited by manscher; 07-09-2014 at 11:34 PM. Reason: typo
 
Old 07-10-2014, 12:08 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"dd" writes every block that it can read, even if it is in error. There are much better alternatives - ddrescue for example.
What you have done is truncate the filesystem - check the arithmetic in the messages you cited above. This is never going to work - ensure the target partition is at least as big as the source, or use a file-aware tool that will only copy the used portiions of the filesystem.
Copying the whole disk may mess with the architecture of the target disk - less of an issue these days, but I don't ever do it; partition by partition gives much better control over the whole affair.
 
1 members found this post helpful.
Old 07-10-2014, 01:29 AM   #3
manscher
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for your reply. I understand that I should stick to copying partition-by-partition.

The problem with using a file-aware tool (I assume you mean something like cp -R) is that because of the disk problems, I have trouble mounting the old file systems. So I have two questions:
  • If I'm willing to accept that the partition is truncated (and thus lose small amounts of data), how do I clean up the file system structure?
  • The alternative to accepting a truncated file system is to re-partition the new disk to exactly match the old one and copy the data again using dd or ddrescue, right? I'm not sure if I'm able to create exactly the same size for the last partition (i.e. since the sector structure is different for the new disk, it might be a tiny bit smaller), so if that happens, how do I clean up the file system structure? for this last partition, I can probably repair any errors this might create.
 
Old 07-10-2014, 02:31 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Truncating the file system invalidates it - you (effectively) lose the lot, not just a bit. After that is forensic recovery - slooooow and indefinite.
Seems you bought a second disk of the same (FSVO "same") size. Newer tools align new partitions differently, especially on the newer devices with bigger physical blocks. This might explain why you can't allocate all the partitions the "same" (FSVO ...) size. If it was me, I would work on just the partition that could give back the most space. Get it across to the new disk using a larger size, fix the filesystem, shrink it to release space, then shrink the partition to match (gparted is good for this), then work on the other partitions on the now larger than strictly required free space.

Recovery is always more work simply restoring from a current backup.
 
1 members found this post helpful.
Old 07-10-2014, 02:50 AM   #5
manscher
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks again. I'll start over with partitions that are large enough. So, to summarize my understanding of your suggestion:
  1. Re-partition the new disk with partitions that are same or larger size (number of blocks), if possible. If not, do not create last partition yet.
  2. Copy data to partitions that are sufficiently large, using dd or ddrescue
  3. If necessary, shrink recovered partitions to free space, create last partition and copy data
  4. Resize partitions to desired size

Last edited by manscher; 07-10-2014 at 03:28 AM. Reason: Clarification
 
Old 07-10-2014, 04:18 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Looks like a plan.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Corrupt superblock or partition table jdtiede Linux - Hardware 2 12-29-2008 03:31 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
superblock or partition table corrupt? Kristian2 Linux - Newbie 1 05-11-2004 09:34 AM
corrupt partition table Verso Linux - Hardware 5 12-16-2003 10:23 AM
Corrupt partition table mback Linux - Software 3 04-27-2002 11:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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