如何使用Live CD来修复Grub / Grub2

注册 Vultr VPS 送你10美金 免费玩4个月

Introduction

一般我会在计算机上装两个或者多个系统,例如,我在计算机上安装了Ubuntu、Windows 7、Windows 8.1。有一天我的Win8.1不能正常使用了,我想重新安装Win8.1,但是安装之后Linux就不能被引导进入了!大家知道Linux是使用Grub来引导的,那我们完全可以重新安装Grub!

因为原先的Linux不能进入了,所以我们制作一个Linux系统安装盘,然后利用“试用Ubuntu“来完成这个任务。

制作Linux安装盘

暂时不说这个了。

开始恢复

列出磁盘分区

[email protected]:~$ sudo fdisk -l

我有三个硬盘,输出结果如下:

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x2bf44b31

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   209717247   104857600    7  HPFS/NTFS/exFAT
/dev/sda2       209717248   419432447   104857600    7  HPFS/NTFS/exFAT
/dev/sda3       419434494  1953523711   767044609    f  W95 Ext'd (LBA)
Partition 3 does not start on physical sector boundary.
/dev/sda5       419434496   629149695   104857600    7  HPFS/NTFS/exFAT
/dev/sda6       629151744   838866943   104857600    7  HPFS/NTFS/exFAT
/dev/sda7       838868992  1048584191   104857600    7  HPFS/NTFS/exFAT
/dev/sda8      1048586240  1048975359      194560   83  Linux
/dev/sda9      1048977408  1348974591   149998592   83  Linux
/dev/sda10     1348976640  1548974079    99998720   83  Linux
/dev/sda11     1548976128  1889515519   170269696    7  HPFS/NTFS/exFAT
/dev/sda12     1889525760  1953523711    31998976   82  Linux swap / Solaris

Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc4e7c4e7

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xafd68fba

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   209717247   104857600    7  HPFS/NTFS/exFAT
/dev/sdc2       209717248   625139711   207711232    f  W95 Ext'd (LBA)
/dev/sdc5       209719296   625139711   207710208    7  HPFS/NTFS/exFAT

其中System标记为Linux的就是Linux控制的分区了。

挂载硬盘上的Linux分区

我自己知道当初安装Linux的时候分区是这样的:

/boot   ~200MB
/       ~150GB
/home   ~?

所以我判断:

/dev/sda8  /boot
/dev/sda9  /
/dev/sda10 /home

故作如下挂挂载操作:

[email protected]:~$ sudo mount /dev/sda9  /mnt
[email protected]:~$ sudo mount /dev/sda8  /mnt/boot
[email protected]:~$ sudo mount /dev/sda10 /mnt/home

挂载结束后,还要进行如下操作(原因不明):

[email protected]:~$ sudo mount --bind /sys /mnt/sys
[email protected]:~$ sudo mount --bind /proc /mnt/proc
[email protected]:~$ sudo mount --bind /dev /mnt/dev

使用硬盘上的Linux系统重新安装grub

如果你使用的是grub2:

[email protected]:~$ sudo chroot /mnt
[email protected]:/# grub2-install /dev/sda
[email protected]:/# grub2-mkconfig -o /boot/grub2/grub.cfg
[email protected]:/# exit # 退出chroot

如果不是grub2:

[email protected]:~$ sudo chroot /mnt
[email protected]:/# grub-install /dev/sda
[email protected]:/# grub-mkconfig -o /boot/grub/grub.cfg
[email protected]:/# exit # 退出chroot

退出 & 重起

如果你想

[email protected]:~$ sudo umount /mnt/sys
[email protected]:~$ sudo umount /mnt/proc
[email protected]:~$ sudo umount /mnt/dev
[email protected]:~$ sudo umount /mnt/home
[email protected]:~$ sudo umount /mnt/boot
[email protected]:~$ sudo umount /mnt
[email protected]:~$ sudo shutdown -r -h now

注册 Vultr VPS 送你10美金 免费玩4个月