运行Ubuntu20.04的KVM虚机遇到一些问题, 单独总结一下

镜像扩容

不能用virt-resize --expand /dev/sda1 old.qcow2 new.qcow2这样的命令, 这样制作出来的镜像, 丢失了/dev/sda14, /dev/sda15这两个分区, 变成了 /dev/sda1, /dev/sda2, /dev/sda3, 会导致install --import时卡住. 用virt-filesystems --long --parts --blkdevs -h -a new.qcow2命令查看, 会发现/dev/sda1的大小变成了4MB

因为镜像是为云服务提供的, 安装启动时配合init脚本扩容, 如果要脱机扩容的话, 网上几乎查不到能解决这个问题的办法, 最后是通过 转换为raw格式->parted调整分区大小->转回qcow2完成的, 参考 https://blog.richliu.com/2018/08/25/2318/change-ubuntu-cloud-image-size/

具体过程为

  1. # resize原始镜像
  2. qemu-img resize focal-server-cloudimg-amd64-50g.qcow2 50G
  3. # 转换为raw格式镜像
  4. qemu-img convert -f qcow2 -O raw focal-server-cloudimg-amd64-50g.qcow2 focal-server-cloudimg-amd64.raw
  5. # 重命名以防混淆
  6. mv focal-server-cloudimg-amd64.raw focal-server-cloudimg-amd64-50g.raw
  7. # 运行parted
  8. parted focal-server-cloudimg-amd64-50g.raw
  9. ######################## 开始
  10. GNU Parted 3.1
  11. Using /data/backup/vm_images/focal-server-cloudimg-amd64-50g.raw
  12. Welcome to GNU Parted! Type 'help' to view a list of commands.
  13. (parted) p
  14. Error: The backup GPT table is not at the end of the disk, as it should be.
  15. This might mean that another operating system believes the disk is smaller.
  16. Fix, by moving the backup to the end (and removing the old backup)?
  17. Fix/Ignore/Cancel? Fix
  18. Warning: Not all of the space available to
  19. /data/backup/vm_images/focal-server-cloudimg-amd64-50g.raw appears to be used,
  20. you can fix the GPT to use all of the space (an extra 100245504 blocks) or
  21. continue with the current setting?
  22. Fix/Ignore? Fix
  23. Model: (file)
  24. Disk /data/backup/vm_images/focal-server-cloudimg-amd64-50g.raw: 53.7GB
  25. Sector size (logical/physical): 512B/512B
  26. Partition Table: gpt
  27. Disk Flags:
  28. Number Start End Size File system Name Flags
  29. 14 1049kB 5243kB 4194kB bios_grub
  30. 15 5243kB 116MB 111MB fat32 boot
  31. 1 116MB 2361MB 2245MB ext4
  32. (parted) resizepart
  33. Partition number? 1
  34. End? [2361MB]? 53.7G
  35. (parted) p
  36. Model: (file)
  37. Disk /data/backup/vm_images/focal-server-cloudimg-amd64-50g.raw: 53.7GB
  38. Sector size (logical/physical): 512B/512B
  39. Partition Table: gpt
  40. Disk Flags:
  41. Number Start End Size File system Name Flags
  42. 14 1049kB 5243kB 4194kB bios_grub
  43. 15 5243kB 116MB 111MB fat32 boot
  44. 1 116MB 53.7GB 53.6GB ext4
  45. (parted) q
  46. ########################### 结束
  47. # 查看raw格式的分区大小是否正确
  48. virt-filesystems --long --parts --blkdevs -h -a focal-server-cloudimg-amd64-50g.raw
  49. Name Type MBR Size Parent
  50. /dev/sda1 partition - 50G /dev/sda
  51. /dev/sda14 partition - 4.0M /dev/sda
  52. /dev/sda15 partition - 106M /dev/sda
  53. /dev/sda device - 50G -
  54. # 转回qcow2格式
  55. qemu-img convert -f raw -O qcow2 focal-server-cloudimg-amd64-50g.raw focal-server-cloudimg-amd64-50g-resized.qcow2
  56. # 再次检查
  57. virt-filesystems --long --parts --blkdevs -h -a focal-server-cloudimg-amd64-50g-resized.qcow2
  58. Name Type MBR Size Parent
  59. /dev/sda1 partition - 50G /dev/sda
  60. /dev/sda14 partition - 4.0M /dev/sda
  61. /dev/sda15 partition - 106M /dev/sda
  62. /dev/sda device - 50G -

