首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >KVM和Kickstart -未能关闭

KVM和Kickstart -未能关闭
EN

Unix & Linux用户
提问于 2017-03-12 12:52:26
回答 2查看 1.7K关注 0票数 1

我正在构建一个工具来帮助我管理我的KVM服务器。它生成一个命令,该命令使用一个启动文件为我自动安装KVM来宾。下面是它生成的用于自动安装Ubuntu16.04来宾的示例命令。

代码语言:javascript
复制
virt-install --connect qemu:///system  \
--nographics \
--os-type linux \
--accelerate \
--hvm \
--network network=default,model=virtio \
--name testing124 \
--os-variant ubuntu16.04 \
--ram 1024 \
--vcpus 2 \
--location http://us.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/ \
--disk /home/stuart/code-copy/vms/testing124/disk.raw,bus=virtio,format=raw,cache=writethrough \
--extra-args "console=ttyS0 ks=http://pastebin.com/raw/6TznVUuN"

我希望使用exec命令从工具内部执行此命令,而不是打印出来,并要求我手动复制和粘贴它以执行,就像我到现在为止所做的那样。问题是命令永远不会完成,因为virt控制台始终处于打开状态。默认情况下,来宾将重新启动,并连接控制台。如果我指定shutdown而不是reboot,那么安装将停留在以下步骤:

如果我指定了haltpoweroff而不是shutdown,那么来宾就会关闭,但是控制台仍然挂在一个空白屏幕上。如果执行running,则Virsh也会将来宾显示为virsh list --all

需要对KVM来宾安装所需的命令或KVM启动文件进行哪些更改才能优雅地完成?

附录

启动文件将在下面复制,以防引用的文件发生更改或丢失。

代码语言:javascript
复制
# Ubuntu server 64bit example kickstart/seed with shutdown

# System language
#lang en_US
lang en_GB

# Language modules to install
#langsupport en_US
langsupport en_GB

# System keyboard
keyboard us

# System mouse
mouse

# System timezone
#timezone America/Chicago
timezone --utc America/Chicago

# Root password
rootpw --disabled

# Initial user
user ubuntu --fullname "" --password ubuntu
preseed user-setup/allow-password-weak boolean true

# pick only one of these actions to take after installation completed
#reboot
#shutdown
#halt
poweroff

# Use text mode install
text

# Install OS instead of upgrade
install

# Use http installation media
url --url http://archive.ubuntu.com/ubuntu

# System bootloader configuration
bootloader --location=mbr

# Clear the Master Boot Record
zerombr yes

# Partition clearing information
clearpart --all --initlabel

# Partition setup
part / --fstype ext4 --size 1 --grow
#part /boot --fstype ext2 --size 200 --asprimary
#part swap  --size 1024
#part pv.01 --size 1 --grow
#volgroup rootvg pv.01
#logvol / --fstype ext4 --vgname=rootvg --size=1 --grow --name=rootvol
#preseed partman-lvm/confirm_nooverwrite boolean true

# If you have swap commented out/not specified then you need to have this line.
preseed --owner partman-basicfilesystems partman-basicfilesystems/no_swap boolean false

# System authorization infomation
auth  --useshadow  --enablemd5

# Firewall configuration
firewall --disabled

# Do not configure the X Window System
skipx

# Make sure to install the acpid package so that virsh commands such
# as virsh shutdown will take effect
%packages
@ubuntu-server
@openssh-server
@acpid
EN

回答 2

Unix & Linux用户

发布于 2017-03-12 15:01:21

事实证明,这正是--noautoconsole选项在virt-install中的完美之处。

来自手册页的描述:

不要自动尝试连接到来宾控制台。默认行为是启动VNC客户端来显示图形控制台,或者运行"virsh“" console”命令来显示文本控制台。使用此参数将禁用此行为。

现在,程序执行的virt命令几乎会立即执行并返回,因为它不会连接到控制台并等待客户完成安装。即使没有任何连接到控制台,客人仍将继续使用启动脚本在后台安装。只要启动文件没有任何问题,客户将在完成时执行完整的安装和关机(如果在启动文件中指定了关机)。我可以通过轮询virsh list --all判断客户何时已经完成安装,直到客户不再显示为running为止。

更新后的命令如下:

代码语言:javascript
复制
virt-install --connect qemu:///system  \
--nographics \
--os-type linux \
--accelerate \
--hvm \
--network network=default,model=virtio \
--name testing124 \
--os-variant ubuntu16.04 \
--ram 1024 \
--vcpus 2 \
--location http://us.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/ \
--disk /home/stuart/code-copy/vms/testing124/disk.raw,bus=virtio,format=raw,cache=writethrough \
--noautoconsole \
--extra-args "console=ttyS0 ks=http://pastebin.com/raw/6TznVUuN"
票数 1
EN

Unix & Linux用户

发布于 2017-03-12 23:40:17

我在自动化安装中通常使用的是--noreboot --noautoconsole,它几乎涵盖了完全无人参与的安装。尽管如此,使用virt-builder而不是virt-install通常更快、更好,因为命令比完整的OS安装更稳定,图像操作更快和更一致。有了预先制作好的模板,VM映像的速度甚至比这个还要快。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/350920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档