重装windows后如何找回我的ubuntu

来源:互联网 发布:网络公开课的利弊 编辑:程序博客网 时间:2024/05/22 14:36
用LiveCD覆盖Windows启动设置


从LiveCD启动并打开一个终端(terminal).你需要运行几条命令,比如sudo -i,来获得root权限.小心任何一个输入错误,这在root下可能带来不可挽回的结果.

我们需要找到安装Ubuntu的分区.用fdisk -l命令得到分区信息,例如:

$ sudo fdisk -l

Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1           8       64228+  83  Linux
/dev/hda2               9        1224     9767520   83  Linux
/dev/hda3   *        1225        2440     9767520   a5  FreeBSD
/dev/hda4            2441       14593    97618972+   5  Extended
/dev/hda5           14532       14593      498015   82  Linux swap / Solaris
/dev/hda6            2441       14530    97112862   83  Linux

Partition table entries are not in disk order

Here I have three Linux partitions. /dev/hda2 is my root partition, /dev/hda1 is my /boot partition and /dev/hda6 is my /home partitoins. If you only have one, obviously this is the one your Ubuntu system is installed on. If you have more than one and you don't know which one your Ubuntu is installed on, we'll look for it later. First, create a mountpoint for your partition, for example :


$ mkdir /mnt/root


Then mount your partition in it. If you don't know which one it is, then mount any of them, we'll se if it's the correct one.


$ mount -t ext3 /dev/hda2 /mnt/root


Of course, replace /dev/hda2 with the correct name of your partition. You can check if it's the correct one by running ls /mnt/root, which should output something like this :

bin    dev      home        lib    mnt   root     srv  usr
boot   etc      initrd      lib64  opt   sbin     sys  var
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz

If what you have looks not at all like this, you didn't mount the correct partition. Do umount /mnt/root to unmount it and try another one. You also need to mount your /boot partition if you made one, like this :


$ mount -t ext3 /dev/hda1 /mnt/root/boot


To make sure it was the correct one, run ls /mnt/root/boot, which sould output something like this :

config-2.6.18-3-686      initrd.img-2.6.18-3-686.bak  System.map-2.6.18-3-686
grub                     lost+found                   vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686  memtest86+.bin

Once again, if what you have doesn't fit, unmount it and try another partition.

Now that everything is mounted, we just need to reinstall GRUB :


$ grub-install --root-directory=/mnt/root /dev/hda


If you got BIOS warnings try:


$ grub-install --root-directory=/mnt/root /dev/hda --recheck


Of course, replace /dev/hda with the location you want to install GRUB on. If all went well, you should see something like this :


Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.

Check if this is correct or not. If any of the lines is incorrect,

fix it and re-run the script `grub-install'.


(hd0) /dev/hda

Now you can reboot and the GRUB menu should appear. If you see a warning message regarding XFS filesystem, you can ignore it.