无盘启动引导 修复super block

  • Post author:
  • Post category:其他


有一台线上服务器(简称S),运行 centOS 6.5 系统,闲置了一段时间,再次启动,开启报告,super block 损坏。

为了修复super block,本想找一个系统镜像做一个U盘启动盘,发现竟然没有可用的U盘。所以只能脑洞大开,使用network booting 了.

先把 network booting 的方法描述一下:

1 有一台现成的ubuntu机器(简称U),把 S 和 U 连上同一个交换机。

2 在U上安装 dhcp  server 和 tftp server

apt-get install isc-dhcp-server

apt-get install tftpd

3 配置 dhcp server,配置文件 /etc/dhcp/dhcpd.conf ,内容如下:

allow booting;

allow bootp;

# 定义规则来识别来自于PXE和Etherboot客户端的DHCP请求。

class “pxe” {

match if substring (option vendor-class-identifier, 0, 9) = “PXEClient”;

}

class “etherboot” {

match if substring (option vendor-class-identifier, 0, 9) = “Etherboot”;

}

subnet 10.11.0.0 netmask 255.255.255.0 {

option broadcast-address 10.11.0.255;

pool {

default-lease-time 180; # no long lease time required for booting

max-lease-time 360;     # booted system does its own dhcp request

server-name “mybootserver”;

next-server 10.11.0.121; # in case your local DNS only handles

# unqualified domains keep trailing ‘.’

filename “pxelinux.0”;

allow members of “pxe”;

allow members of “etherboot”; # allow etherboot, too

range 10.11.0.120 10.11.0.122;

}

}

注意上面的配置,已经尽量避免局域网内2台dhcp服务器并存造成不利后果,防止U的dhcp干扰网关的DHCP服务运行。

4 配置tftpd,配置文件没有,新建文件  /etc/xinetd.d/tftpd, 内容如下:

service tftp

{

disable         = no

socket_type     = dgram

protocol        = udp

wait            = yes

user            = hhy

server          = /usr/sbin/in.tftpd

server_args     = -s /home/hhy/tftpd/ubuntu-boot

#source          = 11

cps             = 100 2

flags =IPv4

}

注意 /home/hhy/tftpd/ubuntu-boot 目录下的所有文件最好 chmod 777 ,防止因为权限的原因不能读取文件。

5 在机器U上启动 dhcp 服务和 tftp 服务

service isc-dhcp-server start

service xinetd restart

6 制作启动根目录,将 U 上的  /boot 下的 vmlinuz 和 initrd.img 拷贝到 /home/hhy/tftpd/ubuntu-boot 下

将 /usr/lib/syslinux/pxelinux.0 拷贝到 /home/hhy/tftpd/ubuntu-boot 下

在 /home/hhy/tftpd/ubuntu-boot 建立目录 pxelinux.cfg,并在pxelinux.cfg目录下新建一个文件名为default的文件,内容如下:

default linux

prompt   1

timeout  30

# Install Linux

label linux

kernel vmlinuz

append initrd=initrd-full.img splash=silent showopts

上面的操作完成后,/home/hhy/tftpd/ubuntu-boot 下ls得到的结果如下:

initrd.img  pxelinux.0  pxelinux.cfg   vmlinuz

7 启动机器S,按F10,选择从network boot(注意:我的案例是按F10,别的机器可能不是,注意看开机后bios中的提示)。这时候可以看到,S机器成功的找到U了,并从U机器的 /home/hhy/tftpd/ubuntu-boot 启动了,最终进入 initrd 环境。

8 S机器进入initrd后,发现了一个问题。没有fdisk mke2fs e2fsck 这些常用的文件系统命令。于是重新制作一个 initrd.img.方法如下:

cd /home/hhy/tftpd/ubuntu-boot

mkdir tmp && mv initrd.img tmp/initrd.zip

cd tmp && gunzip initrd.zip

cpio -id < ./initrd

cp /sbin/fdisk /sbin/mke2fs /sbin/e2fsck  ./sbin

用ldd命令检查  fdisk mke2fs e2fsck 依赖的so模块是否都在当前目录( /home/hhy/tftpd/ubuntu-boot/tmp/)下,经过检查都有。

find ./ | grep -v initrd | cpio -H newc -o | gzip -v -9 > ./initrd.img

cp initrd.img ../initrd-full.img

修改 /home/hhy/tftpd/ubuntu-boot/pxelinux.cfg/default 下的内容,修改 initrd=initrd.img 为 initrd=initrd-full.img

9 重启机器S并再次 network booting,进入 initrd 后,就可以使用 fdisk mke2fs e2fsck  这些命令了。df 命令显示 S 有2个硬盘 /dev/sda /dev/sdd.再用fdisk命令发现这2个盘竟然各有一个 boot 分区。使用 dumpe2fs 发现所有的文件系统都报告超级块找不到,懵了?后来请服务器厂商检查硬盘,原来是硬盘基本报废了,无法修复。



版权声明:本文为amdkings1原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。