Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Ubuntu 10.04 LTS server which had its partition table blown away. We realized it happened before a shutdown and were able to backup all files completely. With the system still up, we hope to be able to recover it.

Here are my questions:

  • Is there an easy way to flush the in-memory configuration back to the partition table? Can we run TestDisk while booted or should we reboot and run TestDisk?

  • If we run TestDisk and successfully recover the the partition table of /dev/sda (sda1 is LVM, sda5 is /boot (ext2)), will we be able to recover the LVM configuration successfully? Is there any manual work that needs to be done to get /dev/mapper/hostname-root (ext3) and /dev/mapper/hostname-swap_1 (swap) "mapped" again or does LVM take care of that?

Also, if you have any other tips, we would be eager to hear. And please forgive my ignorance of LVM.

What we did wrong

This is the offending command:

echo -e "o\nn\np\n1\n\n+100M\na\n1\nw\n" | fdisk $hdd

It was part of a script to put an image on a fresh HDD but it was accidentally run on the server.

o: Create a new DOS style partition (enter)
n: Answer No (enter)
p: Primary (enter)
1: Partition 1 (enter)
(enter)
+100M: 100 MB partition size (enter)
a: (not sure) (enter)
1: (not sure) (enter)
w: Write configuration (enter)

What we know

We have collected tons of information and (at present) the system is still up, so we can run other commands if needed.

All appearances indicate that /dev/sda was set up like so:

/dev/sda1 Linux LVM
    /dev/mapper/hostname-root   /  ext3
    /dev/mapper/hostname-swap_1   none  swap
/dev/sda2   ?   ?
/dev/sda5   /boot   ext2
  • There are two "physical disks", both are RAID-1 mirrors on an INTEL SRCSASPH16I RAID controller. I've omitted /dev/sdb everywhere as it's irrelevant (but entirely backed up anyway).

  • There is no data corruption (yet), all we did was overwrite the partition table. MBR and data areas should still be intact.

Output of TestDisk

If we narrow testdisk to look at /dev/sda, we see this.

# testdisk /dev/sda

Select a media (use Arrow keys, then press Enter):
Disk /dev/sda - 248 GB / 231 GiB - INTEL SRCSASPH16I

If we DO NOT narrow testdisk to /dev/sda, we see this.

# testdisk

Select a media (use Arrow keys, then press Enter):
Disk /dev/sda - 248 GB / 231 GiB - INTEL SRCSASPH16I
Disk /dev/mapper/hostname-root - 242 GB / 225 GiB - INTEL SRCSASPH16I
Disk /dev/mapper/hostname-swap_1 - 6085 MB / 5804 MiB - INTEL SRCSASPH16I

/dev/sda

Selecting /dev/sda (partition table type is autodetected as "Intel"):

Disk /dev/sda - 248 GB / 231 GiB - CHS 30272 255 63
Current partition structure:
     Partition                  Start        End    Size in sectors

No EXT2, JFS, Reiser, cramfs or XFS marker
 1 * Linux                    0   1  1    13 254 63     224847
 1 * Linux                    0   1  1    13 254 63     224847

It prompts to run a quick search. When the quick search completes we have this:

Disk /dev/sda - 248 GB / 231 GiB - CHS 30272 255 63
     Partition               Start        End    Size in sectors
P Linux LVM                0   1  1 30240 254 63  485821602
L Linux                30241   1  1 30271 254 63     497952

Selecting the "Linux LVM" volume or the "Linux" volume, we see this:

Disk /dev/sda - 248 GB / 231 GiB - CHS 30272 255 63

     Partition                  Start        End    Size in sectors

 1 P Linux LVM                0   1  1 30240 254 63  485821602
 2 E extended LBA         30241   0  1 30271 254 63     498015
 5 L Linux                30241   1  1 30271 254 63     497952

/dev/mapper/hostname-root

Selecting /dev/mapper/hostname-root (partition table type is autodetected as "None"):

Disk /dev/mapper/hostname-root - 242 GB / 225 GiB - CHS 473849856 1 1
     Partition               Start        End    Size in sectors
P ext3                           0  473849855  473849856

/dev/mapper/hostname-swap_1

Selecting /dev/mapper/hostname-swap_1 (partition table type is autodetected as "None"):

Disk /dev/mapper/hostname-swap_1 - 6085 MB / 5804 MiB - CHS 11886592 1 1
     Partition               Start        End    Size in sectors
P Linux SWAP 2                   0   11886575   11886576

Output of other utilities

