使用guestfish修改Centos系统Qcow2镜像默认配置

镜像下载地址

https://cloud.centos.org/centos/7/images/

安装所需工具

[root@controller ~]# yum install -y libguestfs-tools-c

修改默认Root密码

[root@controller ~]# virt-customize --add CentOS-7-x86_64-GenericCloud-2009.qcow2 --root-password password:000000
[   0.0] Examining the guest ...
virt-customize: error: libguestfs error: could not create appliance through 
libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: Cannot access storage file 
'/root/CentOS-7-x86_64-GenericCloud-2009.qcow2' (as uid:107, gid:107): 
Permission denied [code=38 int1=13]

If reporting bugs, run virt-customize with debugging enabled and include 
the complete output:

  virt-customize -v -x [...]

如果出现以上提示权限不足等信息,可根据提示声明一个环境变量实现直接修改Root密码

[root@controller ~]# export LIBGUESTFS_BACKEND=direct

再次执行修改Root密码

[root@controller ~]# virt-customize --add CentOS-7-x86_64-GenericCloud-2009.qcow2 --root-password password:000000
[   0.0] Examining the guest ...
[  24.2] Setting a random seed
[  24.4] Setting passwords
[  37.2] Finishing off
[root@controller ~]# 

开启ssh远程登录

先运行该镜像并将系统分区挂载至根目录下

[root@controller ~]# guestfish --rw -a CentOS-7-x86_64-GenericCloud-2009.qcow2 

Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.

Type: ‘help’ for help on commands
      ‘man’ to read the manual
      ‘quit’ to quit the shell

><fs>run
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
><fs> list-filesystems 
/dev/sda1: xfs
><fs> mount /dev/sda1 /
><fs> 

编辑/etc/ssh/sshd_config配置文件

><fs> vi /etc/ssh/sshd_config

搜索关键词PermitRootLogin,若参数前有#注释则将注释去除并将参数值改为yes

 PermitRootLogin yes

搜索关键词PasswordAuthentication,若参数前有#注释则将注释去除并将参数值改为yes

PasswordAuthentication yes

编辑/etc/cloud/cloud.cfg配置文件

><fs> vi /etc/cloud/cloud.cfg
disable_root: 0
ssh_pwauth:   1

关闭防火墙

编辑/etc/selinux/config配置文件

><fs> vi /etc/selinux/config 
SELINUX=enforcing
改为
SELINUX=disabled

><fs> sh 'systemctl stop firewalld'
© 版权声明
THE END
喜欢就支持一下吧
点赞33 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容