使用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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM