---
# System prepended metadata

title: cloud-init environment
tags: [Ubuntu, MAAS, virtualization, openstack]

---

###### tags: `virtualization` `MAAS` `openstack` `Ubuntu`

# cloud-init environment
## Prerequisites
- 兩種使用 cloud-init 的方式(都只在 linux 上有效)
    - kvm or libvirt ( recommanded )
        - acted like real machine
    - lxd
        - using lxd debuging is much faster
- 可以擇一安裝
## lxd install
```bash=
sudo apt install snap
sudo snap install lxd
sudo lxd init --auto

# please logout and login
sudo usermod -aG lxd $USER

# if id print you are in lxd group, you are success installed
# otherwise just reboot it
id $USER
```

## install virtual machine manager
### CPU 硬體虛擬化
KVM 的執行必須仰賴 Intel VT 或 AMD-V 這兩種 CPU 硬體虛擬化功能，若在 Linux 中想要檢查自己的 CPU 是否有開啟這個功能，可以查看 /proc/cpuinfo 中是否有 vmx 或 svm 這兩個關鍵字
```
grep -E '(vmx|svm)' /proc/cpuinfo
```
#### 利用 package 確認虛擬化狀態
- 安裝 cpu checker
    ```
    sudo apt update
    sudo apt install  cpu-checker
    ```
- check kvm status
    ```
    sudo kvm-ok
    ``` 
    如果發現虛擬化那部份出問題，會 output 一些 error message
    
## install kvm at ubuntu
```
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
```
- list of packages
    - qemu-kvm: kvm 提供硬體虛擬化的 hypervisor
    - libvirt-daemon-system: 提供設定 libvirt 的 daemon 程式
    - libvirt-clients: 提供管理的 api
    - bridge-utils: a set of commandline to configure the ethernet network
    - virtinst: a set of commandline to configure the virtual machine
    - virt-manager: a easy-to-use GUI interface to configure the vitual machine

### check kvm is-active
```
sudo systemctl is-active libvirtd
```
if output active,then it is active.

### add user and group
```
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
```
log and login back, check the group has libvert and kvm.
```
id $USER
```

[more network setting](https://help.ubuntu.com/community/KVM/Networking#Bridged_Networking)