카테고리

asm (27) bootloader_x86_grub (1) C (92) compile (11) config (76) CPP (13) CSS (1) debugging (7) gimp (1) Go (1) html (1) Java (1) JavaScript (1) kernel (19) LibreOffice (3) Linux system progamming (21) MFC (1) opencv (4) OpenGL (1) PHP (1) Python (4) qemu (29) shell (3) socket (7) troubleshooting (2) ubuntu18.04 (2) windows (1)

2019/01/04

Cloud image amd64

1. Cloud image amd64
데스크탑 시스템 설치없이 직접 부팅 할 수있는 이미지임.
이게 가능한 이유는 https://help.ubuntu.com/community/CloudInit
여기 사이트에 설명 되어 있음.

즉 init 개념을 -> Cloudint 개념을 추가해 부팅 시퀀서를 만듬.

이미지 생성 스크립트
vi upstream.sh
#!/usr/bin/env bash

sudo apt-get install cloud-image-utils qemu qemu-system qemu-system-x86

# qcow2 형식.
img=ubuntu-18.04-server-cloudimg-amd64.img
if [ ! -f "$img" ]; then
  wget "https://cloud-images.ubuntu.com/releases/18.04/release/${img}"

  # sparse resize: 추가 공간을 사용하지 않고 나중 크기 변경 허용.
  # https://superuser.com/questions/1022019/how-to-increase-size-of-an-ubuntu-cloud-image
  qemu-img resize "$img" +128G
fi

user_data=user-data.img
if [ ! -f "$user_data" ]; then
  # 암호.
  # https://serverfault.com/questions/920117/how-do-i-set-a-password-on-an-ubuntu-cloud-image
  # https://askubuntu.com/questions/507345/how-to-set-a-password-for-ubuntu-cloud-images-ie-not-use-ssh
  cat >user-data <<EOF
#cloud-config
password: totoro
chpasswd: { expire: False }
ssh_pwauth: True
EOF
  cloud-localds "$user_data" user-data
fi

qemu-system-x86_64 \
  -drive "file=${img},format=qcow2" \
  -drive "file=${user_data},format=raw" \
  -device rtl8139,netdev=net0 \
  -enable-kvm \
  -m 2G \
  -netdev user,id=net0 \
  -serial mon:stdio \
  -smp 2 \
  -vga virtio \
;
:wq

QEMU 시작 후 부트 메뉴가 나타나면, 엔터 입력.

부트 메시지
error: no such device: root.

Press any key to continue...

특정 시간이 지나면 자동 부팅 됨.

사용자 이름: ubuntu
암호: totoro

인터넷 동작 확인.

댓글 없음:

댓글 쓰기