0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KVM上でamazon linux2023

Posted at

amazon linux2023イメージのダウンロード

例:al2023-kvm-2023.5.20240916.0-kernel-6.1-x86_64.xfs.gpt.qcow2
https://cdn.amazonlinux.com/al2023/os-images/2023.5.20240916.0/kvm/

cloud-init用のデータを作成

適当なディレクトリを作って、以下の3ファイルを作成
例では、/mnt/ssd1/kvm/init/al2023/ に作成

vi meta-data

local-hostname: al2023

vi user-data

#cloud-config
#vim:syntax=yaml
users:
  - default
  - name: testuser
    groups: sudo
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    plain_text_passwd: testpass1234
    lock_passwd: false
chpasswd:
  list: |
    ec2-user:amazon

vi network-config

version: 2
ethernets:
  virtio:
    addresses:
      - 192.168.0.25/24
    gateway4: 192.168.0.1
    nameservers:
      addresses:
        - 194.168.0.1

※network-config で指定したが、なぜかdhcpになってしまったので、後で修正

バーチャルマシンの作成

/mnt/ssd1/kvm がkvmのイメージディレクトリの例です

virt-install \
    --memory 2048 \
    --vcpus 2 \
    --name AL2023 \
    --disk /mnt/ssd1/kvm/al2023-kvm-2023.5.20240916.0-kernel-6.1-x86_64.xfs.gpt.qcow2,device=disk,bus=virtio,format=qcow2 \
    --osinfo detect=on,require=off \
    --network bridge=br0 \
    --virt-type kvm \
    --graphics none \
    --noautoconsole \
    --import \
    --cloud-init user-data="/mnt/ssd1/kvm/init/al2023/user-data,meta-data=/mnt/ssd1/kvm/init/al2023/meta-data,network-config=/mnt/ssd1/kvm/init/al2023/network-config" 

初回起動時

ec2-userでログインするとパスワード変更が求められますので、設定してください

sshで鍵無ログイン可能に設定

vi /etc/ssh/sshd_config

#AuthorizedKeysFile     .ssh/authorized_keys
PasswordAuthentication yes

ipアドレス固定化

vi /etc/systemd/network/10-cloud-init-ens2.network

[Match]
MACAddress=xx:xx:xx:xx:xx:xx
Name=ens2

[Network]
#DHCP=ipv4
Address=192.168.0.25/24
Gateway=192.168.0.1
DNS=192.168.0.1

DHCP=ipv4をコメントアウトして、Address、Gateway、DNSを設定します

systemctl restart systemd-networkd

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?