# Export Image

## Prerequisite

* ต้องมี image อยู่ใน project

## Instructions

สามารถ export image ได้จากบน Windows OS และ Linux OS โดยดำเนินการตามขั้นตอนด้านล่าง

### **หากต้องการ export ด้วย Windows OS สามารถดำเนินการได้ตามด้านล่าง**

1. Download & Install Python

   &#x20;

   สามารถ Download Python ได้จาก link <https://www.python.org/ftp/python/3.13.3/python-3.13.3-amd64.exe> เลือก Add python.exe to PATH และ กด Install Now

   &#x20;

   ![](https://t9003005656.p.clickup-attachments.com/t9003005656/3d4c4f1b-c19d-473d-8e11-cfdb991525f7/image.png)

   &#x20;
2. ทดสอบ python ใช้งานได้ปกติหรือไม่ โดยเปิด cmd และใช้ command ดังนี้

```
C:\Users\OhmzPC>python --version
Python 3.13.3
```

3. สร้าง venv เพื่อใช้งานสำหรับ openstack client

```
C:\Users\OhmzPC>cd Documents

C:\Users\OhmzPC\Documents>mkdir Export_Image

C:\Users\OhmzPC\Documents>cd Export_Image

C:\Users\OhmzPC\Documents\Export_Image>python -m venv osclient

C:\Users\OhmzPC\Documents\Export_Image>osclient\Scripts\activate

(osclient) C:\Users\OhmzPC\Documents\Export_Image>pip install --upgrade pip
Requirement already satisfied: pip in c:\users\ohmzpc\documents\export_image\osclient\lib\site-packages (25.0.1)

(osclient) C:\Users\OhmzPC\Documents\Export_Image>pip install python-openstackclient

(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack --version
openstack 8.0.0
```

4. Setting Public API RC File

<figure><img src="/files/x6n7AIjl4h3Tsru7cISm" alt=""><figcaption></figcaption></figure>

5. แก้ไข test\_project\_RC\_file.sh เป็น test\_project\_RC\_file.bat ดังนี้

> แก้จาก #!/usr/bin/env bash เป็น @echo off
>
> แก้จาก # เป็น rem
>
> แก้จาก export เป็น set
>
> แก้จาก if \[ -z "$\<Variable>" ]; then unset \<Variable>; fi เป็น if "%\<Variable>%"=="" set \<Variable>=
>
> ตัวอย่าง
>
> if \[ -z "$OS\_USER\_DOMAIN\_NAME" ]; then unset OS\_USER\_DOMAIN\_NAME; fi เป็น
>
> if "%OS\_USER\_DOMAIN\_NAME%"=="" set OS\_USER\_DOMAIN\_NAME=
>
> แก้จาก read -sr OS\_PASSWORD\_INPUT เป็น set /p OS\_PASSWORD\_INPUT=

(osclient) C:\Users\OhmzPC\Documents\Export\_Image>notepad test\_project\_RC\_file.sh

```
#!/usr/bin/env bash
# To use NIPA Cloud Space public API you need to authenticate against the Identity
# service named keystone, which returns a **Token** and **Service Catalog**.
# The catalog contains the endpoints for all services the user/project has
# access to - such as Compute Instance, Compute Image, Block Storage, Networking.

export OS_AUTH_URL=https://identity-api.nipa.cloud/
# Co-working project identity
export OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
export OS_PROJECT_NAME="test_project"
export OS_USER_DOMAIN_NAME="nipacloud"
if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi
export OS_PROJECT_DOMAIN_ID="c6b00adf4ed04fc5a958121fadb0e401"
if [ -z "$OS_PROJECT_DOMAIN_ID" ]; then unset OS_PROJECT_DOMAIN_ID; fi
# unset v2.0 items in case set
unset OS_TENANT_ID
unset OS_TENANT_NAME
# performing the action as the **user**.
export OS_USERNAME="test_user@nipa.cloud"
echo "Please enter your NIPA Cloud Space user's password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
# NIPA Cloud Space only have 1 region "NCP-TH"
export OS_REGION_NAME="NCP-TH"
# Don't leave a blank variable, unset it if it was empty
if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
```

แก้เป็น (osclient) C:\Users\OhmzPC\Documents\Export\_Image>notepad test\_project\_RC\_file.batฃ

```
@echo off
rem To use NIPA Cloud Space public API you need to authenticate against the Identity
rem service named keystone, which returns a **Token** and **Service Catalog**.
rem The catalog contains the endpoints for all services the user/project has
rem access to - such as Compute Instance, Compute Image, Block Storage, Networking.

set OS_AUTH_URL=https://identity-api.nipa.cloud/
rem Co-working project identity
set OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
set OS_PROJECT_NAME=test_project
set OS_USER_DOMAIN_NAME=nipacloud
if "%OS_USER_DOMAIN_NAME%"=="" set OS_USER_DOMAIN_NAME=
set OS_PROJECT_DOMAIN_ID=c6b00adf4ed04fc5a958121fadb0e401
if "%OS_PROJECT_DOMAIN_ID%"=="" set OS_PROJECT_DOMAIN_ID=
rem unset v2.0 items in case set
set OS_TENANT_ID=
set OS_TENANT_NAME=
rem performing the action as the **user**.
set OS_USERNAME=test_user@nipa.cloud
echo Please enter your NIPA Cloud Space user's password for project %OS_PROJECT_NAME% as user %OS_USERNAME%:
set /p OS_PASSWORD_INPUT= 
set OS_PASSWORD=%OS_PASSWORD_INPUT%
rem NIPA Cloud Space only have 1 region "NCP-TH"
set OS_REGION_NAME=NCP-TH
rem Don't leave a blank variable, unset it if it was empty
if "%OS_REGION_NAME%"=="" set OS_REGION_NAME=
set OS_INTERFACE=public
set OS_IDENTITY_API_VERSION=3
```

6. รันไฟล์ test\_project\_RC\_file.bat และ check ว่า สามารถใช้ openstack client ใน project ได้หรือไม่

```
(osclient) C:\Users\OhmzPC\Documents\Export_Image>test_project_RC_file.bat
Please enter your NIPA Cloud Space user's password for project test_project as user test_user@nipa.cloud: <ใส่ password>
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                                                                   |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires    | 2025-04-26T03:59:41+0000                                                                                                                                                                |
| id         | gAAAAABoCwithNSV3tPsaDzi54VvrSxIz6V9rreRJBurlVV2e4Ii5aolilEBRWtUnargn4iKPu8ru-Rt0XqXJl3HHs1x5ZzmH-oM-XQoFRRi7ov_ofiuhryudjdbvSmKHX7d0ZsrEOIvrbCkAqH4gnPNlpsbNc6dnnY5P1s5vmqDrXsOAOB9ywY |
| project_id | 834995e704b44fa888b7xxxxxxxxxxxx                                                                                                                                                     |
| user_id    | e6275119d15648bfb7c2xxxxxxxxxxxx                                                                                                                                                        |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

7. list image ใน project ด้วย command

```
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image list
+--------------------------------------+--------------------------------------+--------+
| ID                                   | Name                                 | Status |
+--------------------------------------+--------------------------------------+--------+
| d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx | ubuntu-24-v250307                    | active |
+--------------------------------------+--------------------------------------+--------+
```

8. download image ใน project ด้วย command

```
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image save --file <ชื่อ file image>.qcow2 <image_ID>

ตัวอย่าง
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image save --file ubuntu-24-v250307.qcow2 d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx
```

9. ถ้า download เรียบร้อยแล้วจะได้ไฟล์ image

```
(osclient) C:\Users\OhmzPC\Documents\Export_Image>dir
 Volume in drive C is Windows
 Volume Serial Number is XXXX-XXXX

 Directory of C:\Users\OhmzPC\Documents\Export_Image

04/25/2025  11:08 AM    <DIR>          .
04/25/2025  10:43 AM    <DIR>          ..
04/25/2025  10:57 AM             1,270 test_project_RC_file.bat
04/25/2025  10:49 AM             1,343 test_project_RC_file.sh
04/25/2025  10:51 AM    <DIR>          osclient
04/25/2025  11:09 AM     1,243,992,064 ubuntu-24-v250307.qcow2
               3 File(s)  1,243,994,677 bytes
               3 Dir(s)  326,236,172,288 bytes free
```

###

### **หากต้องการ export ด้วย Linux สามารถดำเนินการได้ตามด้านล่าง**

#### สำหรับ Mac OS ให้เตรียม environment ตามด้านล่าง

1. Download & Install Python

&#x20;      1.1 ติดตั้ง Homebrew (หากยังไม่ได้ติดตั้ง)

```
$ /bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"
```

&#x20;      1.2 ติดตั้ง Python ผ่าน Homebrew

```
$ brew update
$ brew install python3
```

&#x20;      1.3 ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

```
$ python3 --version
Python 3.12.3
```

2. สร้าง venv เพื่อใช้งานสำหรับ openstack client

```
$ cd ~/
$ python3 -m venv osclient
$ source osclient/bin/activate
(osclient) $ pip install --upgrade pip
(osclient) $ pip install python-openstackclient
(osclient) $ openstack --version
openstack 8.0.0
```

#### สำหรับ Ubuntu/Debian ให้เตรียม environment ตามด้านล่าง

1. Download & Install Python

```
root@test-export-image:~# apt update -y
root@test-export-image:~# apt install -y python3 python3-pip python3-venv
```

2. ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

```
root@test-export-image:~# python3 --version
Python 3.12.3
```

3. สร้าง venv เพื่อใช้งานสำหรับ openstack client

```
root@test-export-image:~# mkdir /opt/osclient
root@test-export-image:~# cd /opt/osclient/
root@test-export-image:/opt/osclient# python3 -m venv osclient
root@test-export-image:/opt/osclient# source /opt/osclient/osclient/bin/activate
(osclient) root@test-export-image:/opt/osclient# pip install --upgrade pip
(osclient) root@test-export-image:/opt/osclient# pip install python-openstackclient
(osclient) root@test-export-image:/opt/osclient# openstack --version
openstack 8.0.0
```

#### สำหรับ Rocky/AlmaLinux ให้เตรียม environment ตามด้านล่าง

1. Download & Install Python

```
[root@test-export-image ~]# yum update -y
[root@test-export-image ~]# yum install -y python3 python3-pip python3-virtualenv
```

2. ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

```
[root@test-export-image ~]# python3 --version
Python 3.12.3
```

3. สร้าง venv เพื่อใช้งานสำหรับ openstack client

```
[root@test-export-image ~]# mkdir /opt/osclient
[root@test-export-image ~]# cd /opt/osclient/
[root@test-export-image osclient]# python3 -m venv osclient
[root@test-export-image osclient]# source /opt/osclient/osclient/bin/activate
(osclient) [root@test-export-image osclient]# pip install --upgrade pip
(osclient) [root@test-export-image osclient]# pip install python-openstackclient
(osclient) [root@test-export-image osclient]# openstack --version
openstack 8.0.0
```

#### หลังจากเตรียม environment สำหรับแต่ละ OS เรียบร้อยแล้ว ให้ดำเนินการตามขั้นตอนด้านล่างต่อไป

1. Download Public API RC File โดย download จากหน้า project บน Nipa Cloud Space

<figure><img src="/files/7th7Oc4qEDLjzxt3rn6T" alt=""><figcaption></figcaption></figure>

2. ตรวจสอบ RC\_file.sh

```
(osclient) root@test-export-image:/opt/osclient# vim test_project_RC_file.sh
#!/usr/bin/env bash
# To use NIPA Cloud Space public API you need to authenticate against the Identity
# service named keystone, which returns a **Token** and **Service Catalog**.
# The catalog contains the endpoints for all services the user/project has
# access to - such as Compute Instance, Compute Image, Block Storage, Networking.

export OS_AUTH_URL=https://identity-api.nipa.cloud/
# Co-working project identity
export OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
export OS_PROJECT_NAME="test_project"
export OS_USER_DOMAIN_NAME="nipacloud"
if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi
export OS_PROJECT_DOMAIN_ID="c6b00adf4ed04fc5a958121fadb0e401"
if [ -z "$OS_PROJECT_DOMAIN_ID" ]; then unset OS_PROJECT_DOMAIN_ID; fi
# unset v2.0 items in case set
unset OS_TENANT_ID
unset OS_TENANT_NAME
# performing the action as the **user**.
export OS_USERNAME="test_user@nipa.cloud"
echo "Please enter your NIPA Cloud Space user's password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
# NIPA Cloud Space only have 1 region "NCP-TH"
export OS_REGION_NAME="NCP-TH"
# Don't leave a blank variable, unset it if it was empty
if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi
export OS_INTERFACE=public
export OS_IDENTITY_API_VERSION=3
```

3. source ไฟล์ test\_project\_RC\_file.sh และ check ว่า สามารถใช้ openstack client ใน project ได้หรือไม่

```
(osclient) root@test-export-image:/opt/osclient# source test_project_RC_file.sh
Please enter your NIPA Cloud Space user's password for project test_project as user test_user@nipa.cloud:<ใส่ password>
(osclient) root@test-export-image:/opt/osclient# openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                                                                   |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires    | 2025-04-26T04:36:06+0000                                                                                                                                                                |
| id         | gAAAAABoCxE24s4f-T2MOyOFsLcfGWvbf1zwQBZfwC3KcqiKSpod1OuDJa3xdWaBvtMui7w9Hr3B0OHkQYx8u1aQYKodxhyKSLIcazwG1JbwAbt-Vgx8KAcU5zWQGAkPoOUmWuyNFW0ZkzONKU0HOmISAr8DM1bErVjWL7Il595Xmzmjr_889Uo |
| project_id | 834995e704b44fa888b7xxxxxxxxxxxx                                                                                                                                                        |
| user_id    | e6275119d15648bfb7c2xxxxxxxxxxxx                                                                                                                                                        |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
(osclient) root@test-export-image:/opt/osclient#
```

4. list image ใน project ด้วย command

```
(osclient) root@test-export-image:/opt/osclient# openstack image list
+--------------------------------------+--------------------------------------+--------+
| ID                                   | Name                                 | Status |
+--------------------------------------+--------------------------------------+--------+
| d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx | ubuntu-24-v250307                    | active |
+--------------------------------------+--------------------------------------+--------+
```

5. download image ที่ต้องการใน project ด้วย command

```
(osclient) root@test-export-image:/opt/osclient# openstack image save --file <ชื่อ file image> <image_ID>

ตัวอย่าง
(osclient) root@test-export-image:/opt/osclient# openstack image save --file ubuntu-24-v250307.qcow2 d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx
```

6. ถ้า download เรียบร้อยแล้วจะได้ไฟล์ image

```
(osclient) root@test-export-image:/opt/osclient# ls -lh
total 1.2G
-rw-r--r-- 1 root root 1.4K Apr 25 11:31 test_project_RC_file.sh
drwxr-xr-x 5 root root 4.0K Apr 25 11:26 osclient
-rw-r--r-- 1 root root 1.2G Apr 25 11:38 ubuntu-24-v250307.qcow2
(osclient) root@test-export-image:/opt/osclient#
```

#### &#x20;สำหร้บการแปลงไฟล์จาก qcow2 ไปยังรูปแบบอื่นๆ สามารถใช้เครื่องมือ qemu-img ในการแปลงไฟล์ในรูปแบบอื่น เช่น VMDK, VHD, OVA หรือ OVF ได้

#### 1. qemu-img (เครื่องมือหลักสำหรับ Block Image)

เป็นเครื่องมือ Command-line ที่มาพร้อมกับ QEMU/KVM รองรับการแปลงไฟล์แบบ Direct conversion ได้เกือบทุกตระกูล

วิธีการใช้งาน (Syntax):

ใช้คำสั่ง qemu-img convert ตามด้วยฟอร์แมตต้นทางและปลายทาง:

แปลงเป็น VMDK (สำหรับ VMware):

```
qemu-img convert -f qcow2 -O vmdk input.qcow2 output.vmdk
```

แปลงเป็น VHD (สำหรับ Hyper-V / Azure):

```
qemu-img convert -f qcow2 -O vpc input.qcow2 output.vhd
```

แปลงเป็น VHDX (สำหรับ Hyper-V รุ่นใหม่):

```
qemu-img convert -f qcow2 -O vhdx input.qcow2 output.vhdx
```

#### 2. การสร้าง OVA หรือ OVF

เนื่องจาก OVA/OVF ไม่ใช่แค่ไฟล์ Disk (Block device) แต่เป็น "แพ็กเกจ" ที่รวมเอาไฟล์ Config (.ovf), ไฟล์ Disk (.vmdk) และไฟล์อื่นๆ เข้าด้วยกัน คุณไม่สามารถใช้ qemu-img ตัวเดียวจบได้ ต้องใช้วิธีดังนี้

วิธีที่ 1: ใช้ virt-v2v (แนะนำสำหรับ Linux สาย Enterprise)

เครื่องมือนี้ถูกออกแบบมาเพื่อย้าย VM ข้าม Platform โดยเฉพาะ มันจะจัดการแปลงทั้ง Disk และแก้ไข Driver ภายใน OS ให้รองรับ Hypervisor ตัวใหม่ด้วย

```
virt-v2v -i disk input.qcow2 -o ova -os /path/to/output
```

วิธีที่ 2: Manual Packaging (ทำเองแบบ Manual)

1. แปลง qcow2 เป็น VMDK ด้วย qemu-img
2. นำไฟล์ VMDK ไปสร้าง VM บน VMware Workstation หรือ ESXi

ใช้เมนู "Export to OVF/OVA" จากตัวโปรแกรม VMware เอง

#### 3. เครื่องมือทางเลือกอื่นๆ (GUI & Automation)

* StarWind V2V Converter (Windows): เป็นโปรแกรมฟรีที่มี GUI ใช้งานง่ายมาก รองรับการแปลง qcow2 ไปยังฟอร์แมตต่างๆ และสามารถ Push ขึ้น Cloud (AWS, Azure) หรือ VMware/Hyper-V Host ได้โดยตรง
* Clonezilla: ใช้ในกรณีที่ต้องการทำ Disk Cloning จาก Virtual Disk หนึ่งไปยังอีกลูกหนึ่งผ่านระบบ Network
* VBoxManage: หากคุณใช้ VirtualBox สามารถใช้คำสั่ง:

```
VBoxManage clonemedium disk input.qcow2 output.vdi --format VDI
```

\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-epc.gitbook.io/ncs-documents/compute/compute-image/export-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
