3

I was trying to restore the grub after I reinstalled windows, so I mounted the partition where ubuntu was installed but I got:

$ sudo mount /dev/sda3 /mnt
mount: you must specify the filesystem type

So I did

$ sudo mount -t ext4 /dev/sda3 /mnt 
mount: wrong fs type, bad option, bad superblock on /dev/sda3,
   missing codepage or helper program, or other error
   In some cases useful info is found in syslog - try

Then I tried the solution for bad superblocks:

$ sudo e2fsck -f /dev/sda3
e2fsck 1.42.9 (4-Feb-2014)
e2fsck: Attempt to read block from filesystem resulted in short read while trying 
to open /dev/sda3
Could this be a zero-length partition?

$ sudo dumpe2fs /dev/sda3|grep -i superblock
dumpe2fs 1.42.9 (4-Feb-2014)
dumpe2fs: Attempt to read block from filesystem resulted in short read while 
trying to open /dev/sda3
Couldn't find valid filesystem superblock.

$ sudo mke2fs -n /dev/sda3
mke2fs 1.42.9 (4-Feb-2014)
mke2fs: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).

Edit2: And as Android Dev suggested (same using 8193)

$ sudo e2fsck -f -b 32768 -y /dev/sda3
e2fsck 1.42.9 (4-Feb-2014)
e2fsck: Invalid argument while trying to open /dev/sda3

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

So what is going on here?? My parted -l looks like this:

$ sudo parted -l
Model: ATA SAMSUNG HM321HI (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size    Type      File system     Flags
1      1049kB  106MB  105MB   primary   ntfs            boot
2      106MB   231GB  231GB   primary   ntfs
3      231GB   320GB  89.4GB  extended
5      256GB   258GB  1991MB  logical   linux-swap(v1)
6      258GB   320GB  62.4GB  logical   ext4

I noted (thanks to oldfred) that partition sda4 (where ubuntu was installed) is missing! between 231GB and 256GB, sda6 is my /home. I used to have 2 partitions for windows and when I reinstalled I did it in just one, so ubuntu partitions might have been from sda4 to sda7 before (but not sure). Would this be related to the problem?

My options are to recover this partition with testdisk or to reinstall ubuntu, but I wanted to ask if someone knows of a different solution for this.

I've read similar questions but none provides a solution different from testdisk and I'm not sure if that is my problem.

Edit1:

The output for 'sudo update-grub' reads

/usr/sbin/grub-probe: error: failed to get canonical path of `/cow'.

similar for sudo grub-install /dev/sda3:

$ sudo grub-install /dev/sda3
Installing for i386-pc platform.
grub-install: error: failed to get canonical path of `/cow'.

Edit3 (solution):

In case someone else stumbles with this problem, I recovered the missing partition using parted rescue, as suggested by oldfred in the comments. His solution can be found in this link (posts 21 and 22)

http://ubuntuforums.org/showthread.php?t=1775331&page=3

In order to re-install the grub, I followed these steps:

$ sudo mount /dev/sda7 /mnt
$ sudo mount --bind /dev /mnt/dev 
$ sudo mount --bind /dev/pts /mnt/dev/pts
$ sudo mount --bind /proc /mnt/proc 
$ sudo mount --bind /sys /mnt/sys
$ sudo chroot /mnt
# grub-install --recheck /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

where sda7 was the recovered partition. Worked perfectly.

source (spanish): http://www.taringa.net/post/linux/18583092/Como-recuperar-Grub-despues-de-instalar-Windows.html

2 Answers2

0

No need to mount the partition.

sudo grub-install /dev/XXX EDIT Since it's a dual boot, XXX should be the first sector, EG: /dev/sda

EDIT 2: Your filesystem might be slightly corrupted. You could try this command (DISCLAIMER! A: Command from here, B: Make a backup!): sudo e2fsck -f -b 32768 -y /dev/xxx1

Source: https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows

Source for where to install: Where should I install grub?

  • Hi Android Dev, I edited post with the output – EternalGenin Mar 15 '16 at 15:48
  • @JVR See edited answer. – You'reAGitForNotUsingGit Mar 15 '16 at 15:59
  • 1
    Oh I see, but I'm still getting the same error using /dev/sda – EternalGenin Mar 15 '16 at 16:04
  • 1
    Link is not clear, but you must mount partition with install if using live installer. You only can directly reinstall from inside a working install, as then it knows which partition install is mounted on. And your install is in sda6. Your sda3 is the extended partition. Easier just to use Boot-repair as it sorts out details. – oldfred Mar 15 '16 at 16:28
  • @AndroidDev didn't work either, see Edit2 – EternalGenin Mar 15 '16 at 17:15
  • @oldfred wow you're right sda3 is the extended partition, then the sda4 is missing between 231GB and 256GB. sda6 is my /home – EternalGenin Mar 15 '16 at 17:22
  • 1
    If you did something in Windows to rewrite partition table, it likes to forget to include Linux partition. Not sure why it wrote one but not the other? Parted rescue seems easier than testdisk http://askubuntu.com/questions/665445/upgraded-to-windows-10-on-dual-boot-and-cant-boot-to-ubuntu-partition/665462 and: http://askubuntu.com/questions/654386/windows-10-upgrade-lead-into-grub-rescue/655080#655080 – oldfred Mar 15 '16 at 17:47
  • @oldfred thank you so much for your help, parted rescue did the job. One more doubt, the root partition now appears as sda7 and fdisk says that the partition table entries are not in disk order. Will this be a problem? Should I rename it? – EternalGenin Mar 15 '16 at 21:51
  • No need to change order. It is just a note. It used to be importand when fstab and many tools only used device like /dev/sda7, but now with UUIDs the device number is not as important. I have had drive order issues where I skipped a SATA port on plugging in drives. My flash drive would be sdf, but on reboot becomd sdb and every other drive changed. So best to pay attention. But changing partition order can also create issues. – oldfred Mar 16 '16 at 13:16
  • OK, worked fine. I could restore the grub without problems. Thanks again oldfred. – EternalGenin Mar 16 '16 at 18:25
0

Your problem is not a GRUB problem; you've lost at least one partition, probably because Microsoft's disk partitioning software (which was used during Windows' re-installation) has some severe bugs that can cause exactly this problem when a disk contains logical partitions.

Chances are you can recover your partition(s) using the TestDisk program. You should be cautious, though; this type of recovery operation is not risk-free, particularly when non-experts try to recover partitions. You may want to read the Wikipedia article on MBR data structures and the TestDisk instructions before proceeding. There are plenty of questions and answers that touch on TestDisk on this site, too, but a quick search turned up nothing really concise.

After you've recovered your Ubuntu partition(s), you can re-install GRUB. Note that the partition number may have changed, so don't blindly try to use /dev/sda3, as you did in your initial recovery attempts.

Rod Smith
  • 44,284
  • 7
  • 63
  • 105
  • I could easily recover the partition using parted rescue, and restore the grub, this time mounting sda7 and installing in sda. Thanks for pointing that out – EternalGenin Mar 16 '16 at 18:47