经过上面的操作, 这个镜像在安装后只需要执行resize2fs /dev/vda1就能扩充分区了.

root口令

focal-server-cloudimg-xxx 这些镜像是为云环境创建的, 会配合一个init脚本(或者iso)启动并创建普通用户, 默认root不能登录也没有密码, 而单机运行还是需要root的, 所以在安装前, 要设置一下root口令:

  1. virt-customize -a some.qcow2c --root-password password:[your password]

import安装虚机

命令

  1. virt-install --name vm_ub01 --vcpus 4 --memory 8192 --disk /data/vms/vm_ubtu.qcow2 --graphics none --import --os-type linux --os-variant ubuntu20.04 --network bridge=br0,model=virtio

网络配置

这些是在虚机上执行的, 在install --import之后, 虚机网卡是未启动的, 而且net-tools也没安装, 只能通过基础的ip命令进行操作

  1. # 查看ip, 可以看到有一个未启动的ens3网口
  2. ip addr
  3. # 启动nes3,
  4. ip link set ens3 up
  5. # 再次查看, 并无ipv4地址
  6. ip addr
  7. # 查看网卡硬件信息, 这里可以看到mac地址和网口名称
  8. lshw -class network
  9. # 增加网络配置
  10. vi /etc/netplan/99_config.yaml
  11. # 内容开始
  12. network:
  13. version: 2
  14. renderer: networkd
  15. ethernets:
  16. ens3:
  17. dhcp4: true
  18. # 内容结束, 用下面的命令启用
  19. netplan apply
  20. # 再次查看, 这时候就有ip了
  21. ip addr
  22. # ping检查连通性
  23. ping 202.38.64.1

启动sshd失败

虚机上启动ssh, 出现ssh.service: Start request repeated too quick的错误

sshd -t检查, 提示no hostkey

  1. sshd: no hostkeys available -- exiting.

重新生成hostkey

  1. ssh-keygen -A
  2. ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519

之后重启sshd就正常了

关于hostkey

hostkey就是ssh服务中, 服务端的私钥, 正常情况是随着OpenSSH安装时一起生成的.

  1. In OpenSSH, host keys are usually stored in the /etc/ssh directory, in files starting with ssh_host_<rsa/dsa/ecdsa/ed25519>_key (the location can be changed in server configuration files).
  2. Host keys are normally generated automatically when OpenSSH is first installed or when the computer is first booted. The ssh-keygen program can be used for generating additional host keys or for replacing existing keys.

root不能通过密码登录ssh

需要修改/etc/ssh/sshd_config, 将这两行改成下面的值, 然后重启ssh服务

  1. PermitRootLogin yes
  2. PasswordAuthentication yes

参考

