使用云镜像 Centos7 镜像模板命令初始化
  mPcyh9OXzYGu 2023年11月02日 73 0


安装kvm 镜像工具套装 

CentOS-7-x86_64-GenericCloud-2111.qcow2


apt install -y libguestfs-tools

yum install -y libguestfs-tools libguestfs-winsupport guestfish


  • debian11
#!/bin/bash


export IMAGE_NAME=debian-11-nocloud-amd64.qcow2

cat>sources.list<<EOF
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
EOF

virt-customize  --hostname "debian-11-tpl.dh.local" \
               --ssh-inject root:file:/var/lib/vz/template/key/dh_id_rsa.pub  \
               --root-password password:Kuberneter@50W \
               --upload ./sources.list:/etc/apt/sources.list \
               --install cloud-init,htop,vim,qemu-guest-agent,curl,wget,bash-completion,net-tools,axel \
               --timezone "Asia/Shanghai" \
               --run-command "systemctl stop postfix rpcbind.socket"  \
               --run-command "rm -f /etc/machine-id /var/lib/dbus/machine-id "  \
               --run-command "systemd-machine-id-setup "  \
               --firstboot-command "dpkg-reconfigure openssh-server" \
               --delete '/var/log/*.log'. -a ${IMAGE_NAME}
virt-sysprep --enable machine-id,logfiles   -a ${IMAGE_NAME}


  • Centos7.9
#!/bin/env bash
set -e

image_name=CentOS-7-x86_64-GenericCloud-2111.qcow2
virt-customize -a $image_name  --selinux-relabel  --timezone "Asia/Shanghai" \
--run-command "sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config" \
--run-command "sed -i s/#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config" \
--ssh-inject root:file:/var/lib/vz/template/key/dh_id_rsa.pub  \
--root-password password:Kuberneter@50W \
--run-command "yum update -y" \
--install net-tools,wget,vim,unzip,qemu-guest-agent,jq,bash-completion,yum-utils,device-mapper-persistent-data,lvm2,openssl,socat,conntrack,ebtables,ipset,sysstat,iotop,iftop,nload,bridge-utils,bash-completion,bind-utils,nc,binutils,iscsi-initiator-utils,kmod-xfs,xfsprogs,sg3_utils-devel.x86_64,sg3_utils-libs.x86_64,sg3_utils.x86_64,psmisc \
--run-command 'yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo' \
--run-command 'yum install docker-ce -y' \
--run-command 'systemctl enable docker' \
--append-line '/etc/profile:KKZONE=cn' \
--run-command 'mkdir -p /etc/docker' \
--upload ./daemon.json:/etc/docker/daemon.json \
--run-command 'systemctl enable qemu-guest-agent' \
--append-line '/etc/profile:alias vi=vim' \
--append-line '/etc/profile:unset MAILCHECK' \
--run-command 'rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org' \
--run-command 'rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm' \
--run-command 'yum --enablerepo=elrepo-kernel install kernel-lt -y' \
--run-command 'grub2-set-default 0' \
--run-command 'grub2-mkconfig -o /boot/grub2/grub.cfg' \
--run-command 'yum clean all'

virt-sysprep  --selinux-relabel --enable machine-id,logfiles   -a ${image_name}

使用云镜像  Centos7 镜像模板命令初始化_Windows

  相关命令大致意思,需要使用看帮助文档或者搜索

guestfish interactive shell  挂载镜像,并提供一个交互的shell。

guestmount mount guest filesystem in hos 将镜像挂载到指定的目录。

guestumount unmount guest filesystem 卸载镜像目录。

virt-alignment-scan 镜像块对齐扫描。

virt-builder ― quick image builder 快速镜像创建。

virt-cat(1) ― display a file 显示镜像中文件内容。

virt-copy-in(1) ― copy files and directories into a VM 拷贝文件到镜像内部。

virt-copy-out(1) ― copy files and directories out of a VM 拷贝镜像文件出来。

virt-customize(1) ― customize virtual machines 定制虚拟机镜像

virt-df(1) ― free space 查看虚拟机镜像空间使用情况。

virt-diff(1) ― differences 不启动虚拟机的情况下,比较虚拟机内部两份文件差别。

virt-edit(1) ― edit a file 编辑虚拟机内部文件。

virt-filesystems(1) ― display information about filesystems, devices, LVM 显示镜像文件系统信息。

virt-format(1) ― erase and make blank disks 格式化镜像内部磁盘。

virt-inspector(1) ― inspect VM images 镜像信息测试。

virt-list-filesystems(1) ― list filesystems 列出镜像文件系统。

virt-list-partitions(1) ― list partitions 列出镜像分区信息。

virt-log(1) ― display log files 显示镜像日志。

virt-ls(1) ― list files 列出镜像文件。

virt-make-fs(1) ― make a filesystem 镜像中创建文件系统。

virt-p2v(1) ― convert physical machine to run on KVM 物理机转虚拟机。

virt-p2v-make-disk(1) ― make P2V ISO 创建物理机转虚拟机ISO光盘。

virt-p2v-make-kickstart(1) ― make P2V kickstart 创建物理机转虚拟机kickstart文件。

virt-rescue(1) ― rescue shell 进去虚拟机救援模式。

virt-resize(1) ― resize virtual machines 虚拟机分区大小修改。

virt-sparsify(1) ― make virtual machines sparse (thin-provisioned) 镜像稀疏空洞消除。

virt-sysprep(1) ― unconfigure a virtual machine before cloning 镜像初始化。

virt-tar(1) ― archive and upload files 文件打包并传入传出镜像。

virt-tar-in(1) ― archive and upload files 文件打包并传入镜像。

virt-tar-out(1) ― archive and download files 文件打包并传出镜像。

virt-v2v(1) ― convert guest to run on KVM 其他格式虚拟机镜像转KVM镜像。

virt-win-reg(1) ― export and merge Windows Registry keys windows注册表导入镜像。

libguestfs-test-tool(1) ― test libguestfs 测试libguestfs

libguestfs-make-fixed-appliance(1) ― make libguestfs fixed appliance

hivex(3) ― extract Windows Registry hive 解压windows注册表文件。

hivexregedit(1) ― merge and export Registry changes from regedit-format files 合并、并导出注册表文件内容。

hivexsh(1) ― Windows Registry hive shell window注册表修改交互的shell。

hivexml(1) ― convert Windows Registry hive to XML 将window注册表转化为xml

hivexget(1) ― extract data from Windows Registry hive 得到注册表键值。

guestfsd(8) ― guestfs daemon guestfs服务。
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  wwLZeziuqjLR   2023年12月11日   31   0   0 Dockercentos
  MCWYWqSAMsot   2023年12月11日   33   0   0 Docker
  DnoStTHsc0vp   2023年12月11日   25   0   0 Docker
  wwLZeziuqjLR   2023年12月08日   100   0   0 Dockercentosbash
  wwLZeziuqjLR   2023年12月07日   34   0   0 Dockercentos
mPcyh9OXzYGu