Centos 远程重装系统

一、得到基本信息

# 查看 IP地址及网卡信息
[root@localhost /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:21:70:5c:a5:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.17.131/24 brd 192.168.17.255 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::221:70ff:fe5c:a56f/64 scope link
valid_lft forever preferred_lft forever
# 查看网关
[root@localhost /]# ip route show
default via 192.168.17.254 dev enp3s0 proto static metric 100
192.168.17.0/24 dev enp3s0 proto kernel scope link src 192.168.17.131 metric 100

从这里我们可以得到如下信息:

设备名称: enp3s0
IP地址:192.168.17.131
网关地址:192.168.17.254
子网掩码:255.255.255.0

二、下载CentOS 的 bootstrap 文件

阿里云镜像地址:http://pub.mirrors.aliyun.com/centos

cd /boot && wget http://pub.mirrors.aliyun.com/centos/7/os/x86_64/isolinux/vmlinuz && wget http://pub.mirrors.aliyun.com/centos/7/os/x86_64/isolinux/initrd.img

三、添加grub启动条目

查看/boot/grub2/grub.cfg,找到如下代码部分:

menuentry 'CentOS Linux (3.10.0-327.22.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-5abaf349-18ce-4481-8e31-f29b0120827f' {

        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  3ee40dd3-d836-4aa5-b145-9fbc2541b151
        else
          search --no-floppy --fs-uuid --set=root 3ee40dd3-d836-4aa5-b145-9fbc2541b151
        fi
    linux16 /vmlinuz-3.10.0-327.22.2.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
        initrd16 /initramfs-3.10.0-327.22.2.el7.x86_64.img
}

然后把这一段拷贝到/etc/grub.d/40_custom中做如下修改:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry 'NetInstall' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  3ee40dd3-d836-4aa5-b145-9fbc2541b151
        else
          search --no-floppy --fs-uuid --set=root 3ee40dd3-d836-4aa5-b145-9fbc2541b151
        fi
    linux16 /vmlinuz inst.vnc inst.vncpassword=12345678 inst.headless ip=192.168.17.131::192.168.17.254:255.255.255.0::enp3s0:none nameserver=114.114.114.114 inst.repo=http://pub.mirrors.aliyun.com/centos/7/os/x86_64/ inst.lang=en_US inst.keymap=us
    initrd16 /initrd.img
}
# 此处解释一下格式:
inst.vnc #启用vnc
inst.vncpassword=12345678 # vnc 登陆密码(至少是8个及其以上的字符)
inst.headless
ip=192.168.17.131::192.168.17.254:255.255.255.0::enp3s0:none # ip=ip::网关:子网掩码::设备名称:none
nameserver=114.114.114.114 # DNS地址
inst.repo=http://mirror.centos.org/centos/7/os/x86_64/ # yum源地址
inst.lang=en_US # 默认语言
inst.keymap=us # 键盘模式
# 配置/etc/default/grub
vim /etc/default/grub
# 修改 GRUB_DEFAULT=0 为 GRUB_DEFAULT=saved
# 除此之外保证没有被修改过

再检查一次,所有配置

四、 重建grub配置

# 重建grub配置,如果是efi,需要grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg
# 列出所有启动条目
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
# 下一次启动使用NetInstall,仅使用一次
grub2-reboot NetInstall
# 重启系统
reboot

五、使用VNC安装CentOS系统

其他资料都提到等待一分钟左右,个人实验等待了约10分钟,这主要取决于网速。

下载 tightVNC (http://www.tightvnc.com/download.php)

地址:ip-xxxxxx:1

密码:12345678

Guess you like

Origin blog.csdn.net/never_late/article/details/121558876