本文将介绍 CentOS 通过 EFI 方式启动并在线重装系统。

先决条件:必须为 EFI 方式启动,且引导为 Grub2。

1、下载并安装需要重装的系统版本的引导文件,本例中为 CentOS 7.2.1511

yum -y install wget lsof net-tools
wget /boot/ http://vault.centos.org/7.2.1511/os/x86_64/images/pxeboot/initrd.img -O /boot/initrd_pxe.img
wget /boot/ http://vault.centos.org/7.2.1511/os/x86_64/images/pxeboot/vmlinuz -O /boot/vmlinuz_pxe
chmod +x /boot/vmlinuz_pxe

2、通过 df -hfdisk -l 查看当前系统 /boot 文件夹所在分区。

[root@centos ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        463M     0  463M   0% /dev
tmpfs           494M     0  494M   0% /dev/shm
tmpfs           494M   44M  450M   9% /run
tmpfs           494M     0  494M   0% /sys/fs/cgroup
/dev/sda3        39G  2.1G   37G   6% /
/dev/sda1       512M   12M  501M   3% /boot/efi
tmpfs            99M     0   99M   0% /run/user/1000

[root@centos ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 50.0 GB, 50010783744 bytes, 97677312 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: gpt
Disk identifier: 604C5A4B-DB3A-4BB6-B719-A193B6869312


#         Start          End    Size  Type            Name
 1         2048      1050623    512M  EFI System      EFI System Partition
 2      1050624     17827839      8G  Linux swap      
 3     17827840     97675263   38.1G  Microsoft basic 

从上面的输出可以判断 /boot 目录在 /dev/sda3 分区,故对应的 grub 中应设置为 hd0,gpt3

3、添加 grub 自定义菜单

# 将重装系统的自定义菜单写入 40_custom
cat >> /etc/grub.d/40_custom  << EOF
menuentry 'VNCInstallCentOS' {
    set root='hd0,gpt3'
    linuxefi /boot/vmlinuz_pxe inst.vnc inst.vncpassword=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8` inst.headless ip=dhcp nameserver=114.114.114.114 inst.repo=http://vault.centos.org/7.2.1511/os/x86_64/ inst.lang=en_US inst.keymap=us
    initrdefi /boot/initrd_pxe.img
}
EOF
# 查看 40_custom 菜单,并记录下生成的 vncpassword 的值
cat /etc/grub.d/40_custom
# 重新生成 Grub 菜单
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
# 检查新生成的 Grub 菜单
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/efi/EFI/centos/grub.cfg
# 重新引导进行系统重装
grub2-reboot VNCInstallCentOS
reboot

4、使用VNC客户端连接服务器进行系统重装

注意:连接时需要输入密码,密码在第三步自动生成,你也可以修改第三步的自动生成代码的部分,直接指定你需要的密码。


原文链接地址:http://blog.exsvc.cn/article/centos-efi-pxe-reinstall.html
转载请注明:转载自 易科博客 ,谢谢!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注