『楼 主』:
linux中修复GRUB
使用 LLM 解释/回答一下
linux中修复GRUB
最近2003系统老出问题,
主要是防火墙导致很多聊天软件都用不了@|@
哎,有时候甚至把MBR文件也弄没了
没办法重新安装GRUB么????????
呵呵不需要浪费宝贵时间了,看看最近收获吧: >
.................修复Linux 9 GRUB引导感受...................
1.把安装盘的第一张放到光驱,然后重新启动机器,在BOIS中把系统用光驱来引导。
2.等安装界面出来后,按F5
然后在boot后面下输入
linux rescue
然后就是回车一下
3.一系列键盘以及几项简单的配制,过后就[继续]了。。。这个过程,我不说了,比较简单。
4.然后会出现这样的字符
sh#
5.我们就可以操作GRUB了。。。哈。。。只要能出现这样的,以后都是小KISS了,我就是不说,谁也能明白,地球人都知道了。。。。
sh#grub
会出现这样的字符
grub>
我们就可以在这样的字符后面,注意root后面空格后才是(hdx,y)
grub>root (hdX,Y)
grub>setup (hd0)
如果成功会有一个successful......
这里的X,如果是一个盘,就是0,如果你所安装的linux的根分区在第二个硬盘上,那X就是1了;Y,就是装有linux系统所在的根分区。 setup (hd0)就是把GRUB写到硬盘的MBR上。
我 来举个例子吧,如果以我的硬盘为例。我在第一个硬盘上装了XP,在第一个硬盘的hda9个装了RH73.我总共有两个硬盘。如果我把GRUB丢了,就用这 种办法找回来。如果你不知道你的linux安装到哪个分区上,也就是说,不知道这个Y是多少,这也不要紧,先输入root (hdX,然后用[TAB]来查看,一下就明白了...
操作如下:[前面开机启动的上面有说明]
sh# grub
会出现下面的字样的
grub>
然后再这样操作,如果我知道我的linux装在第一个硬盘上,但我不知道装在哪个分区上,就可以先输入root (hd0,然后用[TAB]键来补齐,然后就明白了,你也可以打入
find /boot/grub/grub.conf
find /grub/grub.conf
来查询下位置
grub>root (hd0,8)
grub>setup (hd0)
当然意外也是有的,比如这次MagicLinux仍旧没法引导系统,解决如下:
装XP系统后不见了GRUB系统引导
用红旗4.1的安装盘
F5
linux rescue
grub
find /grub/grub.conf
得到hd0,6
root (hd0,6)
setup (hd0)
然后退出,grub是建成了,可我只能呆在grub>下了。。。
在grub>下,cat (hd0,6)/grub/grub.conf,回车
查看命令行,照抄第一个LINUX系统登陆的长串命令,回车
boot,回车就进入了系统
然后/boot/grub中建立一个menu.lst文件,直接将grub.conf中内容复制到menu.lst中重起,grub图形界面就回来了~~
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
修复GRUB引导菜单
又看到一些朋友发这样的帖子问重新安装win破坏grub及忘了root密码解决的方法,我写了解决的方法并且置顶,大家以后直接看就可以了。
一、fdisk /mbr是把DOS的引导记录写进MBR
如果grub出现问题。
1,用制作好的软盘启动,如果软盘没有制作好,就用安装光盘选择升级,最后可以制作启动盘,用制作好的软盘启动后,在shell下输入grub-install /dev/hda 这样就把grub安装到到MBR。
2 从光盘启动,当出现boot时,输入linux rescue
一系列键盘以及几项简单的配制,过后就[继续]了。。。这个过程,我不说了,比较简单。
然后会出现这样的字符
sh#grub
会出现这样的字符
grub>
我们就可以在这样的字符后面,输入
grub>root (hdX,Y)
grub>setup (hd0)
如果成功会有一个successful......
这里的X,如果是一个盘,就是0,如果你所安装的linux的根分区在第二个硬盘上,那X就是1了;Y,就是装有linux系统所在的根分区,,不知道根分区在哪,可以df,它就会显示出来。 setup (hd0)就是把GRUB写到硬盘的MBR上。
二、如果超级用户将密码忘记,就无法进入系统,也无法管理和使用系统。本来这种事不太可能发生,但是在一些Linux单机使用者,尤其是初学者中,却是比较容易发生。一般的解决方法就是格式化硬盘来重新安装系统,但这有点儿小题大作了。如何修复,进入有以下方法
当密码忘了怎么办?
一. lilo
1. 在出现 lilo: 提示时键入 linux single
画面显示 lilo: linux single
2. 回车可直接进入linux命令行
3. #vi /etc/passwd
将第一行,即以root开头的一行中root:后和下一个:前的内容删除,
第一行将类似于
root::......
或者直接passwd
保存
4. #reboot重启,root密码为空
二. grub
1. 在出现grub画面时,用上下键选中你平时启动linux的那一项(别选dos哟),然后按e键
2. 再次用上下键选中你平时启动linux的那一项(类似于kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/),然后按e键
3. 修改你现在见到的命令行,加入single,结果如下:
kernel /boot/vmlinuz-2.4.18-14 single ro root=LABEL=/ 或者把single加在最后也可以的。
4. 回车返回,然后按b键启动,即可直接进入linux命令行
5. #vi /etc/passwd
将第一行,即以root开头的一行中root:后和下一个:前的内容删除,
第一行将类似于
root::......
或者直接passwd
保存
6. #reboot重启,root密码为空
如果不是双启动,用制作好的软盘启动,linux single,linux 1,linux -s 都可以进入单用户方式, 然后进去后passwd ,如果没有制作好的软盘,你安装光盘启动,选择升级制作一个。,不过用安装光盘也可以passwd。
在开始时输入linux rescue ,进入修复模式,然后选择只读或是跳过,只读它已经挂接好的硬盘,跳过你要自己挂接硬盘。
然后chroot ./
进入真正的单用户模式,然后passwd.
如果系统中没有软驱,光驱,可以把硬盘拆下,挂到其它有linux,unix的电脑中,然后mount,然后找到挂载你的硬盘的/etc/passwd,清除root密码也可以的。不过这种方法我没有试过。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
修复grub指南(使用工具)
1、下载工具
如 果你将 Grub 安装到了 MBR,重新安装 Windows XP/2K 等会将 MBR 清除,那么怎么修复 MBR 中的 Grub 引导记录呢?这里介绍的方法是使用 Grub4DOS 这个DOS下的工具,最新版本的 Grub4DOS 可以在 这里下载到,下来之后可以用 win 下的 WinRAR、WinZIP 或 Linux 下的 tar zxvf 命令解开,将其中的 grub.exe 放在你的一个 fat/fat32 分区中(如 D:\grub4dos)。
2、重新启动到 DOS,你可以用 DOS 启动软盘或光盘(我想一般都有一张 win98或 winme 光盘吧)。然后键入:
代码:
d:\grub4dos\grub.exe
这样就进入了 Grub 环境,你可以看到一个 gurb> 提示符,下面要做的就是恢复你的 Grub 引导记录
3、在 Grub> 提示符下键入
代码:
root (hdx,y)
kernel (hdx,y)/boot/yourkernelname ro root=/dev/hdxx
setup (hd0)
第一个命令是指定你的 /boot 分区位置,如果你的 /boot 没有单独分区,那么就是你的 / 分区。
第二个命令指定内核位置,具体位置根据自己的实际情况确定。
第三个命令是将 Grub 引导记录写入 MBR 。
如果你对自己的 Linux 分区位置不十分清楚,你可以使用 TAB 键补全功能来查看确定。
执行完 setup 命令后成功会看到 succeed ! 字样。
现在你就可以重启进入 Grub 了。
4、如果你只是想启动 Linux 而不是修复 Grub,那么你可以在进入 DOS 后键入下面命令启动你的 Linux 系统。
代码:
d:\grub4dos\grub.exe --config-file=(hdx,y)/boot/grub/grub.conf
其中参数同上。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
修复Linux的Grub引导(vfloppy)
最 近我的机器硬盘不够用,就把软驱下了(占位置),装了第二块硬盘,然后再将第一块硬盘装了Windows XP,第二块硬盘装了RedHat Fedora Core 1(Red Hat Linux个人版),用Linux下的Grub来引导。考虑到Windows系统经常要重装,想应做一个Linux应急启动盘来修复Grub引导,可没有 软驱如何来做呢?经查看帮助发现如下办法可行,供大家参考:
一、制作Linux启动盘,在Linux下用mkbootdisk可以制作一张启动应 急盘,可没有软驱怎么做呢?没关系,mkbootdisk可以将启动盘制作成镜像文件,在我的机器上是这样做的:mkbootdisk --device /root/fedora.img 2.4.22-1.2115.nptl。最后的参数为你的Linux内核版本号,如不知道可用uname -r查一下。然后将软盘镜像文件拷贝到Windows分区下。
二、找一个叫虚拟启动软盘的软件vfloppy,运行后将fedora.img装载 进去,实际是在Windows XP的boot.ini加入软盘的启动。这样在Windows XP启动时如选择软盘启动就会进入Linux。如Grub损坏或是Windows系统重装后改写了MBR(主引导记录),可用此办法启动到Linux,然 后用grub-install /dev/hda重新安装Grub就可以了。
注:还可以用一些软件来管理MBR,比如SRCTools。
### Repairing GRUB in Linux
Recently, the 2003 system has been having a lot of problems.
Mainly, the firewall causes many chat software to not work @|@
Hey, sometimes even the MBR file is lost
Is there no way to reinstall GRUB???
Hehe, no need to waste precious time. Let's look at the recent gains: >
.................Feeling of repairing Linux 9 GRUB boot...................
1. Put the first installation disc into the CD-ROM, then restart the machine, and set the system to boot from the CD-ROM in the BIOS.
2. When the installation interface appears, press F5
Then type after boot
linux rescue
Then press Enter
3. A series of keyboard operations and a few simple configurations, then ... I won't go into details about this process, it's relatively simple.
4. Then such characters will appear
sh#
5. We can operate GRUB... Hehe... As long as such a thing appears, the rest is easy. I just won't say it, everyone can understand, everyone in the world knows it...
sh#grub
Such characters will appear
grub>
We can operate behind such characters. Note that after the root space is a (hdx,y)
grub>root (hdX,Y)
grub>setup (hd0)
If successful, there will be a successful......
Here, X, if it is one disk, it is 0. If the root partition of your installed Linux is on the second hard disk, then X is 1; Y is the root partition where the Linux system is installed. setup (hd0) is to write GRUB to the MBR of the hard disk.
Let me give an example. Take my hard disk as an example. I installed XP on the first hard disk and RH73 on hda9 of the first hard disk. I have a total of two hard disks. If I lose GRUB, I can use this method to get it back. If you don't know which partition your Linux is installed on, that is, you don't know what Y is, it doesn't matter. First, enter root (hdX, then use to check, and you will understand...
The operation is as follows:
sh# grub
The following words will appear
grub>
Then operate like this. If I know that my Linux is installed on the first hard disk but I don't know which partition it is installed on, I can first enter root (hd0, then use the key to complete, then you will understand. You can also type
find /boot/grub/grub.conf
find /grub/grub.conf
to query the location
grub>root (hd0,8)
grub>setup (hd0)
Of course, there are accidents. For example, this time MagicLinux still can't boot the system. The solution is as follows:
After installing the XP system, GRUB system boot is gone
Use the installation disc of Red Flag 4.1
F5
linux rescue
grub
find /grub/grub.conf
Get hd0,6
root (hd0,6)
setup (hd0)
Then exit, GRUB is built, but I can only stay at grub>...
Under grub>, cat (hd0,6)/grub/grub.conf, press Enter
Check the command line, copy the long command for the first Linux system login, press Enter
boot, press Enter to enter the system
Then create a menu.lst file in /boot/grub, directly copy the content in grub.conf to menu.lst, restart, and the GRUB graphical interface will come back~~
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Repairing the GRUB boot menu
I saw some friends post such posts asking about the method to solve reinstalling Win breaking GRUB and forgetting the root password. I wrote the solution and pinned it, so everyone can just look at it later.
1. fdisk /mbr writes the DOS boot record into the MBR
If GRUB has problems.
1. Boot with a made floppy. If the floppy is not made, use the installation CD to select upgrade, and finally make a bootable disk. After booting with the made floppy, enter grub-install /dev/hda in the shell to install GRUB to the MBR.
2. Boot from the CD. When boot appears, type linux rescue
A series of keyboard operations and a few simple configurations, then ... I won't go into details about this process, it's relatively simple.
Then such characters will appear
sh#grub
Such characters will appear
grub>
We can type behind such characters
grub>root (hdX,Y)
grub>setup (hd0)
If successful, there will be a successful......
Here, X, if it is one disk, it is 0. If the root partition of your installed Linux is on the second hard disk, then X is 1; Y is the root partition where the Linux system is installed. If you don't know where the root partition is, you can use df, and it will display it. setup (hd0) is to write GRUB to the MBR of the hard disk.
2. If the super user forgets the password, he can't enter the system, and can't manage and use the system. Originally, this kind of thing is not very likely to happen, but among some Linux single-machine users, especially beginners, it is relatively easy to happen. The general solution is to format the hard disk and reinstall the system, but this is a bit overkill. How to repair it, there are the following methods
What to do if you forget the password?
1. lilo
1. When the lilo: prompt appears, type linux single
The screen shows lilo: linux single
2. Press Enter to directly enter the Linux command line
3. #vi /etc/passwd
Delete the content after root: and before the next : in the first line, which starts with root.
The first line will be similar to
root::......
Or directly passwd
Save
4. #reboot restart, the root password is empty
2. grub
1. When the grub screen appears, use the up and down keys to select the item you usually start Linux with (don't select dos), then press e key
2. Again use the up and down keys to select the item you usually start Linux with (similar to kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/), then press e key
3. Modify the command line you see now, add single, the result is as follows:
kernel /boot/vmlinuz-2.4.18-14 single ro root=LABEL=/ or you can add single at the end.
4. Press Enter to return, then press b key to start, and you can directly enter the Linux command line
5. #vi /etc/passwd
Delete the content after root: and before the next : in the first line, which starts with root.
The first line will be similar to
root::......
Or directly passwd
Save
6. #reboot restart, the root password is empty
If it is not a dual boot, boot with a made floppy, linux single, linux 1, linux -s can all enter single-user mode, then go in and passwd. If there is no made floppy, you start with the installation CD, select upgrade to make one. However, you can also passwd with the installation CD.
Type linux rescue at the beginning, enter repair mode, then select read-only or skip. Read-only mounts the already mounted hard disk, and skip you have to mount the hard disk yourself.
Then chroot ./
Enter the real single-user mode, then passwd.
If there is no floppy drive or CD-ROM in the system, you can remove the hard disk, hang it on another computer with Linux, Unix, then mount, then find the /etc/passwd that mounts your hard disk, and clear the root password. But I haven't tried this method.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Guide to repairing GRUB (using tools)
1. Download the tool
If you installed Grub to the MBR, reinstalling Windows XP/2K, etc. will clear the MBR. Then how to repair the Grub boot record in the MBR? The method introduced here is to use Grub4DOS, a tool under DOS. The latest version of Grub4DOS can be downloaded here. After downloading, you can use WinRAR, WinZIP under win or the tar zxvf command under Linux to unzip it, and put grub.exe in one of your fat/fat32 partitions (such as D:\grub4dos).
2. Restart to DOS, you can use a DOS boot floppy or CD-ROM (I think everyone generally has a win98 or winme CD-ROM). Then type:
Code:
d:\grub4dos\grub.exe
This enters the Grub environment, and you can see a gurb> prompt. What needs to be done next is to restore your Grub boot record
3. Type under the Grub> prompt
Code:
root (hdx,y)
kernel (hdx,y)/boot/yourkernelname ro root=/dev/hdxx
setup (hd0)
The first command is to specify the location of your /boot partition. If your /boot is not a separate partition, then it is your / partition.
The second command specifies the location of the kernel, which is determined according to your actual situation.
The third command is to write the Grub boot record to the MBR.
If you are not very clear about the location of your Linux partition, you can use the TAB key completion function to check and determine.
After executing the setup command, if successful, you will see the succeed! word.
Now you can restart and enter Grub.
4. If you just want to start Linux instead of repairing Grub, then you can type the following command after entering DOS to start your Linux system.
Code:
d:\grub4dos\grub.exe --config-file=(hdx,y)/boot/grub/grub.conf
The parameters are the same as above.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Repairing the GRUB boot of Linux (vfloppy)
Recently, my machine's hard disk is not enough, so I removed the floppy drive (taking up space), installed a second hard disk, then installed Windows XP on the first hard disk, and RedHat Fedora Core 1 (Red Hat Linux personal edition) on the second hard disk, using Grub under Linux to boot. Considering that the Windows system often needs to be reinstalled, I want to make a Linux emergency boot disk to repair the Grub boot. But without a floppy drive, how to do it? After checking the help, the following method is found to be feasible, for your reference:
1. Make a Linux boot disk. Under Linux, mkbootdisk can be used to make an emergency boot disk. But without a floppy drive, how to do it? It doesn't matter, mkbootdisk can make the boot disk into an image file. On my machine, it is done like this: mkbootdisk --device /root/fedora.img 2.4.22-1.2115.nptl. The last parameter is the version number of your Linux kernel. If you don't know, you can check it with uname -r. Then copy the floppy image file to the Windows partition.
2. Find a software called virtual boot floppy vfloppy. Run it and load fedora.img into it. Actually, add the boot of the floppy to boot.ini in Windows XP. Then when Windows XP starts, if you select floppy boot, you will enter Linux. If Grub is damaged or the Windows system reinstalls and rewrites the MBR (master boot record), you can use this method to boot into Linux, then use grub-install /dev/hda to reinstall Grub.
Note: You can also use some software to manage the MBR, such as SRCTools.
|