2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

qcow2ファイルをvirtualbox用にvdi変換

Last updated at Posted at 2017-11-05

▼はじめに

■やりたいこと

linux環境だけでqcow2ファイルをvdiファイルへ変換する

■やったこと

linux環境にvirtualboxをインストールしてファイル変換した

■背景

研修用の教材でqcow2を用いて環境を構築する必要があった。
ただ、qcow2のためそれ用の環境を用意する必要が有るが諸事情でvirtualboxを用いてそのqcow2を使いたい。
virtualboxで使用できるのはqcow2ではなくvdi形式のためqcow2ファイルからvdiファイルへ変換して環境を構築しよう

■参考

Linuxだからできないなんて言わないよ- KVM-QEMU用イメージqcow2からVirtualBox用イメージvdiに変換

■実行環境

  • server:conoha vps 2GB-3CPU
  • OS:centOS 7
[root@host-150-95-134-215 ~]# uname -a
Linux host-150-95-134-215 3.10.0-514.21.1.el7.x86_64 #1 SMP Thu May 25 17:04:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@host-150-95-134-215 ~]#

▼手順

・ファイル配置

変換したいファイルをlinux環境へ配置する

・virtualboxのrepository登録

curl http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -o /etc/yum.repos.d/virtualbox.repo

・virtualboxパッケージインストール

yum install VirtualBox-5.2.x86_64

・qcow2 ⇒ vdiファイル変換

VBoxManage convertdd [変換元qcow2ファイル名] [変換後vdiファイル名]

実行結果

[root@host-150-95-134-215 opcel-images]# curl http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -o /etc/yum.repos.d/virtualbox.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   259  100   259    0     0   1639      0 --:--:-- --:--:-- --:--:--  1649
[root@host-150-95-134-215 opcel-images]#
[root@host-150-95-134-215 opcel-images]# yum search virtualbox
Loaded plugins: fastestmirror, langpacks
virtualbox/7/x86_64/signature                                                                                                                                                                                                                   |  181 B  00:00:00
Retrieving key from https://www.virtualbox.org/download/oracle_vbox.asc
Importing GPG key 0x98AB5139:
 Userid     : "Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>"
 Fingerprint: 7b0f ab3a 13b9 0743 5925 d9c9 5442 2a4b 98ab 5139
 From       : https://www.virtualbox.org/download/oracle_vbox.asc
Is this ok [y/N]: y
virtualbox/7/x86_64/signature                                                                                                                                                                                                                   | 1.1 kB  00:00:20 !!!
virtualbox/7/x86_64/primary                                                                                                                                                                                                                     | 8.7 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.kddilabs.jp
 * epel-debuginfo: www.ftp.ne.jp
 * epel-source: ftp.kddilabs.jp
 * extras: ftp.iij.ad.jp
 * ius: mirrors.tuna.tsinghua.edu.cn
 * updates: ftp.iij.ad.jp
virtualbox                                                                                                                                                                                                                                                       44/44
======================================================================================================================= N/S matched: virtualbox =======================================================================================================================
VirtualBox-4.3.x86_64 : Oracle VM VirtualBox
VirtualBox-5.0.x86_64 : Oracle VM VirtualBox
VirtualBox-5.1.x86_64 : Oracle VM VirtualBox
VirtualBox-5.2.x86_64 : Oracle VM VirtualBox

  Name and summary matches only, use "search all" for everything.
[root@host-150-95-134-215 opcel-images]#

[root@host-150-95-134-215 opcel-images]# yum install VirtualBox-5.2.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.kddilabs.jp
 * epel-debuginfo: www.ftp.ne.jp
 * epel-source: ftp.kddilabs.jp
 * extras: ftp.iij.ad.jp
 * ius: mirrors.tuna.tsinghua.edu.cn
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package VirtualBox-5.2.x86_64 0:5.2.0_118431_el7-1 will be installed
--> Processing Dependency: libXt.so.6()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Processing Dependency: libGL.so.1()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Processing Dependency: libXinerama.so.1()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Processing Dependency: libXmu.so.6()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Processing Dependency: libSDL-1.2.so.0()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Processing Dependency: libXcursor.so.1()(64bit) for package: VirtualBox-5.2-5.2.0_118431_el7-1.x86_64
--> Running transaction check
---> Package SDL.x86_64 0:1.2.15-14.el7 will be installed
---> Package libXcursor.x86_64 0:1.1.14-8.el7 will be installed
--> Processing Dependency: libXfixes.so.3()(64bit) for package: libXcursor-1.1.14-8.el7.x86_64
---> Package libXinerama.x86_64 0:1.1.3-2.1.el7 will be installed
---> Package libXmu.x86_64 0:1.1.2-2.el7 will be installed
---> Package libXt.x86_64 0:1.1.5-3.el7 will be installed
---> Package mesa-libGL.x86_64 0:17.0.1-6.20170307.el7 will be installed
--> Processing Dependency: mesa-libglapi = 17.0.1-6.20170307.el7 for package: mesa-libGL-17.0.1-6.20170307.el7.x86_64
--> Processing Dependency: libxshmfence.so.1()(64bit) for package: mesa-libGL-17.0.1-6.20170307.el7.x86_64
--> Processing Dependency: libglapi.so.0()(64bit) for package: mesa-libGL-17.0.1-6.20170307.el7.x86_64
--> Processing Dependency: libXxf86vm.so.1()(64bit) for package: mesa-libGL-17.0.1-6.20170307.el7.x86_64
--> Processing Dependency: libXdamage.so.1()(64bit) for package: mesa-libGL-17.0.1-6.20170307.el7.x86_64
--> Running transaction check
---> Package libXdamage.x86_64 0:1.1.4-4.1.el7 will be installed
---> Package libXfixes.x86_64 0:5.0.3-1.el7 will be installed
---> Package libXxf86vm.x86_64 0:1.1.4-1.el7 will be installed
---> Package libxshmfence.x86_64 0:1.2-1.el7 will be installed
---> Package mesa-libglapi.x86_64 0:17.0.1-6.20170307.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================================================================================================================
 Package                                                          Arch                                                     Version                                                                  Repository                                                    Size
