Thursday, March 15, 2012

Retrieving the file-system from a lost Linux partition

When you lost a Linux partition on Storage device, there is a 80% chance that you can retrieve the file-system in it just by Re-creating the lost Partition. I have tried couple of times in the recent past and it worked successfully.
Here's the sequence of steps which I performed to retrieve the file-system "/us2001" on a lost partition from a SAN disk:

[root@server-tap04 mapper]# mount -t ext3 /dev/mapper/us2001np1 /us2001
mount: special device /dev/mapper/us2001np1 does not exist
[root@server-tap04 mapper]# fdisk -l /dev/mapper/us2001n
 Disk /dev/mapper/us2001n: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk /dev/mapper/us2001n doesn't contain a valid partition table
[root@server-tap04 mapper]#
[root@server-tap04 mapper]# multipath -l | grep -A5 us2001n
us2001n (350002ac009290783)
[size=10 GB][features="1 queue_if_no_path"][hwhandler="0"]
\_ round-robin 0 [active]
\_ 1:0:0:1 sdc 8:32 [active]
\_ 2:0:0:1 sdb 8:16 [active]
[root@server-tap04 mapper]# fdisk -l /dev/sdc
 Disk /dev/sdc: 10.7 GB, 10737418240 bytes
 64 heads, 32 sectors/track, 10240 cylinders
 Units = cylinders of 2048 * 512 = 1048576 bytes
 Disk /dev/sdc doesn't contain a valid partition table
[root@server-tap04 mapper]# fdisk /dev/sdc
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10240, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10240, default 10240):
Using default value 10240
Command (m for help): w
The partition table has been altered!
 Calling ioctl() to re-read partition table.
Syncing disks.
[root@server-tap04 mapper]# kpartx -a /dev/mapper/us2001n
[root@ server-tap04 mapper]# kpartx -l /dev/mapper/us2001n
us2001np1 : 0 20971488 /dev/mapper/us2001n 32
[root@rica-chi-tap04 mapper]# mount -t ext3 /dev/mapper/us2001np1 /us2001
[root@rica-chi-tap04 mapper]# df -h /us2001
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/us2001np1
                      9.9G  5.8G  4.1G  59% /us2001
[root@rica-chi-tap04 mapper]# cd /us2001                <-- Partition recreated and mounted  
[root@rica-chi-tap04 us2001]# ls -l                           <-- All the files are retrieved
total 28
-rw-r--r--  1 root     root     0 Jan 18  2011 2
-rw-r--r--  1 root     root     0 Jan 18  2011 abc
drwxr-xr-x  5 appltest dba   4096 Aug 10  2010 BI_Disco10g
drwx------  2 root     root 16384 Aug  6  2010 lost+found
drwxr-xr-x  4 appltest dba   4096 Mar 11  2011 product
[root@server-tap04 us2001]# touch xyz
[root@server-tap04 us2001]# 

No comments:

Post a Comment