日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

运行自定义映像。linux,安装和使用virt-customize自定义Qcow2/Raw Linux OS磁盘映像

發(fā)布時間:2024/1/18 linux 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 运行自定义映像。linux,安装和使用virt-customize自定义Qcow2/Raw Linux OS磁盘映像 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文將討論如何使用virt-customize自定義Qcow2映像,QCOW代表(QEMU Copy On Write),是QEMU處理器仿真器支持的磁盤映像格式之一,它使用磁盤存儲優(yōu)化策略,在實際需要之前延遲存儲分配,Qcow2旨在取代qcow圖像格式,這些圖像格式通常用于OpenStack Platform、KVM管理程序和oVirt/RHEV虛擬化平臺,在這篇文章中,我們將操作一些自定義Qcow圖像格式的示例,同時保持數(shù)據(jù)完整性和圖像大小的小消耗。

virt-customize簡介

virt-customize命令行工具由libguestfs-tools包提供,可用于在各種Linux發(fā)行版上安裝, Virt-customize可以通過安裝軟件包,編輯配置文件等來自定義虛擬機(磁盤映像),它通過修改guest虛擬機或磁盤映像來實現(xiàn)此目的,它適用于raw和qcow2圖像格式。

在Linux上安裝virt-customize

通過libguestfs-tools安裝virt-customize命令行工具:

1、CentOS/RHEL

$ sudo yum -y install libguestfs-tools

2、Ubuntu/Debian

$ sudo apt-get -y install libguestfs-tools

3、Arch/Manjaro

$ yaourt -S --noconfirm --needed libguestfs

通過查看幫助頁面確認安裝:

$ virt-customize --help

如果正在處理正在運行的虛擬機映像,請在進行就地編輯之前將其停止,在KVM上(在Debian 10 Buster系統(tǒng)中安裝KVM虛擬化的方法),通過以下方式執(zhí)行此操作:

sudo virsh shutdown

virt-customize使用示例

我們將介紹一些如何使用virt-customize自定義Qcow2和Raw OS圖像格式的示例。

首先,訪問集LIBGUESTFS_BACKEND:

export LIBGUESTFS_BACKEND=direct

1.設(shè)置root密碼

要設(shè)置root密碼,請使用以下命令:

# virt-customize -a rhel-server-7.6.qcow2 --root-password password:StrongRootPassword

[ ? 0.0] Examining the guest ...

[ ? 1.9] Setting a random seed

[ ? 1.9] Setting passwords

[ ? 6.8] Finishing off

注:

rhel-server-7.6.qcow2是要修改圖像的名稱。

StrongRootPassword是為root用戶設(shè)置的密碼。

2.注冊RHEL系統(tǒng)

要注冊RHEL映像并訂閱可用池,請使用以下命令:

$ virt-customize -a overcloud-full.qcow2 --run-command 'subscription-manager register --username=[username] --password=[password]'

[ ? 0.0] Examining the guest ...

[ ? 2.0] Setting a random seed

[ ? 2.0] Running: subscription-manager register --username=user1 --password=mypassword

[ ?38.5] Finishing off

$ virt-customize -a rhel-server-7.6.qcow2 --run-command 'subscription-manager attach --pool [subscription-pool]'

注:

[username]-替換為有效的用戶名,例如–username=admin。

[password]-替換為提供的用戶名的有效密碼。

-run-command選項用于執(zhí)行虛擬映像文件中的任何命令。

3.在圖像中安裝軟件包

可以使用以下命令在qcow2或原始磁盤映像中安裝軟件包:

$ virt-customize -a rhel-server-7.6.qcow2 --install [vim,bash-completion,wget,curl,telnet,unzip]

[ ? 0.0] Examining the guest ...

[ ? 2.1] Setting a random seed

[ ? 2.1] Installing packages: [vim bash-completion wget curl telnet unzip]

[ 563.2] Finishing off

$ virt-customize -a rhel-server-7.6.qcow2 --install net-tools

4.上傳文件

見下面的例子:

$ virt-customize -a rhel-server-7.6.qcow2 --upload rhsm.conf:/etc/rhsm/rhsm.conf

[ ? 0.0] Examining the guest ...

[ ? 2.9] Setting a random seed

[ ? 3.0] Setting the machine ID in /etc/machine-id

[ ? 3.0] Uploading: rhsm.conf to /etc/rhsm/rhsm.conf

[ ? 3.4] Finishing off

# virt-customize -a rhel-server-7.6.qcow2 --upload yum.conf:/etc/yum.conf

[ ? 0.0] Examining the guest ...

[ ? 1.9] Setting a random seed

[ ? 1.9] Uploading: yum.conf to /etc/yum.conf

[ ? 2.2] Finishing off

# virt-customize -a rhel-server-7.6.qcow2 --upload proxy.sh:/etc/profile.d/

[ ? 0.0] Examining the guest ...

[ ? 1.9] Setting a random seed

[ ? 1.9] Uploading: proxy.sh to /etc/profile.d/

[ ? 2.3] Finishing off

格式為:

local_file_path:image_file_path

5.設(shè)置時區(qū)

# virt-customize -a rhel-server-7.6.qcow2 --timezone "Asia/Shanghai"

6.上傳SSH公鑰

上傳用戶的SSH公鑰:

$ virt-customize -a rhel-server-7.6.qcow2 ?--ssh-inject jmutai:file:./id_rsa.pub

[ ? 0.0] Examining the guest ...

[ ? 1.9] Setting a random seed

[ ? 2.0] SSH key inject: jmutai

[ ? 3.2] Finishing off

7.Relabel SELinux

要重新標記SELinux文件上下文,請使用:

$ virt-customize -a rhel-server-7.6.qcow2 --selinux-relabel

[ ? 0.0] Examining the guest ...

[ ? 2.0] Setting a random seed

[ ? 2.0] SELinux relabelling

[ ? 8.6] Finishing off

有關(guān)更多命令用法選項,請檢查:

$ man virt-customize

$ virt-customize --help

相關(guān)主題

總結(jié)

以上是生活随笔為你收集整理的运行自定义映像。linux,安装和使用virt-customize自定义Qcow2/Raw Linux OS磁盘映像的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。