=======================================================================================================================================================================================================================================================================
Installing:
 VirtualBox-5.2                                                   x86_64                                                   5.2.0_118431_el7-1                                                       virtualbox                                                    77 M
Installing for dependencies:
 SDL                                                              x86_64                                                   1.2.15-14.el7                                                            base                                                         204 k
 libXcursor                                                       x86_64                                                   1.1.14-8.el7                                                             base                                                          30 k
 libXdamage                                                       x86_64                                                   1.1.4-4.1.el7                                                            base                                                          20 k
 libXfixes                                                        x86_64                                                   5.0.3-1.el7                                                              base                                                          18 k
 libXinerama                                                      x86_64                                                   1.1.3-2.1.el7                                                            base                                                          14 k
 libXmu                                                           x86_64                                                   1.1.2-2.el7                                                              base                                                          71 k
 libXt                                                            x86_64                                                   1.1.5-3.el7                                                              base                                                         173 k
 libXxf86vm                                                       x86_64                                                   1.1.4-1.el7                                                              base                                                          18 k
 libxshmfence                                                     x86_64                                                   1.2-1.el7                                                                base                                                         7.2 k
 mesa-libGL                                                       x86_64                                                   17.0.1-6.20170307.el7                                                    base                                                         155 k
 mesa-libglapi                                                    x86_64                                                   17.0.1-6.20170307.el7                                                    base                                                          41 k

Transaction Summary
=======================================================================================================================================================================================================================================================================
Install  1 Package (+11 Dependent packages)

Total download size: 78 M
Installed size: 176 M
Is this ok [y/d/N]: y
Downloading packages:
(1/12): SDL-1.2.15-14.el7.x86_64.rpm                                                                                                                                                                                                            | 204 kB  00:00:00
(2/12): libXdamage-1.1.4-4.1.el7.x86_64.rpm                                                                                                                                                                                                     |  20 kB  00:00:00
(3/12): libXcursor-1.1.14-8.el7.x86_64.rpm                                                                                                                                                                                                      |  30 kB  00:00:00
(4/12): libXinerama-1.1.3-2.1.el7.x86_64.rpm                                                                                                                                                                                                    |  14 kB  00:00:00
(5/12): libXxf86vm-1.1.4-1.el7.x86_64.rpm                                                                                                                                                                                                       |  18 kB  00:00:00
(6/12): libXfixes-5.0.3-1.el7.x86_64.rpm                                                                                                                                                                                                        |  18 kB  00:00:00
(7/12): libxshmfence-1.2-1.el7.x86_64.rpm                                                                                                                                                                                                       | 7.2 kB  00:00:00
(8/12): mesa-libglapi-17.0.1-6.20170307.el7.x86_64.rpm                                                                                                                                                                                          |  41 kB  00:00:00
(9/12): libXt-1.1.5-3.el7.x86_64.rpm                                                                                                                                                                                                            | 173 kB  00:00:00
(10/12): mesa-libGL-17.0.1-6.20170307.el7.x86_64.rpm                                                                                                                                                                                            | 155 kB  00:00:00
(11/12): libXmu-1.1.2-2.el7.x86_64.rpm                                                                                                                                                                                                          |  71 kB  00:00:00
warning: /var/cache/yum/x86_64/7/virtualbox/packages/VirtualBox-5.2-5.2.0_118431_el7-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY===========================================================================   ] 8.9 MB/s |  76 MB  00:00:00 ETA
Public key for VirtualBox-5.2-5.2.0_118431_el7-1.x86_64.rpm is not installed
(12/12): VirtualBox-5.2-5.2.0_118431_el7-1.x86_64.rpm                                                                                                                                                                                           |  77 MB  00:00:07
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                  9.9 MB/s |  78 MB  00:00:07
Retrieving key from https://www.virtualbox.org/download/oracle_vbox.asc
Importing GPG key 0x98AB5139:
 Userid     : "Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>"
 Fingerprint: 7b0f ab3a 13b9 0743 5925 d9c9 5442 2a4b 98ab 5139
 From       : https://www.virtualbox.org/download/oracle_vbox.asc
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libXfixes-5.0.3-1.el7.x86_64                                                                                                                                                                                                                       1/12
  Installing : libXt-1.1.5-3.el7.x86_64                                                                                                                                                                                                                           2/12
  Installing : libXmu-1.1.2-2.el7.x86_64                                                                                                                                                                                                                          3/12
  Installing : libXcursor-1.1.14-8.el7.x86_64                                                                                                                                                                                                                     4/12
  Installing : libXdamage-1.1.4-4.1.el7.x86_64                                                                                                                                                                                                                    5/12
  Installing : mesa-libglapi-17.0.1-6.20170307.el7.x86_64                                                                                                                                                                                                         6/12
  Installing : SDL-1.2.15-14.el7.x86_64                                                                                                                                                                                                                           7/12
  Installing : libXxf86vm-1.1.4-1.el7.x86_64                                                                                                                                                                                                                      8/12
  Installing : libXinerama-1.1.3-2.1.el7.x86_64                                                                                                                                                                                                                   9/12
  Installing : libxshmfence-1.2-1.el7.x86_64                                                                                                                                                                                                                     10/12
  Installing : mesa-libGL-17.0.1-6.20170307.el7.x86_64                                                                                                                                                                                                           11/12
  Installing : VirtualBox-5.2-5.2.0_118431_el7-1.x86_64                                                                                                                                                                                                          12/12

