在Mac OS X下无提示安装CentOS 7后,虚拟盒子缺少来宾添加物

问题描述 投票:0回答:1

我正在使用Virtual Box在Mac OS X上设置Centos7虚拟机。这在过去似乎没什么效果,但突然我遇到了问题。不知道为什么。

我确实创建了一个脚本来自动化整个过程。该脚本主要基于最小的ISO安装程序进行VBoxManage Centos的无人参与安装。

VBoxManage unattended install centos7 --user=datasqill --password=pwd --country=DE --locale=de_DE --time-zone=UTC --hostname=centos7.treimers --iso=/Users/treimers/Projekte/Linux/CentOS-7-x86_64-Minimal-1908.iso --post-install-template redhat_postinstall.sh --script-template redhat67_ks.cfg --install-additions --start-vm=gui

我曾经打电话

VBoxManage guestproperty wait centos7 /VirtualBox/GuestInfo/OS/NoLoggedInUsers

为了等待安装过程完成。等待不会终止,并且似乎永远等待。我认为这是因为未安装来宾添加项。

在我的脚本下面找到,我正在使用Virtual Box Application文件夹中的资源文件redhat67_ks.cfg和redhat_postinstall.sh。

我的环境是

OS:Mac OS X 10.11.6(El Capitan)虚拟盒子:6.1.6 r137129CentOS映像:CentOS-7-x86_64-Minimal-1908.iso

也许有人知道我的设置可能有什么问题。

谢谢托尔斯滕

#!/bin/bash

function printhelp() {
    echo "Create CentOS VM"
    echo "Usage: $(basename $0) [OPTIONS]..."
    echo "Creates a new VirtualBox VM with CentOS 7"
    echo
    echo "Options:"
    echo "  -?: help - print usage and exit"
    echo "  -c <country>: country - country setting for new VM like DE, EN, ..."
    echo "  -h <hostname>: host name - host name of new VM"
    echo "  -i <isoimage>: isoimage- path to CentOS ISO Image"
    echo "  -k <keyfile>: keyfile - private Vagrant key file (use ./vagrant.d/insecure_private_key in user home directory)"
    echo "  -l <locale>: locale - locale setting of new VM like de_DE, en_US, ..."
    echo "  -m <keymap>: keymap - keyboard map for new VM like de, en, ..."
    echo "  -n <name>: name - VirtualBox name of new VM"
    echo "  -p <password>: password - password for standard user and root user in new VM"
    echo "  -s <size>: size - disk size in MB"
    echo "  -t <timezone>: timezone - time zone of new VM like UTC, ..."
    echo "  -u <user>: user - create standard user with given name in new VM"
    echo "  -v: verbose - prints all commands to console on execution [OPTIONAL]"
    echo
    echo "Example:"
    echo "$(basename $0) -c DE -h centos7.datasqill -i ~/Projekte/Linux/CentOS-7-x86_64-Minimal-1908.iso -k ~/.vagrant.d/insecure_private_key -l de_DE -m de -n centos7 -p softquadrat -s 8192 -t UTC -u datasqill"
    echo
    echo ""
    exit 1
}

function removeOld() {
    # remove any failed previous attempt
    # https://www.virtualbox.org/ticket/17335
    VBoxManage controlvm ${VBoxName} poweroff 2> /dev/null || true
    sleep 10
    VBoxManage unregistervm ${VBoxName} --delete 2> /dev/null || true
    sleep 10
    rm -fr "${VBoxDir}"/${VBoxName} 2> /dev/null
}

function createVM() {
    # create vm
    # Note: available ostypes can be displayed by VBoxManage list ostypes | less
    VBoxManage createvm --name ${VBoxName} --ostype RedHat_64 --register
    # create and attach disks
    VBoxManage createmedium --filename "${VBoxDir}/${VBoxName}/${VBoxName}.vdi" --size ${diskSize}
    VBoxManage storagectl ${VBoxName} --name SATA --add SATA --controller IntelAhci
    VBoxManage storageattach ${VBoxName} --storagectl SATA --port 0 --device 0 --type hdd --medium "${VBoxDir}/${VBoxName}/${VBoxName}.vdi"
    VBoxManage storagectl ${VBoxName} --name IDE --add ide
    VBoxManage storageattach ${VBoxName} --storagectl IDE --port 0 --device 0 --type dvddrive --medium ${IsoImage}
    # set memory
    VBoxManage modifyvm ${VBoxName} --memory 1024 --vram 16
    # enable io apic
    VBoxManage modifyvm ${VBoxName} --ioapic on
    # set boot order
    VBoxManage modifyvm ${VBoxName} --boot1 dvd --boot2 disk --boot3 none --boot4 none
    # set virtual cpus
    VBoxManage modifyvm ${VBoxName} --cpus 1
    # disable audio
    VBoxManage modifyvm ${VBoxName} --audio none
    # disable usb controller
    VBoxManage modifyvm ${VBoxName} --usb off
    VBoxManage modifyvm ${VBoxName} --usbehci off
    VBoxManage modifyvm ${VBoxName} --usbxhci off
    # define network settings
    VBoxManage modifyvm ${VBoxName} --nic1 nat
    # create port forwarding rule
    # VBoxManage modifyvm ${VBoxName} --natpf1 ssh2,tcp,127.0.0.1,22022,,22
}

