virsh 显示虚拟机正在运行,但它无法启动,或者没有网络访问权限

virsh 显示虚拟机正在运行,但它无法启动,或者没有网络访问权限

我在让虚拟机在 18.04 (服务器) LTS 上运行方面遇到了很多麻烦。我说运行,是因为感觉 virsh 报告它在运行,但它从未启动过。这是一个非常基本的测试虚拟机,我正在尝试设置它,以便我能够为我试图启动的几个生产 (家庭服务器) 虚拟机获得正确的语法。我想退出并像几年前一样回到 14.04 LTS,但我正在尝试了解为什么我看到的是什么。

这是 Ubuntu 服务器 18.04 LTS 的全新安装,迄今为止仅完成了以下操作。

添加到 /etc/apt/sources.list,这可以防止操作系统找不到和安装软件包,特别是 mailutils 和 ubuntu-vm-builder。

deb http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe

sudo apt-get install zfsutils-linux
sudo zpool import Storage
sudo zpool status
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install htop nmon samba nfs-kernel-server nfs-common qemu-kvm postfix mailutils ubuntu-vm-builder libvirt-bin

禁用软盘:

echo "blacklist floppy" | sudo tee /etc/modprobe.d/blacklist-floppy.conf
sudo rmmod floppy
sudo update-initramfs -u

