Skip to content

Commit

Permalink
Update LIBVIRT_NVIDIA_JETSON_CLOUD_IMAGES.md
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorific committed Jun 3, 2024
1 parent 44ad2a0 commit 7664a21
Showing 1 changed file with 95 additions and 17 deletions.
112 changes: 95 additions & 17 deletions docs/LIBVIRT_NVIDIA_JETSON_CLOUD_IMAGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
# Libvirt cloud images on Nvidia Jetson

# Create a storage pool for cloud-init boot images

> **Note:**
> There is a `--cloud-init` parameter for `virt-install` to auto-generate the
> cloud-init ISO. It creates a pool called `boot-scratch` in
> `/var/lib/libvirt/boot`. However oftentimes it's just easier to control the
> lifecycle of these images manually
```
# Create the storage pool definition
$ virsh pool-define-as \
--name boot-scratch \
--type dir \
--target /var/lib/libvirt/boot
Pool iso defined
# Create the local directory
$ virsh pool-build boot-scratch
# Start the storage pool
$ virsh pool-start boot-scratch
# Turn on autostart
$ virsh pool-autostart boot-scratch
# Verify the storage pool is listed
$ virsh pool-list --all
Name State Autostart
------------------------------------
boot-scratch active yes
default active yes
iso active yes
$ virsh vol-list --pool boot-scratch --details
Name Path Type Capacity Allocation
---------------------------------------------
# Verify the storage pool configuration
$ virsh pool-info boot-scratch
Name: boot-scratch
UUID: 9e3bfda7-299e-4b40-8ce5-82a08f150368
State: running
Persistent: yes
Autostart: yes
Capacity: 6.93 TiB
Allocation: 121.86 GiB
Available: 6.81 TiB
```

## Download the Ubuntu Cloud Image
```
# JetPack 5.x
mkdir ~/ubuntu-server-2004 && cd ~/ubuntu-server-2004
curl -LO https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img
# JetPack 6.x
mkdir ~/ubuntu-server-2204 && cd ~/ubuntu-server-2204
curl -LO https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img
$ qemu-img info jammy-server-cloudimg-arm64.img
Expand All @@ -18,32 +67,51 @@ Format specific information:
compat: 0.10
refcount bits: 16
sudo mkdir -p /var/lib/libvirt/images/ubuntu-server-2204
sudo qemu-img convert -f qcow2 -O qcow2 jammy-server-cloudimg-arm64.img /var/lib/libvirt/images/ubuntu-server-2204/root-disk.qcow2
sudo qemu-img resize -f qcow2 /var/lib/libvirt/images/ubuntu-server-2204/root-disk.qcow2 32G
sudo qemu-img convert -f qcow2 -O qcow2 jammy-server-cloudimg-arm64.img /var/lib/libvirt/images/ubuntu-server-2204.qcow2
sudo qemu-img resize -f qcow2 /var/lib/libvirt/images/ubuntu-server-2204.qcow2 32G
```

```
touch network-config
touch meta-data
cat >meta-data <<EOF
instance-id: ubuntu-server-2204
local-hostname: ubuntu-server-2204
EOF
# openssl passwd -6 <password>
cat >user-data <<EOF
#cloud-config
password: password
chpasswd:
expire: False
ssh_pwauth: True
hostname: ubuntu-server-2204.corp.polymathrobotics.dev
users:
- default
- name: automat
groups: users
shell: /bin/bash
passwd: $6$WmRgh/NiWY/OIot.$SY0X.EfPAVxzfAizOaua5j10HfacJbJEFnCh0M9T81nqm1i05.BaRx.p9KUqiJEptbS891kPpA7V3vbt6NaFS0
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: false
ssh_authorized_keys:
- <ssh pub key 1>
packages:
- qemu-guest-agent
growpart:
mode: auto
devices: ['/']
power_state:
mode: reboot
EOF
```

```
sudo apt-get update
sudo apt-get install genisoimage
# -input-charset utf-8 \
genisoimage \
-output seed.img \
-input-charset utf-8 \
-output ubuntu-server-2204-cloud-init.img \
-volid cidata -rational-rock -joliet \
user-data meta-data network-config
sudo cp seed.img /var/lib/libvirt/images/ubuntu-server-2204/seed.iso
sudo cp ubuntu-server-2204-cloud-init.img /var/lib/libvirt/boot/ubuntu-server-2204-cloud-init.iso
```

```
Expand All @@ -54,11 +122,24 @@ virt-install \
--memory 2048 \
--vcpus 2 \
--os-variant ubuntu20.04 \
--disk /var/lib/libvirt/images/ubuntu-server-2204/root-disk.qcow2,bus=virtio \
--disk /var/lib/libvirt/images/ubuntu-server-2204/seed.iso,device=cdrom \
--disk /var/lib/libvirt/images/ubuntu-server-2204.qcow2 \
--disk /var/lib/libvirt/boot/ubuntu-server-2204-cloud-init.iso,device=cdrom \
--network network=host-network,model=virtio \
--noautoconsole \
--console pty,target_type=serial \
--import \
--debug
virsh console ubuntu-server-2204
# Disable cloud-init
$ sudo touch /etc/cloud/cloud-init.disabled
$ cloud-init status
status: disabled
$ sudo shutdown -h now
$ virsh domblklist ubuntu-server-2204
Target Source
----------------------------------------------------------------------
Expand All @@ -68,7 +149,7 @@ $ virsh domblklist ubuntu-server-2204
$ virsh change-media ubuntu-server-2204 sda --eject
Successfully ejected media.
$ sudo rm /var/lib/libvirt/images/ubuntu-server-2204/seed.iso
$ sudo rm /var/lib/libvirt/boot/ubuntu-server-2204-cloud-init.iso
$ virsh edit ubuntu-server-2204
# remove entry for the seed.iso
<disk type='file' device='cdrom'>
Expand All @@ -78,9 +159,6 @@ $ virsh edit ubuntu-server-2204
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
# disable cloud-init
sudo touch /etc/cloud/cloud-init.disabled
```

## References
Expand Down

0 comments on commit 7664a21

Please sign in to comment.