差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| linux:qemu-kvm:qemu-img [2019/01/13 16:57] – [仮想ディスクの拡張] ともやん | linux:qemu-kvm:qemu-img [2024/07/07 16:28] (現在) – [参考文献] ともやん | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== qemu-img による仮想ディスクの操作 ====== | ====== qemu-img による仮想ディスクの操作 ====== | ||
| + | |||
| + | ===== 仮想ディスクの作成 ==== | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN> | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | Formatting ' | ||
| + | </ | ||
| + | </ | ||
| ===== 仮想ディスクの容量表示 ===== | ===== 仮想ディスクの容量表示 ===== | ||
| - | <code> | + | <WRAP color_term> |
| - | $ sudo qemu-img info filename.qcow2 | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | < | + | </pre></ |
| + | <WRAP color_result> | ||
| image: filename.qcow2 | image: filename.qcow2 | ||
| file format: qcow2 | file format: qcow2 | ||
| - | virtual size: 256G (274877906944 bytes) | + | virtual size: 256 GiB (274877906944 bytes) |
| - | disk size: 188G | + | disk size: 196 KiB |
| cluster_size: | cluster_size: | ||
| Format specific information: | Format specific information: | ||
| compat: 1.1 | compat: 1.1 | ||
| + | compression type: zlib | ||
| lazy refcounts: false | lazy refcounts: false | ||
| refcount bits: 16 | refcount bits: 16 | ||
| corrupt: false | corrupt: false | ||
| - | </ | + | extended l2: false |
| + | </code></ | ||
| + | </WRAP> | ||
| ===== 仮想ディスクの拡張 ===== | ===== 仮想ディスクの拡張 ===== | ||
| - | <code> | + | <WRAP color_term> |
| - | $ sudo qemu-img resize filename.qcow2 +256G | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | < | + | </pre></ |
| + | <WRAP color_result> | ||
| Image resized. | Image resized. | ||
| - | </ | + | </ |
| + | </ | ||
| 仮想ディスクの容量確認 | 仮想ディスクの容量確認 | ||
| - | <code> | + | <WRAP color_term> |
| - | $ sudo qemu-img info filename.qcow2 | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | < | + | </pre></ |
| + | <WRAP color_result> | ||
| image: filename.qcow2 | image: filename.qcow2 | ||
| file format: qcow2 | file format: qcow2 | ||
| 行 40: | 行 58: | ||
| refcount bits: 16 | refcount bits: 16 | ||
| corrupt: false | corrupt: false | ||
| - | </ | + | </ |
| + | </ | ||
| + | |||
| + | ===== 仮想ディスクイメージの圧縮 ===== | ||
| + | 仮想ディスクイメージの圧縮 (Shrink) とは、仮想ディスクイメージ内の使われなくなった領域を開放し、イメージサイズをコンパクトにして物理ディスク領域も開放する。\\ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | 合計 30426336 | ||
| + | -rw-------. 1 root root 274920112128 12月 2 16:18 Windows_10_Pro_x64.qcow2 | ||
| + | </ | ||
| + | |||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | image: Windows_10_Pro_x64.qcow2 | ||
| + | file format: qcow2 | ||
| + | virtual size: 256 GiB (274877906944 bytes) | ||
| + | disk size: 10.7 GiB | ||
| + | cluster_size: | ||
| + | Format specific information: | ||
| + | compat: 1.1 | ||
| + | compression type: zlib | ||
| + | lazy refcounts: true | ||
| + | refcount bits: 16 | ||
| + | corrupt: false | ||
| + | extended l2: false | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== スパースファイル (sparse file) ==== | ||
| + | スパースファイル (英語: sparse file) とはファイルの一種で、部分的に空のファイルを実際のファイルシステム上で少ない消費容量で効率的に保存する仕組みである。実際にディスク上に空の領域を確保せずに、領域が空であることを示すメタデータを書きこむことで実現される。\\ | ||
| + | [[wpjp> | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | / | ||
| + | </ | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | 合計 13G | ||
| + | -rw-------. 1 root root 257G 12月 2 16:18 Windows_10_Pro_x64.qcow2 | ||
| + | -rw-------. 1 root root 257G 12月 2 16:18 fedora35_minimal.qcow2 | ||
| + | -rw-r--r--. 1 root root 1G 12月 3 00:11 filename.qcow2 | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | ファイルシス | ||
| + | devtmpfs | ||
| + | tmpfs | ||
| + | tmpfs | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | tmpfs | ||
| + | tmpfs | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | 0.0416002 ./ | ||
| + | 0.00872493 ./ | ||
| + | </ | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | image: filename.qcow2 | ||
| + | file format: qcow2 | ||
| + | virtual size: 256 GiB (274877906944 bytes) | ||
| + | disk size: 196 KiB | ||
| + | cluster_size: | ||
| + | Format specific information: | ||
| + | compat: 1.1 | ||
| + | compression type: zlib | ||
| + | lazy refcounts: false | ||
| + | refcount bits: 16 | ||
| + | corrupt: false | ||
| + | extended l2: false | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== 圧縮方法 ==== | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | 合計 30426336 | ||
| + | -rw-------. 1 root root 274920112128 12月 2 16:18 Windows_10_Pro_x64.qcow2 | ||
| + | -rw-r--r--. 1 root root 11280121856 12月 3 12:59 Windows_10_Pro_x64.qcow2_shrink | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_command>< | ||
| + | <b class=GRN>#</ | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | 合計 30426336 | ||
| + | -rw-------. 1 root root 274920112128 12月 2 16:18 Windows_10_Pro_x64.qcow2 | ||
| + | -rw-r--r--. 1 root root 11280121856 12月 3 12:59 Windows_10_Pro_x64.qcow2_shrink | ||
| + | -rw-r--r--. 1 root root | ||
| + | </ | ||
| + | </ | ||
| ===== イメージの移行 ===== | ===== イメージの移行 ===== | ||
| - | VMware の vmdk から QEMU の qcow2 形式に変換するには、以下のコマンドを実行する。\\ | + | VMware の vmdk から QEMU の qcow2 形式に変換するには、以下のコマンドを実行する。\\ |
| - | ※ qcow2 形式は必要に応じて膨らむので、実際に使われている容量のファイルができあがる。\\ | + | ※ qcow2 形式は必要に応じて膨らむので、実際に使われている容量のファイルができあがる。\\ |
| - | <code> | + | <WRAP color_term> |
| - | $ sudo qemu-img convert -O qcow2 filename.vmdk filename.qcow2 | + | <WRAP color_command>< |
| - | </code> | + | <b class=GRN> |
| - | VMware の vmdk から QEMU の qcow2 形式に変換するには、以下のコマンドを実行する。\\ | + | </pre></ |
| - | ※ qcow2 形式は必要に応じて膨らむので、実際に使われている容量のファイルができあがる。\\ | + | </WRAP> |
| - | <code> | + | |
| - | $ sudo qemu-img convert -O qcow2 filename.vmdk filename.qcow2 | + | vmdk から raw イメージに変換するには、以下のコマンドを実行する。\\ |
| - | </code> | + | ※ vmdk で定義されているディスク容量(使われていない領域を含む)の raw イメージができあがる。\\ |
| - | vmdk から raw イメージに変換するには、以下のコマンドを実行する。\\ | + | <WRAP color_term> |
| - | ※ vmdk で定義されているディスク容量(使われていない領域を含む)の raw イメージができあがる。\\ | + | <WRAP color_command>< |
| - | <code> | + | <b class=GRN> |
| - | $ sudo qemu-img convert -O raw filename.vmdk filename.img | + | </pre></ |
| - | </code> | + | </ |
| + | |||
| + | ===== Linux で qcow2 ディスクイメージをマウントする方法 ===== | ||
| + | 参考: [[https:// | ||
| + | |||
| + | ホスト上で NBD を有効にして、QCOW2 を NBD として接続する🤔\\ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | <font color="# | ||
| + | <font color="# | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | < | ||
| + | Units: sectors of 1 * 512 = 512 bytes | ||
| + | Sector size (logical/ | ||
| + | I/O size (minimum/ | ||
| + | Disklabel type: dos | ||
| + | Disk identifier: 0x4ac41c2f | ||
| + | |||
| + | < | ||
| + | /dev/nbd0p1 * 2048 206847 | ||
| + | / | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | NBD を切断する🤔\\ | ||
| + | <WRAP color_term> | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | <WRAP color_result>< | ||
| + | /dev/nbd0 disconnected | ||
| + | </ | ||
| + | <WRAP color_command>< | ||
| + | <font color="# | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== 参考文献 ===== | ||
| + | [[https:// | ||
| + | [[https:// | ||
| + | [[https:// | ||
| + | [[https:// | ||
| + | [[https:// | ||
| + | |||
| + | ==== 付録 ==== | ||
| + | [[tw> | ||
| + | [[tw> | ||