Linux System Repair Best Practices Topic is solved

Using TestDisk to repair the filesystem
Locked
Message
Author
pgreenwood
Posts: 3
Joined: 08 Nov 2016, 17:03

Linux System Repair Best Practices

#1 Post by pgreenwood » 08 Nov 2016, 18:11

First of all, thank you for this awesome utility - TestDisk. I will make a contribution. I've read TestDisk step-by-step and I'm very grateful for the documentation provided and the support of this forum. Here's my story.

I planned to use a mythbuntu live disk to install mythbuntu onto a HDD using a DVD in my laptop's (Dell Vostro 1520) DVD drive via a USB dock attached to my laptop. Before I knew what happened I apparently corrupted the laptop's GRUB and/or boot sector. The OS on my laptop is AVLinux, an audo-optimized Debian system. I think it is the "6" version, a 32-bit system.

Before working with TestDisk I dd'd the problem ("Source") disk (340GB) to a USB-connected ("Rescue") disk (2TB). Should I first try to get the Rescue disk to boot rather than the Source disk? How do I reinstall/repair GRUB on a USB-connected HDD? I suppose launch the LiveCD from the laptop's DVD drive, but then how do I make sure the attempted repair is done to the USB-attached drive and not to the laptop's onboard drive? I see this but it seems like my dd image might somehow "get in the way" of the replacement GRUB installation. Maybe not. Probably just overthinking the problem.

I think there were two partitions installed -- a swap and an ext4. I believe I can see both and can browse the files in the ext4. I suspect the partitions are Primary (swap) and Extended (ext4). Don't know that it matters, as I think TestDisk will "just" figure that out.

TestDisk reports the first partition is "bad" but that, I expect, is because GRUB is gone. Am I correct that its ok to write a new partition table with this first partition labeled "bad"? Should I first try to mark it "P"?

Some of the directories and files in ext4 I browse are red. I understand that means they're deleted. Can/should I do anything special to them before writing a new partition table?

I've tried to copy files to another drive. Some of the files (/boot directory) copy fine, but when I try to copy my /home directory a few files (304) copy and the rest all "fail". I now see that maybe I should "H"ide deleted files first before attempting to copy. I suppose only the copy utility within TestDisk itself (as opposed to, for example, rsync) has any chance of success in this context. Any other suggestions about what I may be doing wrong on this score would be appreciated.

I thought I had a testdisk.log to share but apparently did not get it copied. I'll try to grab it tonight and attach to this post FWIW.

Sponsored links

User avatar
cgrenier
Site Admin
Posts: 3623
Joined: 18 Feb 2012, 15:08
Location: Le Perreux Sur Marne, France
Contact:

Re: Linux System Repair Best Practices

#2 Post by cgrenier » 08 Nov 2016, 19:04

Try the following
- boot from a Linux LiveUSB/LiveDVD
- lsblk
- mount the original "/" in /mnt (ie mount /dev/sdb1 /mnt)
- mount the original "/boot" in /mnt/boot

Code: Select all

mount -t proc none /mnt/proc
mount -t sysfs sysfs /mnt/sys
mount --bind /dev/ /mnt/dev
chroot /mnt /bin/bash
cp /proc/mounts /etc/mtab
grub2-install /dev/sdb
exit

Code: Select all

umount /mnt/dev
umount /mnt/sys
umount /mnt/proc
umount /mnt/boot
umount /mnt
Reboot your computer

pgreenwood
Posts: 3
Joined: 08 Nov 2016, 17:03

Re: Linux System Repair Best Practices

#3 Post by pgreenwood » 12 Nov 2016, 20:41

my efforts to mount the local HDD fail

Code: Select all

root@tester:/home/tester# mount /dev/sda2 /mnt
mount: block device /dev/sda2 is write-protected, mounting read-only
mount: special device /dev/sda2 does not exist
root@tester:/home/tester# 
Attempts to mount /dev/sda1 show the same thing. I think the first partition is swap. Wouldn't that be /dev/sda1?

~# fdisk -l shows:

Code: Select all

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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: 0xea48fe5b

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sdb: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 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: 0xacdd9b22

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         122      976531+   c  W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
/dev/sdb2             123       77825   624149347+  83  Linux

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 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: 0xea48fe5b

   Device Boot      Start         End      Blocks   Id  System
root@tester:/home/tester# 
Do I need to first write (with testdisk) a partition table to /dev/hda before I can mount the partitions? Thank you!

pgreenwood
Posts: 3
Joined: 08 Nov 2016, 17:03

Re: Linux System Repair Best Practices  Topic is solved

#4 Post by pgreenwood » 12 Nov 2016, 23:12

I went back to testdisk. Working from my "rescue" disk I changed the file type of the first partition to 82 swap and marked the second partition "P" as per /etc/fdisk from my salvaged data. I wrote the table via testdisk. Now fdisk and lsblk recognized the primary Linux partition as sd*1 and I was able to run through the commands above and write a new GRUB. I couldn't get the disk to boot via the USB dock but did get it to boot on another computer. I then followed the process once more on /dev/sda1 (my laptop's HDD) and now I have a bootable system again. Thanks, again, Christophe and all others who lend real and moral support!

Locked

Who is online

Users browsing this forum: No registered users and 1 guest