使用 virt-install 從命令行安裝 VM
免責聲明:
我現在
virt-manager
用來創建和管理我的虛擬機,它確實是一個救生員。如果主機沒有圖形顯示,它可以遠端使用(從第三台機器,通常是您的工作站)。我發現的安裝教程中的出現
vnc
讓我認為“推薦”過程需要主機、來賓或兩者上的 X 東西。絕對不。我的錯。如果您處於相同的情況,請在嘗試從命令行安裝 VM 之前三思而後行。我正在嘗試在 Debian 主機中安裝 Debian VM,但
virt-install
我不知道如何將 .iso 映像傳遞給它。virt-install --connect qemu:///system --virt-type kvm --name prod --ram 6144 --disk /srv/vm/prod.qcow,format=qcow2,size=10 --location=/home/jerome/debian-8.0.0-amd64-netinst.iso --network bridge=br0 --os-type linux --os-variant debianwheezy --extra-args='console=tty0 console=ttyS0,115200n8 serial' Starting install... Retrieving file info... | 160 B 00:00 ... ERROR Could not find an installable distribution at '/home/jerome/debian-8.0.0-amd64-netinst.iso' The location must be the root directory of an install tree. Domain installation does not appear to have been successful. If it was, you can restart your domain by running: virsh --connect qemu:///system start prod otherwise, please restart your installation. root@versailles:/etc#
我看到的解決方案似乎很扭曲,比如使用 apache 在本地提供 .iso 圖像,就好像它來自遙遠的地方一樣。
- Linux Mint 14:通過 CLI(無 GUI)在 KVM 中安裝 Ubuntu 12.10 伺服器
- $$ Xen-users $$使用 virt-install 安裝虛擬機(它是 Xen,但看起來還是一樣的問題。
我不敢相信它有那麼複雜。是嗎?
man virt-install
說:If you want to use those options with CDROM media, you have a few options: * Run virt-install as root and do --location ISO * Mount the ISO at a local directory, and do --location DIRECTORY * Mount the ISO at a local directory, export that directory over local http, and do --location http://localhost/DIRECTORY
這不是我在做什麼嗎?
有人說他將 .iso 移到 /cdrom 並且它有效,但我不明白他做了什麼,我無法重現。
我不能在這個問題
--cdrom
中使用而不是--location
as因為只有在使用.--extra-args``--location
virt-install --connect qemu:///system --virt-type kvm --name prod --ram 6144 --disk /srv/vm/prod.qcow,format=qcow2,size=10 --cdrom=/home/jerome/debian-8.0.0-amd64-netinst.iso --network bridge=br0 --os-type linux --os-variant debianwheezy --extra-args='console=tty0 console=ttyS0,115200n8 serial' ERROR --extra-args only work if specified with --location. See the man page for examples of using --location with CDROM media
編輯:
登錄
--debug
virt-install --connect qemu:///system --virt-type kvm --name prod --ram 6144 --disk /srv/vm/prod.qcow,format=qcow2,size=10 --location=/home/jerome/debian-8.0.0-amd64-netinst.iso --network bridge=br0 --os-type linux --os-variant debianwheezy --extra-args='console=tty0 console=ttyS0,115200n8 serial' --debug [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:187) Launched with command line: /usr/share/virt-manager/virt-install --connect qemu:///system --virt-type kvm --name prod --ram 6144 --disk /srv/vm/prod.qcow,format=qcow2,size=10 --location=/home/jerome/debian-8.0.0-amd64-netinst.iso --network bridge=br0 --os-type linux --os-variant debianwheezy --extra-args=console=tty0 console=ttyS0,115200n8 serial --debug [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:195) Requesting libvirt URI qemu:///system [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:199) Received libvirt URI qemu:///system [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (virt-install:193) Requesting virt method 'default', hv type 'kvm'. [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (virt-install:432) Received virt method 'kvm' [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (virt-install:433) Hypervisor name is 'hvm' [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:476) DISPLAY is not set: defaulting to nographics. [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (guest:208) Setting Guest.os_variant to 'debianwheezy' [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (diskbackend:171) Path '/srv/vm' is target for pool 'srv-kvm'. Creating volume 'prod.qcow'. [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (connection:228) Fetching volume XML failed: Storage volume not found: no storage vol with matching path '/media/cdrom0/debian-8.0.0-amd64-netinst.iso' [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (virt-install:551) Guest.has_install_phase: True Starting install... [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (distroinstaller:417) Using scratchdir=/var/lib/libvirt/boot [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:204) Preparing mount at /var/lib/libvirt/boot/virtinstmnt.srz86f [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:214) mount cmd: ['/bin/mount', '-o', 'ro,loop', '/home/jerome/debian-8.0.0-amd64-netinst.iso', '/var/lib/libvirt/boot/virtinstmnt.srz86f'] [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:302) Finding distro store for location=/home/jerome/debian-8.0.0-amd64-netinst.iso [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/.treeinfo [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:325) Prioritizing distro store=<class 'virtinst.urlfetcher.DebianDistro'> [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/current/images/MANIFEST [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/daily/MANIFEST [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/Fedora [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:99) Fetching URI: /var/lib/libvirt/boot/virtinstmnt.srz86f/.disk/info [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:110) Saved file to /var/lib/libvirt/boot/virtinst-info.lZMVqL Retrieving file info... | 160 B 00:00 ... [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:1016) Regex didn't match, not a ALT Linux distro [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/current/images/MANIFEST [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/install/netboot/version.info [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/SL [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/directory.yast [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/CentOS [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/VERSION [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/Server [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/Client [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/RedHat [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/images/pxeboot/vmlinuz [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/images/boot.iso [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/boot/boot.iso [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/current/images/netboot/mini.iso [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:183) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.srz86f/install/images/boot.iso [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (urlfetcher:225) Cleaning up mount at /var/lib/libvirt/boot/virtinstmnt.srz86f [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:234) File "/usr/share/virt-manager/virt-install", line 876, in <module> sys.exit(main()) File "/usr/share/virt-manager/virt-install", line 870, in main start_install(guest, continue_inst, options) File "/usr/share/virt-manager/virt-install", line 588, in start_install fail(e, do_exit=False) File "/usr/share/virt-manager/virtinst/cli.py", line 234, in fail logging.debug("".join(traceback.format_stack())) [mer., 03 juin 2015 17:46:12 virt-install 12991] ERROR (cli:235) Could not find an installable distribution at '/home/jerome/debian-8.0.0-amd64-netinst.iso' The location must be the root directory of an install tree. [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:237) Traceback (most recent call last): File "/usr/share/virt-manager/virt-install", line 560, in start_install dom = guest.start_install(meter=meter, noboot=options.noreboot) File "/usr/share/virt-manager/virtinst/guest.py", line 384, in start_install self._prepare_install(meter, dry) File "/usr/share/virt-manager/virtinst/guest.py", line 277, in _prepare_install util.make_scratchdir(self.conn, self.type)) File "/usr/share/virt-manager/virtinst/installer.py", line 201, in prepare self._prepare(guest, meter, scratchdir) File "/usr/share/virt-manager/virtinst/distroinstaller.py", line 444, in _prepare self._prepare_kernel_url(guest, fetcher) File "/usr/share/virt-manager/virtinst/distroinstaller.py", line 347, in _prepare_kernel_url store = urlfetcher.getDistroStore(guest, fetcher) File "/usr/share/virt-manager/virtinst/urlfetcher.py", line 346, in getDistroStore fetcher.location)) ValueError: Could not find an installable distribution at '/home/jerome/debian-8.0.0-amd64-netinst.iso' The location must be the root directory of an install tree. [mer., 03 juin 2015 17:46:12 virt-install 12991] DEBUG (cli:248) Domain installation does not appear to have been successful. If it was, you can restart your domain by running: virsh --connect qemu:///system start prod otherwise, please restart your installation. Domain installation does not appear to have been successful. If it was, you can restart your domain by running: virsh --connect qemu:///system start prod otherwise, please restart your installation.
它可以工作,
--location http://ftp.us.debian.org/debian/dists/stable/main/installer-amd64/
但是當 .iso 映像在本地可用時這樣做不是有點可惜嗎?
- 可追溯性的喪失:您無法在以後複製,以確保您獲得完全相同的來源。
- 成倍地使用來自伺服器/鏡像的頻寬。
- 需要上網。
- 慢點。
virt-install
嘗試從 ISO 映像中提取核心和 initrd 文件。您可以看到它--debug
的整個活動,包括循環安裝、搜尋這些文件等。Starting install... [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (Installer:182) scratchdir=/var/lib/libvirt/boot [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:184) Preparing mount at /var/lib/libvirt/boot/virtinstmnt.dwcpql [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (OSDistro:65) Attempting to detect distro: [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/.treeinfo [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/Fedora [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/Server [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/Client [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/RedHat [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/CentOS [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/SL [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/directory.yast [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/current/images/MANIFEST [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/daily/MANIFEST [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/current/images/MANIFEST [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/install/netboot/version.info [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/initrd.gz [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (OSDistro:990) Doesn't look like an Ubuntu Distro. [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/VERSION [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/VERSION [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/boot/platform/i86xpv/kernel/unix [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/platform/i86xpv/kernel/unix [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/STARTUP/XNLOADER.SYS [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/images/pxeboot/vmlinuz [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/images/boot.iso [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/boot/boot.iso [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/current/images/netboot/mini.iso [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:169) local hasFile: Couldn't find /var/lib/libvirt/boot/virtinstmnt.dwcpql/install/images/boot.iso [Wed, 03 Jun 2015 07:56:40 virt-install 29692] DEBUG (ImageFetcher:205) Cleaning up mount at /var/lib/libvirt/boot/virtinstmnt.dwcpql [Wed, 03 Jun 2015 07:56:40 virt-install 29692] ERROR (cli:445) Could not find an installable distribution at '/home/yaegashi/debian-8.0.0-amd64-netinst.iso'
我想
virt-install
不支持 Debian netinst ISO 映像--location
(但不知何故 Ubuntu 支持?)。要使用 啟動核心
--extra-args
,virt-install
需要具有這些核心和相應的 initrd 文件。--cdrom
只是將 ISO 附加到客戶的 CD 驅動器,這不足以使用--extra-args
.如果您想使用
--extra-args
,我建議您通過指定最近鏡像的 Debian 安裝程序 URL 來使用“netboot”核心/initrd 文件,如--location http://ftp.us.debian.org/debian/dists/stable/main/installer-amd64/
手冊中所述。
這種方法對我有用:
virt-install --name=centos \ --memory=8196 --vcpus=2 \ --location=/var/lib/libvirt/images/CentOS-7-x86_64-Minimal-1511.iso \ --disk /var/lib/libvirt/images/centos7.qcow2,device=disk,bus=virtio,size=8 \ --network bridge:br0 \ --os-type=linux \ --nographics \ --extra-args='console=tty0 console=ttyS0,115200n8 serial'