LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-14-2011, 01:44 AM   #1
pedward
LQ Newbie
 
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
FAQ: Lost filesystem after re-partitioning


I thought others may find this info useful, because it was hard won and not documented anywhere else.

I had a 250G /home partition I created with Fedora 10 and wanted to shrink this partition to set aside space for an LVM volume group. I used resize2fs to shrink the filesystem to 150G, which worked fine.

Next I went into fdisk (fedora 15) and deleted the /home partition and recreated it as 150G instead of 250G. Up to this point it is all fairly simple, non-destructive changes.

I rebooted to a /home bad magic number in superblock. The first suspicion was that the new partition didn't start at the same place, block wise, as the old partition. I suspected this because the new default units in fdisk are sectors, in fedora 10 they were cylinders.

To determine the correct starting sector I used hexdump -v /dev/sda6 to find the magic number and offset in the filesystem. The magic number for EXT2/3/4 is EF53, in hexdump this appears on a line with xxxxxx30 at the beginning.

On a normal filesystem you will see EF53 on line 00000430. The EXT filesystem keeps backup superblocks at various block offsets of the filesystem. I got a starting list of possible offests by doing mkfs.ext3 -n /dev/sda6 and noted the block offsets for the backup superblocks.

The default block size for the EXT filesystem is 4096 bytes.

Next I ran hexdump -v /dev/sda6 | grep EF53 and listed all of the offsets where the magic number appeared. I had several hundred superblocks near the beginning of the FS, likely due to the resize, then I had superblocks spread out, 179d9030, 279d9030, 379d9030. The pattern was pretty obviously repeating, so I looked back at 079d9030 and found a superblock. This pattern offset is 256MB apart, which is 65536 blocks apart. The mkfs command said 32768 would have been the first backup superblock, but that isn't true!

So, knowing that the superblocks are spaced 65536 blocks apart and the first backup superblock is at location 79d9000, I know that the partition is actually pointing *too far* into the filesystem.

If you do 1000000 - 79d9000 you get 8627000, which is 140668928 decimal. This is 34343 blocks off.

The fdisk in fedora 15 spaces logical partitions 2048 sectors apart by default. To calculate the new partition start, I did an fdisk -l to get the current start, then subtracted (140668928 / 512) = 274744 sectors from the starting offset.

fdisk would not permit me to enter the correct start sector, which was 64 sectors greater than the ending sector of the previous partition. You can get around this by going into expert mode, then choosing 'b' which moves the start of a partition to a specific sector. I entered the correct starting sector in this and rebooted. Success!

To recap:
  • Use hexdump to find the repeating interval of the EF53 magic number in the EXT filesystem.
  • Once the interval is determined, calculate the difference from zero by subtracting the lowest offset backup superblock from the interval eg: 1000000hex - 79d9000hex
  • Divide the difference in bytes by 512 to find the sector difference
  • Use fdisk -l to list the current partition starting sector and add or subtract the difference to get the correct starting value
  • Use expert mode command 'b' of fdisk to set the correct partition starting sector
  • Reboot into single user mode and run fsck on the filesystem
 
Old 11-14-2011, 05:47 AM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,652
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283
Quote:
Hi, Welcome to LQ!

LQ has a fantastic search function that may save you time waiting for an answer to a popular question.

With over 4 million posts to search it's possible the answer has been given.

That's really beautiful,
thank you for your efforts.

regards Glenn
 
  


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
Filesystem/partitioning reccomendations? jmite Linux - Newbie 2 12-14-2008 04:28 AM
By cancelling a GParted partitioning operation, I've lost my OS Mark_in_Hollywood Linux - Newbie 4 04-16-2008 06:08 PM
Filesystem/Partitioning for dual boot debeus Linux - General 2 05-25-2007 09:23 PM
lost space to partitioning? chipmonk010 Linux - Hardware 1 09-04-2005 08:38 PM
Partitioning without lost Zig Linux - Software 6 06-30-2003 06:43 AM

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

All times are GMT -5. The time now is 09:29 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