Creating group 'vboxusers'. VM users must be member of that group!

This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-514.21.1.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-514.21.1.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.
  Verifying  : libxshmfence-1.2-1.el7.x86_64                                                                                                                                                                                                                      1/12
  Verifying  : libXinerama-1.1.3-2.1.el7.x86_64                                                                                                                                                                                                                   2/12
  Verifying  : mesa-libGL-17.0.1-6.20170307.el7.x86_64                                                                                                                                                                                                            3/12
  Verifying  : libXcursor-1.1.14-8.el7.x86_64                                                                                                                                                                                                                     4/12
  Verifying  : libXfixes-5.0.3-1.el7.x86_64                                                                                                                                                                                                                       5/12
  Verifying  : libXxf86vm-1.1.4-1.el7.x86_64                                                                                                                                                                                                                      6/12
  Verifying  : SDL-1.2.15-14.el7.x86_64                                                                                                                                                                                                                           7/12
  Verifying  : libXmu-1.1.2-2.el7.x86_64                                                                                                                                                                                                                          8/12
  Verifying  : mesa-libglapi-17.0.1-6.20170307.el7.x86_64                                                                                                                                                                                                         9/12
  Verifying  : libXdamage-1.1.4-4.1.el7.x86_64                                                                                                                                                                                                                   10/12
  Verifying  : VirtualBox-5.2-5.2.0_118431_el7-1.x86_64                                                                                                                                                                                                          11/12
  Verifying  : libXt-1.1.5-3.el7.x86_64                                                                                                                                                                                                                          12/12

Installed:
  VirtualBox-5.2.x86_64 0:5.2.0_118431_el7-1

Dependency Installed:
  SDL.x86_64 0:1.2.15-14.el7        libXcursor.x86_64 0:1.1.14-8.el7   libXdamage.x86_64 0:1.1.4-4.1.el7           libXfixes.x86_64 0:5.0.3-1.el7                 libXinerama.x86_64 0:1.1.3-2.1.el7   libXmu.x86_64 0:1.1.2-2.el7   libXt.x86_64 0:1.1.5-3.el7
  libXxf86vm.x86_64 0:1.1.4-1.el7   libxshmfence.x86_64 0:1.2-1.el7    mesa-libGL.x86_64 0:17.0.1-6.20170307.el7   mesa-libglapi.x86_64 0:17.0.1-6.20170307.el7

Complete!
[root@host-150-95-134-215 opcel-images]#

[root@host-150-95-134-215 opcel-vol2]# VBoxManage convertdd 1_centos7_c_n.qcow2 1_centos7_c_n.vdi
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (3.10.0-514.21.1.el7.x86_64) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /sbin/vboxconfig

         You will not be able to start VMs until this problem is fixed.
Converting from raw image file="1_centos7_c_n.qcow2" to file="1_centos7_c_n.vdi"...
Creating dynamic image with size 4935122944 bytes (4707MB)...
[root@host-150-95-134-215 opcel-vol2]#
[root@host-150-95-134-215 opcel-vol2]# ls -lrta 1_centos7_c_n.vdi
-rw------- 1 root root 4302307328 Nov  5 11:33 1_centos7_c_n.vdi
[root@host-150-95-134-215 opcel-vol2]# ls -lrtah 1_centos7_c_n.vdi
-rw------- 1 root root 4.1G Nov  5 11:33 1_centos7_c_n.vdi
[root@host-150-95-134-215 opcel-vol2]#
2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?