# cat /etc/fstab

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# / was on /dev/mapper/hostname-root during installation
UUID=9876bd0a-6d5e-4404-8fb0-f32e22f35df4 /               ext3    relatime,errors=remount-ro 0       1
# /boot was on /dev/sda5 during installation
UUID=3659342f-cb67-4ece-bda8-dd12ddcfab09 /boot           ext2    relatime        0       2
# swap was on /dev/mapper/hostname-swap_1 during installation
UUID=4caead54-85aa-4179-8061-5b9735833370 none            swap    sw              0       0

# fdisk -l /dev/sda This is innacurate, obviously, since we blew away our partition table.

Disk /dev/sda: 249.0 GB, 248999051264 bytes
255 heads, 63 sectors/track, 30272 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x4f2c4e4b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          14      112423+  83  Linux

# mount

/dev/mapper/hostname-root on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
/dev/sda5 on /boot type ext2 (rw,relatime)

# vgcfgbackup -f vgcfgbackup.20130607.cfg; cat vgcfgbackup.20130607.cfg

# Generated by LVM2 version 2.02.54(1) (2009-10-26): Fri Jun  7 16:32:20 2013

contents = "Text Format Volume Group"
version = 1

description = "vgcfgbackup -f vgcfgbackup.20130607.cfg"

creation_host = "hostname"      # Linux hostname 2.6.32-45-server #102-Ubuntu SMP Wed Jan 2 22:53:00 UTC 2013 x86_64
creation_time = 1370637140      # Fri Jun  7 16:32:20 2013

hostname {
        id = "VVYltu-kIJU-20mS-uJR0-gS7i-RKLT-TtfRjU"
        seqno = 3
        status = ["RESIZEABLE", "READ", "WRITE"]
        flags = []
        extent_size = 8192              # 4 Megabytes
        max_lv = 0
        max_pv = 0

        physical_volumes {

                pv0 {
                        id = "f7b1tb-Gdp0-JEbx-EVq8-Oz9G-NNsm-4YQYtd"
                        device = "/dev/sda1"    # Hint only

                        status = ["ALLOCATABLE"]
                        flags = []
                        dev_size = 485821602    # 231.658 Gigabytes
                        pe_start = 384
                        pe_count = 59304        # 231.656 Gigabytes
                }
        }

        logical_volumes {

                root {
                        id = "ciNQqj-3yFC-6axd-yNS2-e4xH-mzhv-ng94KE"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

                        segment1 {
                                start_extent = 0
                                extent_count = 57843    # 225.949 Gigabytes

                                type = "striped"
                                stripe_count = 1        # linear

                                stripes = [
                                        "pv0", 0
                                ]
                        }
                }

                swap_1 {
                        id = "IaP7PW-5mrG-NWp7-JSLb-XMRG-C59w-8DhB7K"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

                        segment1 {
                                start_extent = 0
                                extent_count = 1451     # 5.66797 Gigabytes

                                type = "striped"
                                stripe_count = 1        # linear

                                stripes = [
                                        "pv0", 57843
                                ]
                        }
                }
        }
}

# vgdisplay

--- Volume group ---
VG Name               hostname
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               231.66 GiB
PE Size               4.00 MiB
Total PE              59304
Alloc PE / Size       59294 / 231.62 GiB
Free  PE / Size       10 / 40.00 MiB
VG UUID               VVYltu-kIJU-20mS-uJR0-gS7i-RKLT-TtfRjU

# pvdisplay

--- Physical volume ---
PV Name               /dev/sda1
VG Name               hostname
PV Size               231.66 GiB / not usable 1.58 MiB
Allocatable           yes
PE Size               4.00 MiB
Total PE              59304
Free PE               10
Allocated PE          59294
PV UUID               f7b1tb-Gdp0-JEbx-EVq8-Oz9G-NNsm-4YQYtd

# lvdisplay

--- Logical volume ---
LV Name                /dev/hostname/root
VG Name                hostname
LV UUID                ciNQqj-3yFC-6axd-yNS2-e4xH-mzhv-ng94KE
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                225.95 GiB
Current LE             57843
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           251:0

--- Logical volume ---
LV Name                /dev/hostname/swap_1
VG Name                hostname
LV UUID                IaP7PW-5mrG-NWp7-JSLb-XMRG-C59w-8DhB7K
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                5.67 GiB
Current LE             1451
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           251:1

# dmsetup

Name:              hostname-root
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      251, 0
Number of targets: 1
UUID: LVM-VVYltukIJU20mSuJR0gS7iRKLTTtfRjUciNQqj3yFC6axdyNS2e4xHmzhvng94KE

Name:              hostname-swap_1
State:             ACTIVE
Read Ahead:        256
Tables present:    LIVE
Open count:        1
Event number:      0
Major, minor:      251, 1
Number of targets: 1
UUID: LVM-VVYltukIJU20mSuJR0gS7iRKLTTtfRjUIaP7PW5mrGNWp7JSLbXMRGC59w8DhB7K
share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.