这是 /etc/netplan/50-cloud-init.yaml 的输出:(我对这个不太了解,我没有安装云实例,所以也许 18.04 LTS 的实际安装存在问题,因为我看到的所有帐户都表明这个安装的版本似乎与我预期的版本不同。

network:
    version: 2
    renderer: networkd
    ethernets:
            switchports:
              # all cards on second PCI bus; unconfigured by themselves, will be added
              # to br0 below
              match:
                name: enp1*
              mtu: 4400
    bridges:
      # the key name is the name for virtual (created) interfaces; no match: and
      # set-name: allowed
      br0:
        # IDs of the components; switchports expands into multiple interfaces
        interfaces: [switchports]
        addresses: [172.16.5.20/24]
        gateway4: 172.16.5.1
        nameservers:
          addresses: [172.16.5.2]
        parameters:
          forward-delay: 0
          stp: false

sudo netplan apply

如您所见,网桥 0 已启动并且状态良好,能够访问互联网,并且能够无问题地通过 ssh 连接到主机。

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.5.20  netmask 255.255.255.0  broadcast 172.16.5.255

下面是用于启动虚拟机的命令的输出。我对看到的错误有点困惑,因为它们显示为信息性错误,并且不会停止设置。尝试 ping 时,我只得到“目标主机无法访问”的结果。

/$ sudo ubuntu-vm-builder kvm xenial \
>  --dest /Test/Chaos/Test.raw \
>  --hostname Test \
>  --arch amd64 \
>  --mem 4096 \
>  --cpus 4 \
>  --user tadmin \
>  --pass password \
>  --bridge br0 \
>  --ip 172.16.5.29 \
>  --mask 255.255.255.0 \
>  --net 172.16.5.0 \
>  --bcast 172.16.5.255 \
>  --gw 172.16.5.1 \
>  --dns 172.16.5.2 \
>  --components main,universe \
>  --addpkg openssh-server \
>  --addpkg linux-image-generic \
>  --rootsize=20000 \
>  --libvirt qemu:///system ;


2018-09-17 13:10:03,441 INFO    : logging to file: /tmp/tmp3MbyqN
2018-09-17 13:10:03,476 INFO    : Calling hook: preflight_check
2018-09-17 13:10:03,483 INFO    : Calling hook: set_defaults
2018-09-17 13:10:03,484 INFO    : Calling hook: bootstrap
2018-09-17 13:12:51,406 INFO    : Calling hook: configure_os
2018-09-17 13:12:57,667 INFO    : W: Can't drop privileges for downloading as file '/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial_InRelease' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
Extracting templates from packages: 100%
2018-09-17 13:14:44,201 INFO    : W: --force-yes is deprecated, use one of the options starting with --allow instead.
2018-09-17 13:14:44,202 INFO    : W: Can't drop privileges for downloading as file '/var/cache/apt/archives/partial/libglib2.0-0_2.48.2-0ubuntu4_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
2018-09-17 13:14:45,839 INFO    :
2018-09-17 13:14:45,840 INFO    : Current default time zone: 'Etc/UTC'
2018-09-17 13:14:45,842 INFO    : Local time is now:      Mon Sep 17 13:14:45 UTC 2018.
2018-09-17 13:14:45,843 INFO    : Universal Time is now:  Mon Sep 17 13:14:45 UTC 2018.
2018-09-17 13:14:45,843 INFO    :
2018-09-17 13:14:48,138 INFO    : Generating locales (this might take a while)...
2018-09-17 13:14:49,088 INFO    :   en_US.UTF-8... done
2018-09-17 13:14:49,088 INFO    : Generation complete.
Extracting templates from packages: 100%
2018-09-17 13:15:50,805 INFO    : W: --force-yes is deprecated, use one of the options starting with --allow instead.
2018-09-17 13:15:50,805 INFO    : W: Can't drop privileges for downloading as file '/var/cache/apt/archives/partial/base-files_9.4ubuntu4.7_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
2018-09-17 13:15:53,842 INFO    : Cleaning up
2018-09-17 13:15:53,842 INFO    : Calling hook: preflight_check
2018-09-17 13:15:53,939 INFO    : Calling hook: configure_networking
2018-09-17 13:15:53,954 INFO    : Calling hook: create_partitions
2018-09-17 13:15:53,955 INFO    : Creating disk image: "/tmp/tmpBfFwBQ" of size: 21024MB
2018-09-17 13:15:53,972 INFO    : Adding partition table to disk image: /tmp/tmpBfFwBQ
2018-09-17 13:15:54,013 INFO    : Adding type 4 partition to disk image: /tmp/tmpBfFwBQ
2018-09-17 13:15:54,013 INFO    : Partition at beginning of disk - reserving first cylinder
2018-09-17 13:15:54,020 INFO    : Warning: The resulting partition is not properly aligned for best performance.
2018-09-17 13:15:54,041 INFO    : Adding type 3 partition to disk image: /tmp/tmpBfFwBQ
2018-09-17 13:15:54,048 INFO    : [0] ../../libparted/filesys.c:148 (ped_file_system_type_get): File system alias linux-swap(new) is deprecated
2018-09-17 13:15:54,048 INFO    : Warning: The resulting partition is not properly aligned for best performance.
2018-09-17 13:15:54,069 INFO    : Creating loop devices corresponding to the created partitions
2018-09-17 13:15:54,296 INFO    : Creating file systems
2018-09-17 13:15:54,302 INFO    : mke2fs 1.44.1 (24-Mar-2018)
2018-09-17 13:15:55,459 INFO    : Calling hook: configure_mounting
2018-09-17 13:15:55,469 INFO    : Calling hook: mount_partitions
2018-09-17 13:15:55,470 INFO    : Mounting target filesystems
2018-09-17 13:16:00,451 INFO    : Calling hook: install_bootloader
2018-09-17 13:16:03,607 INFO    : E: Can not write log (Is /dev/pts mounted?) - posix_openpt (19: No such device)
2018-09-17 13:16:05,114 INFO    : Removing update-grub hooks from /etc/kernel-img.conf in favour of
2018-09-17 13:16:05,114 INFO    : /etc/kernel/ hooks.
2018-09-17 13:16:05,254 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:05,259 INFO    : findfs: unable to resolve 'UUID=0eca356a-3113-4242-8b0f-fd8e5b4876bb'
2018-09-17 13:16:05,262 INFO    : Cannot determine root device.  Assuming /dev/hda1
2018-09-17 13:16:05,262 INFO    : This error is probably caused by an invalid /etc/fstab
2018-09-17 13:16:05,402 INFO    : Searching for default file ... Generating /boot/grub/default file and setting the default boot entry to 0
2018-09-17 13:16:05,404 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:05,409 INFO    : Testing for an existing GRUB menu.lst file ...
2018-09-17 13:16:05,410 INFO    :
2018-09-17 13:16:05,410 INFO    : Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub: line 1094: read: read error: 0: Bad file descriptor
2018-09-17 13:16:05,703 INFO    : W: --force-yes is deprecated, use one of the options starting with --allow instead.
2018-09-17 13:16:05,703 INFO    : W: Can't drop privileges for downloading as file '/var/cache/apt/archives/partial/libc6-i386_2.23-0ubuntu10_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
2018-09-17 13:16:12,288 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:12,292 INFO    : findfs: unable to resolve 'UUID=0eca356a-3113-4242-8b0f-fd8e5b4876bb'
2018-09-17 13:16:12,294 INFO    : Cannot determine root device.  Assuming /dev/hda1
2018-09-17 13:16:12,295 INFO    : This error is probably caused by an invalid /etc/fstab
2018-09-17 13:16:12,430 INFO    : Searching for default file ... found: /boot/grub/default
2018-09-17 13:16:12,434 INFO    : Testing for an existing GRUB menu.lst file ...
2018-09-17 13:16:12,434 INFO    :
2018-09-17 13:16:12,434 INFO    : Could not find /boot/grub/menu.lst file.
2018-09-17 13:16:12,434 INFO    : Generating /boot/grub/menu.lst
2018-09-17 13:16:12,514 INFO    : Searching for splash image ... none found, skipping ...
2018-09-17 13:16:12,714 INFO    : Found kernel: /boot/vmlinuz-4.4.0-135-generic
2018-09-17 13:16:12,860 INFO    : Updating /boot/grub/menu.lst ... done
2018-09-17 13:16:12,860 INFO    :
2018-09-17 13:16:13,085 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:13,092 INFO    : findfs: unable to resolve 'UUID=0eca356a-3113-4242-8b0f-fd8e5b4876bb'
2018-09-17 13:16:13,094 INFO    : Cannot determine root device.  Assuming /dev/hda1
2018-09-17 13:16:13,094 INFO    : This error is probably caused by an invalid /etc/fstab
2018-09-17 13:16:13,233 INFO    : Searching for default file ... found: /boot/grub/default
2018-09-17 13:16:13,239 INFO    : Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
2018-09-17 13:16:13,373 INFO    : Searching for splash image ... none found, skipping ...
2018-09-17 13:16:13,434 INFO    : Found kernel: /boot/vmlinuz-4.4.0-135-generic
2018-09-17 13:16:13,556 INFO    : Replacing config file /run/grub/menu.lst with new version
2018-09-17 13:16:13,626 INFO    : Found kernel: /boot/vmlinuz-4.4.0-135-generic
2018-09-17 13:16:13,758 INFO    : Updating /boot/grub/menu.lst ... done
2018-09-17 13:16:13,758 INFO    :
2018-09-17 13:16:13,821 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:13,861 INFO    : Calling hook: install_kernel
2018-09-17 13:16:14,686 INFO    : E: Can not write log (Is /dev/pts mounted?) - posix_openpt (19: No such device)
2018-09-17 13:16:15,077 INFO    : W: --force-yes is deprecated, use one of the options starting with --allow instead.
2018-09-17 13:16:15,077 INFO    : W: Can't drop privileges for downloading as file '/var/cache/apt/archives/partial/linux-image-virtual_4.4.0.135.141_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
2018-09-17 13:16:15,078 INFO    : Calling hook: post_install
2018-09-17 13:16:15,078 INFO    : Calling hook: unmount_partitions
2018-09-17 13:16:15,079 INFO    : Unmounting target filesystem
2018-09-17 13:16:18,978 INFO    : Calling hook: convert
2018-09-17 13:16:18,979 INFO    : Converting /tmp/tmpBfFwBQ to qcow2, format /Test/Chaos/Test.raw/tmpBfFwBQ.qcow2
2018-09-17 13:16:20,862 INFO    : Calling hook: fix_ownership
2018-09-17 13:16:20,865 INFO    : Calling hook: deploy
/$
/$
/$ virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     Test                           shut off

/$
/$ virsh start Test
Domain Test started

/$
/$
/$ ping 172.16.5.29
PING 172.16.5.29 (172.16.5.29) 56(84) bytes of data.
From 172.16.5.20 icmp_seq=1 Destination Host Unreachable
From 172.16.5.20 icmp_seq=2 Destination Host Unreachable
From 172.16.5.20 icmp_seq=3 Destination Host Unreachable
^C
--- 172.16.5.29 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3062ms
pipe 4
/$

答案1

消除重复,这是您的ubuntu-vm-builder脚本日志所说的内容(希望日志简洁):

2018-09-17 13:10:03,441 INFO    : logging to file: /tmp/tmp3MbyqN

您应该查看(而不是发布)这个文件。

2018-09-17 13:12:51,406 INFO    : Calling hook: configure_os
2018-09-17 13:12:57,667 INFO    : W: Can't drop privileges for downloading as file '/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial_InRelease' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

用户_apt尝试访问 ,但失败了/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial_InRelease。是否有/partial未完成的更新?或者使用我的pathlld脚本 (https://github.com/waltinator/pathlld.git) 进行调查。使用getent passwd _apt查找的UID和。GID_apt

2018-09-17 13:14:44,201 INFO    : W: --force-yes is deprecated, use one of the options starting with --allow instead.

这不是你的问题——它属于软件包开发者的问题。

2018-09-17 13:15:54,048 INFO    : [0] ../../libparted/filesys.c:148 (ped_file_system_type_get): File system alias linux-swap(new) is deprecated

这不是你的问题——它属于软件包开发者的问题。

2018-09-17 13:16:03,607 INFO    : E: Can not write log (Is /dev/pts mounted?) - posix_openpt (19: No such device)

这是一个重大问题 -/dev/pts在启动过程的早期就通过 进行了安装/etc/rcS.d/S04mountdevsubfs.sh。您的 VM 非常糟糕。

2018-09-17 13:16:05,259 INFO    : findfs: unable to resolve 'UUID=0eca356a-3113-4242-8b0f-fd8e5b4876bb'

UUID=0eca356a-3113-4242-8b0f-fd8e5b4876bb真实的磁盘?难道不应该查看吗/tmp/tmpBfFwBQ?指的是什么UUID

2018-09-17 13:16:05,262 INFO    : Cannot determine root device.  Assuming /dev/hda1
2018-09-17 13:16:05,262 INFO    : This error is probably caused by an invalid /etc/fstab

错误的假设!它将设备视为/dev/hda1/以搜索/etc/fstab。这不是您想要的。这是您的真实分区,而不是虚拟/分区。mount | grep hda1将显示。

2018-09-17 13:16:05,404 INFO    : Searching for GRUB installation directory ... found: /boot/grub
2018-09-17 13:16:05,409 INFO    : Testing for an existing GRUB menu.lst file ...
2018-09-17 13:16:05,410 INFO    :
2018-09-17 13:16:05,410 INFO    : Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub: line 1094: read: read error: 0: Bad file descriptor

Bad file descriptor意味着,在第 行1094/usr/sbin/update-grub尝试读取来自 的响应STDIN,但无法读取,因为它在一个有故障的系统中运行。

2018-09-17 13:16:18,979 INFO    : Converting /tmp/tmpBfFwBQ to qcow2, format /Test/Chaos/Test.raw/tmpBfFwBQ.qcow2

这是您的(损坏的)VM。

相关内容