function unattendedInstall() {
    # start unattended installation
    VBoxManage unattended install ${VBoxName} --user=${user} --password=${password} --country=${country} --locale=${locale} --time-zone=${timezone} --hostname=${hostname} --iso=${IsoImage} --post-install-template redhat_postinstall.sh --script-template redhat67_ks.cfg --install-additions --start-vm=gui
}

function waitVM() {
    VBoxManage guestproperty wait ${VBoxName} "/VirtualBox/GuestInfo/OS/NoLoggedInUsers"
}

function postInstall() {
    # set keymap
    # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/s1-changing_the_keyboard_layout
    # https://linuxconfig.org/how-to-change-system-keyboard-keymap-layout-on-centos-7-linux
    VBoxManage guestcontrol ${VBoxName} --username=root --password=${password} run /bin/localectl set-keymap ${keymap}
    # allow sudo
    cat > ${user} <<-EOF
        ${user} ALL=(ALL) NOPASSWD:ALL
        Defaults:${user} !requiretty
EOF
    VBoxManage guestcontrol ${VBoxName} --username=root --password=${password} copyto --target-directory /etc/sudoers.d ${user}
    rm ${user}
    # create authorized keys
    ssh-keygen -y -f ${privateKeyFile} > authorized_keys
    VBoxManage guestcontrol ${VBoxName} --username=${user} --password=${password} mkdir --parents /home/${user}/.ssh
    VBoxManage guestcontrol ${VBoxName} --username=${user} --password=${password} copyto --target-directory /home/${user}/.ssh authorized_keys
    VBoxManage guestcontrol ${VBoxName} --username=${user} --password=${password} run /bin/chmod 700 /home/${user}/.ssh
    VBoxManage guestcontrol ${VBoxName} --username=${user} --password=${password} run /bin/chmod 600 /home/${user}/.ssh/authorized_keys
    rm authorized_keys
}

function doall() {
    echo "--- Removing old installation"
    date +"%y-%m-%d-%H-%M-%S"
    removeOld
    echo "--- Creating virtual machine"
    date +"%y-%m-%d-%H-%M-%S"
    createVM
    echo "--- Starting Unattended Installation"
    date +"%y-%m-%d-%H-%M-%S"
    unattendedInstall
    echo "--- Wait VM"
    date +"%y-%m-%d-%H-%M-%S"
    waitVM
    echo "--- Post Install Steps"
    date +"%y-%m-%d-%H-%M-%S"
    postInstall
    echo "--- Done"
    date +"%y-%m-%d-%H-%M-%S"
}

# main starts here
set -o nounset
set -o errexit

# get opts
while getopts "?c:h:i:k:l:m:n:p:s:t:u:v" opt; do
    case ${opt} in
    \?)
        printhelp
        ;;
    c)
        country=${OPTARG}
        ;;
    h)
        hostname=${OPTARG}
        ;;
    i)
        IsoImage=${OPTARG}
        ;;
    k)
        privateKeyFile=${OPTARG}
        ;;
    l)
        locale=${OPTARG}
        ;;
    m)
        keymap=${OPTARG}
        ;;
    n)
        VBoxName=${OPTARG}
        ;;
    p)
        password=${OPTARG}
        ;;
    s)
        diskSize=${OPTARG}
        ;;
    t)
        timezone=${OPTARG}
        ;;
    u)
        user=${OPTARG}
        ;;
    v)
        set -x
        ;;
    *)
        echo "Error: Unknown option ${opt}"
        echo
        printhelp
        ;;
    esac
done

shift $((OPTIND-1))

if [[ $# -ne 0 || -z "${country:-}" || -z "${hostname:-}" || -z "${IsoImage:-}" || -z "${privateKeyFile:-}" || -z "${locale:-}"|| -z "${keymap:-}" || -z "${VBoxName:-}" || -z "${password:-}" || -z ${diskSize:-} || -z "${timezone:-}" || -z "${user:-}" ]]
then
    printhelp
fi

# directory with virtual boxes
VBoxDir=`VBoxManage list systemproperties | awk '/Default machine folder/ { print $4 }'`

# get date and time stamp
dat=`date +"%y-%m-%d-%H-%M-%S"`

# log file
logfile=log/createCentOSVM_${dat}.log
mkdir -p log

{
    doall
} 2>&1 | tee ${logfile}
virtualbox
1个回答
0
投票

我终于解决了我的问题。 RTFL =读取f ..日志。

系统无法使用以下命令找到并安装内核开发软件包

log_command_in_target yum -y install "kernel-devel-$(uname -r)"

这是安装Virtual Box来宾附加项所必需的。

我的客户机系统是CentOS 7,但是我使用了最低的ISO进行安装(CentOS-7-x86_64-Minimal-2003.iso),并且其中不包含内核devel软件包。我切换到完整的ISO映像(CentOS-7-x86_64-DVD-2003.iso),突然发现它毫无问题地工作了。

© www.soinside.com 2019 - 2024. All rights reserved.