使用VNC远程安装CentOS 7操作系统

使用VNC远程安装CentOS 7操作系统

by 无若

 

数据中心一般都不在本地,如果希望重新安装系统,难道还要跑到数据中心...
所以必须要有一种方式来远程解决这个问题。

目前CentOS 7主要使用的引导方式是grub2,这与过去的grub1差别其实是很大的。

 

1. 确定你的网卡名称,IP等相关信息

# 查看 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

 

2. 下载 CentOS 的 bootstrap 文件

yum install wget
cd /boot
wget http://mirror.centos.org/centos/7/os/x86_64/isolinux/vmlinuz -O vmlinuz-7
wget http://mirror.centos.org/centos/7/os/x86_64/isolinux/initrd.img -O initrd-7.img

 

3. 添加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-7 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://mirror.centos.org/centos/7/os/x86_64/ inst.lang=en_US inst.keymap=us
    initrd16 /initrd-7.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

打开 /etc/default/grub

修改 GRUB_DEFAULT=0 为 GRUB_DEFAULT=saved

 

# 再检查一次,所有配置

 

4. 重建配置,使配置生效

# 重建grub配置

grub2-mkconfig -o /boot/grub2/grub.cfg

# 列出所有启动条目

awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg

# 下一次启动使用NetInstall,仅使用一次

grub2-reboot NetInstall

# 重启系统

reboot

 

5. 使用VNC安装CentOS系统 

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

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

密码就是上面设置的 12345678

 

成功进入CentOS的安装界面

 

注意:这里使用的是外部的yum源,很多情况下网络是封闭的,那么就必须搭建一台内网的yum源服务器,具体可以参考

http://www.cnblogs.com/gleaners/p/5735472.html

 

参考:

http://www.danpros.com/2016/02/how-to-install-centos-7-remotely-using-vnc 

 

posted @ 2016-08-04 14:10  拾穗云谷  阅读(5278)  评论(0编辑  收藏  举报