본문 바로가기

리눅스

우분투에서 cloud-init을 사용하여 운영체제 설치를 자동화하는 방법(Auto Install)

728x90

우분투에서 cloud-init을 사용하여 운영체제 설치를 자동화하는 방법(Auto Install)

1. cloud-init 구성 파일 작성

cloud-init 구성 파일을 작성해야 합니다. 이 파일은 YAML 형식으로 작성되며, 설치 중에 시스템 구성을 지정합니다. 사용자 계정, 네트워크 설정, 보안 설정 등을 지정할 수 있습니다.

2. ISO 이미지 생성

cloud-init 구성 파일을 포함한 사용자 정의 preseed 파일을 사용하여 ISO 이미지를 생성합니다. 이를 위해 mkisofs나 다른 ISO 생성 도구를 사용할 수 있습니다.

3. ISO 이미지를 사용하여 운영체제 설치

생성된 ISO 이미지를 사용하여 운영체제를 설치합니다. 설치 중에 cloud-init은 구성 파일을 읽어 시스템을 자동으로 설정합니다.

4. 설치 후 부팅

설치가 완료되면 시스템을 재부팅하고, cloud-init은 구성 파일에 따라 시스템을 설정합니다.

sudo touch {meta-data,user-data,vendor-data}

cloud-init 구성 파일

sudo vim user-data
#cloud-config
autoinstall:
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
      - arches: [amd64, i386]
        uri: http://archive.ubuntu.com/ubuntu
      - arches: [default]
        uri: http://ports.ubuntu.com/ubuntu-ports
  identity: {hostname: pxe-clinet, password: ubuntu, realname: ubuntu, username: ubuntu}
  keyboard: {layout: us, toggle: null, variant: ''}
  locale: en_US
  ssh:
    allow-pw: true
    install-server: true
  storage:
    config:
      - {ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda}
      - {device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 1, preserve: false, type: partition, id: partition-1}
      - {fstype: xfs, volume: partition-1, preserve: false, type: format, id: format-1}
      - {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 2, preserve: false, type: partition, id: partition-2}
      - {name: ubuntu-vg, devices: [partition-2], preserve: false, type: lvm_volgroup, id: lvm_volgroup-0}
      - {name: ubuntu-lv, volgroup: lvm_volgroup-0, size: 100%, preserve: false, type: lvm_partition, id: lvm_partition-0}
      - {fstype: xfs, volume: lvm_partition-0, preserve: false, type: format, id: format-2}
      - {device: format-1, path: /boot, type: mount, id: mount-1}
      - {device: format-2, path: /, type: mount, id: mount-2}
  network:
    network:
      version: 2
      ethernets:
        ens3:
          dhcp4: true
  version: 1

 

참고URL

Ubuntu installation documentation : Automated Server installation

Ubuntu installation documentation : Autoinstall schema

 

728x90