Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2116414
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2010-10-20 10:42:23

同事误操作删除了/bin和/boot分区,/bin目录没有了,/boot目录下面为空,导致系统命令不能正常使用,也不敢重新启动系统,还有业务系统在跑。

解决思路:
1、找一台操作系统环境相同的机器,拷贝目录到该机器。
2、估计的重新安装内核,因为找不到内核映射了。


详细解决步骤如下:
1、重新启动机器,插入光盘,进入带网络环境的救援模式。

2、把另外一个系统的bin目录的压缩包拷贝过来,然后解压。

3、因为系统内核丢失了,所以我们需要先安装内核,在安装内核时会自动生成initrd
   a、cd /mnt/
   b、mkdir cd
   c、mount -t iso9660 -o ro /dev/hda /mnt/cd/  (注意,使用dmesg命令详细查看光驱挂载的设备,我的是/dev/hda)
   d、rpm -Uvh --force kernel-2.6.18-164.el5.i686.rpm
4、安装grub
   a、grup-install /dev/sda


5、编辑grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda7
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.18-164.el5.img

注意,如果你是逻辑卷需要修改根目录的标签,我的是逻辑卷。


6,重新启动系统
重新启动系统未成功,出现以下错误:
mount: could not find filesystem '/dev/root'
setuproot: moving /dev failed: No such file or directory
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
switchroot: mount failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init!

经过搜索后,发现此类问题多集中在逻辑卷管理的情况,具体原因是我们在重新安装内核的时候,没有加载一些逻辑卷,解决方法如下:

1) Boot with the rescue CD
2) Type 'chroot /mnt/sysimage'
3) 'cd /boot'
4) 'mkdir newinit'
5) 'cd newinit'
6) 'gunzip -c ../initrd-2.6.18-164.el5.img | cpio -idmv'
7) 'vi init'
8) Find 'mount /sysroot'
9) Delete or comment this out
10) Replace with 'mount -o defaults --ro -t ext3 /dev/VolGroup00/LogVol00 /sysroot' where /dev/VolGroup00/LogVol00 is the mount point for /
11) ':wq' out of vi
12) 'find . | cpio --quiet -c -o >../newinitrd'
13) 'cd ..' - you are now in /boot
14) 'mv initrd-2.6.18-164.el5.img initrd-2.6.18-164.el5.img.bak' - backup current initrd img file
15) 'gzip -9 < newinitrd > initrd-2.6.18-164.el5.img'
16) Reboot the computer without the CD

再次重新启动系统,OK,问题解决。

7、尝试进行远程连接,因为远程服务器不允许root直接连接,可以用普通用户进行登录,登录后执行 su - root 命令,输入密码总是提示密码错误,但是在终端直接用root是可以登录的,奇怪,后来发现问题出在 su 命令上,是文件权限粘贴位的问题,因为拷贝过来的su命令权限如下:

[root@localhost ~]# ll /bin/su
-rwxr-xr-x 1 root root 23960 Oct 18 21:46 /bin/su

正确如下:
[root@localhost ~]# ll /bin/su
-rwsr-xr-x 1 root root 23960 Oct 18 21:46 /bin/su

这样就简单了,设置粘贴位如下:
[root@localhost ~]# chmod u+s mount

除了su命令外,还有另外几个需要设置粘贴位,mount,ping,ping6,traceroute,traceroute6,umount。
另外还要注意一些软连接。


参考文献:
http://blog.chinaunix.net/u3/93926/showart_1873106.html
http://hi.baidu.com/shaotg/blog/item/ab03ed36384c07310b55a9e0.html

阅读(7352) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~