본문 바로가기

AWS Cloud School

[05.02] KVM 이미지 생성(CLI환경), kvmnet 네트워크 추가, virt-builder, virt-customize

 

virt-install --name=v2 --vcpus=2 --memory=512 --os-variant=debian8 

--cdrom /remote/images/vyos.iso --network bridge=br0 --graphic=vnc --noautoconsole --disk path=/remote/vm/v2.img,size=2

 

 

virt-install --name=c1 --ram=256 --network network=kvmnet1 --disk=/remote/vm/c1.img --import --noautoconsole --graphic=vnc

 

 

 

[root@srv1 qemu]# cp /remote/images/cent78.img /remote/vm/cent1.img

# 복사

[root@srv1 qemu]# virt-install --name=cent1 --ram=2048 --network bridge=br0 --disk=/remote/vm/cent1.img --import --noautoconsole --graphic=vnc

# 생성

 

 

 

 

 

<이미지 커스터마이징>

virt-customize

/remote/images/cent78.img 이미지 파일을 커스터마이징 해보자

 

[root@srv1 qemu]# virt-customize -a /remote/images/cent78.img --firstboot-install httpd \

--firstboot-command 'systemctl disable --now firewalld && systemctl enable --now httpd'

 

# 웹서버 설치, 방화벽 종료

 

[root@srv1 qemu]# cp /remote/images/cent78.img /remote/vm/cent2.img

 

[root@srv1 qemu]# virt-install --name=cent2 --ram=2048 --network bridge=br0 --disk=/remote/vm/cent2.img --import --noautoconsole --graphic=vnc

 

 

 

 

 

 

 

 

virt-builder centos-7.8 --size=6.5G --format=qcow2 -o /remote/images/cent78.img --root-password password:test123 --mkdir /root/.ssh --upload /root/.ssh/id_rsa.pub:/root/id_rsa.pub --firstboot-command 'cat /root/id_rsa.pub >> /root/.ssh/authorized_keys' --selinux-relabel

 

[root@srv1 ~]# cp /remote/images/cent78.img /remote/vm/cent1.img

# 빌드된원본은 소중히 간직하기 위해 복사를 해서 복사한 이미지로 vm을 생성

 

virt-install --name=cent1 --ram=2048 --network bridge=br0 --disk=/remote/vm/cent1.img --import --noautoconsole --graphic=vnc

 

 

 

<ssh-inject 를 통한 authorized_keys 등록>

 

--ssh-inject <사용자>:file:<파일경로>

를 통해 자동으로 authorized_keys 생성이 가능하다.

 

virt-builder centos-7.8 --size=6.5G --format=qcow2 -o /remote/images/cent78.img --root-password password:test123 --ssh-inject root:file:/root/.ssh/id_rsa.pub --selinux-relabel

 

[root@srv1 ~]# cp /remote/images/cent78.img /remote/vm/cent1.img

 

virt-install --name=cent1 --ram=2048 --network bridge=br0 --disk=/remote/vm/cent1.img --import --noautoconsole --graphic=vnc

 

 

virt-customize -a /remote/images/cent78.img --firstboot-install httpd \

--firstboot-command 'systemctl disable --now firewalld && systemctl enable --now httpd && echo I LOVE TEACHER > /var/www/html/index.html'

 

[root@srv1 ~]# cp /remote/images/cent78.img /remote/vm/cent2.img

 

[root@srv1 ~]# virt-install --name=cent2 --ram=2048 --network bridge=br0 --disk=/remote/vm/cent2.img --import --noautoconsole --graphic=vnc