Ubuntu20.04 Focal Cloudimage扩容以及KVM安装的问题记录的更多相关文章

  1. 从零开始安装搭建win10与ubuntu20.04双系统开发环境——集安装、配置、软件、美化、常见问题等于一体的——超详细教程

    目录 **前言 ** 关于系统安装配置与软件安装 一.Win10安装ubuntu20.04双系统 1.按照自己的需求分区 2.配置软件镜像源 软件包管理工具介绍 更换APT源--使用国内镜像 3.解决 ...

  2. Mac Mini 安装Ubuntu20.04 KVM

    在一台 Mac Mini mid 2011上安装Ubuntu20.04并配置KVM环境, 过程也适用于其他版本的Mac Mini. 硬件配置 I5 2415, 内存8G*2, 硬盘 SSD 500G ...

  3. 树莓派4b安装Ubuntu20.04

    树莓派4b安装Ubuntu20.04 下载Ubuntu20.04镜像 下载地址 安装Raspberry Pi Imager 下载地址 烧录系统 打开Raspberry Pi Imager,选择自己刚刚 ...

  4. ubuntu20.04 编译安装ckermit

    ubuntu20.04编译安装ckermit 我呢之前一直使用的是ubuntu18.04,最近在安装了某个软件之后,再加上自己的操作不当最终导致ubuntu系统卡死无法进入桌面环境,早就想更新20.0 ...

  5. Ubuntu20.04安装Typora

    Ubuntu20.04安装Typora 安装方法 # optional, but recommended sudo apt-key adv --keyserver keyserver.ubuntu.c ...

  6. 在VirtualBox上安装Ubuntu-20.04

    本文主要介绍如何在VirtualBox上安装Ubuntu-20.04 目录 下载VirtualBox 下载Ubuntu-20.04镜像 新建虚拟机 第一步:打开VirtualBox 第二步:设置虚拟机 ...

  7. 自动化kolla-ansible部署ubuntu20.04+openstack-victoria之准备安装-09

    自动化kolla-ansible部署ubuntu20.04+openstack-victoria之准备安装-09 欢迎加QQ群:1026880196 进行交流学习 准备安装 #controller1 ...

  8. Ubuntu20.04安装Redis

    本文介绍了如何在Ubuntu20.04上安装Redis. 安装Redis sudo apt install redis-server 检查服务的状态 安装完成后可以通过以下命令检查服务的状态 sudo ...

  9. Ubuntu20.04安装MongoDB

    本教程描述了如何在Ubuntu20.04上安装MongoDB4.4 安装MongoDB Ubuntu 20.04默认存储库中不提供最新版本的MongoDB,因此需要在系统中添加官方的MongoDB存储 ...

随机推荐

  1. 带你读AI论文丨RAID2020 Cyber Threat Intelligence Modeling GCN

    摘要:本文提出了基于异构信息网络(HIN, Heterogeneous Information Network)的网络威胁情报框架--HINTI,旨在建模异构IOCs之间的相互依赖关系,以量化其相关性 ...

  2. nRF24L01基于FIFO TX队列的发送性能优化

    RF24项目代码分析 头文件 https://github.com/nRF24/RF24/blob/master/RF24.h 源文件 https://github.com/nRF24/RF24/bl ...

  3. Spark-寒假-实验2

    1. 计算级数 代码: import scala.io.StdIn object jishu { def main(args:Array[String]) { var Sum=0.0 println( ...

  4. 2月4日 体温APP开发记录

    1.阅读构建之法 现代软件工程(第三版) 2.观看Android开发视频教程最新版 Android Studio开发 3.数据库链接,,数据传输功能测试

  5. 2月3日 体温APP开发记录

    1.阅读构建之法 现代软件工程(第三版) 2.观看Android开发视频教程最新版 Android Studio开发 3.回返地址学习,下载导入相关jar包

  6. 【经验总结】CodeBlocks使用mingw64

    CodeBlocks使用 标签:c++ 一.安装并配置mingw-w64 使用中发现CB默认的编译器版本过低,c++11的一些东西无法使用,比如string中的stoi函数,因此尝试安装新版本的编译器 ...

  7. IoC容器-Bean管理注解方式(组件扫描配置)

    4,开启组件扫描细节配置

  8. linux文件权限全面解析

    目录 linux文件权限全面解析 一:linux文件的权限有哪些? 1,权限分为3个部分 2,权限位 3,每一个权限拥有一个数字编号 4,在添加权限的时候,可以将权限加起来 5,linux添加权限命令 ...

  9. 字节跳动的一道python面试题

    #!/usr/bin/python #coding=utf-8 #好好学习,天天向上 lst = ['hongkong','xiantyk','chinat','guangdong','z'] lst ...

  10. Windows 10 Version 21h1安装

    好久没安装过Windows 10系统了,这两天在下载电脑管家时,使用bing搜索,没注意就选择了第一个,安装后,噩梦就来了,非法广告.各种软件的推送,怎么也清不干净. 没办法,到PCBeta下载了最新 ...