Virtual machine with INCUS (8)

Date: 2024/03/15 (initial publish), 2024/03/17 (last update)

Source: en/note-00070.md

Previous Post Top Next Post

TOC

Here is a series of memos of me trying to use LXC/LXD and INCUS on Debian 12 (bookworm).

I am using Incus for Debian 12 from Zabbly package repository.

Full DE in VM and its storage size

I had problem with VM created by INCUS when I installed full DE and upgraded to the testing due to “disk full`.

In order to check reason for the above problem, I installed most DE (w/o Office programs) without upgrade again. I see:

 $ incus exec vmc0 -- df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           391M  1.4M  390M   1% /run
/dev/sda2       9.6G  4.7G  4.9G  49% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            50M   18M   33M  35% /run/incus_agent
/dev/sda1        99M   12M   87M  12% /boot/efi
tmpfs           391M   64K  391M   1% /run/user/1000

I see that VM has relatively small 10GB allocated. This is OK for console system but not enough for full GUI DE.

The source of the storage size limitation

I checked VM as:

 $ incus config show vmc0
architecture: x86_64
config:
  image.architecture: amd64
  image.description: Debian bookworm amd64 (20240314_05:24)
  image.os: Debian
  image.release: bookworm
  image.serial: "20240314_05:24"
  image.type: disk-kvm.img
  image.variant: cloud
  limits.cpu: "4"
  limits.memory: 4GiB
  user.user-data: |-
    #cloud-config
    users:
    - name: osamu
      groups: adm, mail
      sudo: ALL=(ALL) NOPASSWD:ALL
  volatile.base_image: 8836a6135879e0f6d5be849eeaca9eb69290eb780784dfde7f980eb2395e77a2
  volatile.cloud-init.instance-id: caef9568-f8db-4b7d-babb-8e05fcf75fd3
  volatile.eth0.host_name: tapc904272d
  volatile.eth0.hwaddr: 00:16:3e:52:88:40
  volatile.last_state.power: RUNNING
  volatile.last_state.ready: "false"
  volatile.uuid: 38b6e9a4-03e1-4e03-a91f-634d57c3ead5
  volatile.uuid.generation: 38b6e9a4-03e1-4e03-a91f-634d57c3ead5
  volatile.vsock_id: "2876819046"
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: Osamu's default Incus profile 0

I see no storage limitation here.

Let me dig into default profile used.

 $ incus profile show default
config: {}
description: Default Incus profile
devices:
  eth0:
    name: eth0
    network: incusbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/instances/vmc0
- /1.0/instances/vmc1
- /1.0/instances/ctc0
- /1.0/instances/ctc1

Here, root device uses storage pool default. Let me dig into this storage pool default.

 $ incus storage show default
config:
  source: /var/lib/incus/storage-pools/default
description: ""
name: default
driver: dir
used_by:
- /1.0/instances/ctc0
- /1.0/instances/ctc1
- /1.0/instances/vmc0
- /1.0/instances/vmc1
- /1.0/profiles/default
status: Created
locations:
- none

So I looked into /var/lib/incus/storage-pools/default.

 $ cd /var/lib/incus/storage-pools/default
 $ sudo tree -F -L 3 .
./
├── buckets/
├── containers/
│   ├── ctc0/
│   │   ├── backup.yaml
│   │   ├── metadata.yaml
│   │   ├── rootfs/
│   │   └── templates/
│   └── ctc1/
│       ├── backup.yaml
│       ├── metadata.yaml
│       ├── rootfs/
│       └── templates/
├── containers-snapshots/
├── custom/
├── custom-snapshots/
├── images/
├── virtual-machines/
│   ├── vmc0/
│   │   ├── agent-client.crt
│   │   ├── agent-client.key
│   │   ├── agent.crt
│   │   ├── agent.key
│   │   ├── backup.yaml
│   │   ├── config/
│   │   ├── metadata.yaml
│   │   ├── OVMF_VARS.4MB.ms.fd
│   │   ├── qemu.nvram -> OVMF_VARS.4MB.ms.fd
│   │   ├── root.img
│   │   └── templates/
│   └── vmc1/
│       ├── agent-client.crt
│       ├── agent-client.key
│       ├── agent.crt
│       ├── agent.key
│       ├── backup.yaml
│       ├── config/
│       ├── metadata.yaml
│       ├── OVMF_VARS.4MB.ms.fd
│       ├── qemu.nvram -> OVMF_VARS.4MB.ms.fd
│       ├── root.img
│       └── templates/
└── virtual-machines-snapshots/

21 directories, 22 files
 $ sudo ls -lh virtual-machines/vmc{0,1}/root.img
-rw-r--r-- 1 root root 10G Mar 16 11:18 virtual-machines/vmc0/root.img
-rw-r--r-- 1 root root 10G Mar 15 23:54 virtual-machines/vmc1/root.img

Althogh driver: dir is used, each VM seems to use a fixed 10GB size disk image root.img.

Starting VM with larger disk size

I found a gentoo wiki page on Growing default disk size to be quite useful.

I created osamu-large profile using osamu-large.yaml file under the 018_incus directory.

 $ incus profile edit  osamu-large <osamu-large.yaml
 $ incus profile show  osamu-large
config:
  user.user-data: |-
    #cloud-config
    users:
    - name: osamu
      groups: adm, mail
      sudo: ALL=(ALL) NOPASSWD:ALL
description: Osamu's large Incus profile
devices:
  root:
    path: /
    pool: default
    size: 40GiB
    type: disk
name: osamu-large
used_by: []
 $ incus launch images:debian/12/cloud vmc-large  --vm -c limits.cpu=4 -c limits.memory=4GiB --profile default --profile osamu-large
Launching vmc-large
 $ sudo ls -lh /var/lib/incus/storage-pools/default/virtual-machines/vmc-large/root.img
 $ cd /var/lib/incus/storage-pools/default/virtual-machines/
 $ sudo ls -lh vmc-large/root.img
-rw-r--r-- 1 root root 40G Mar 16 13:56 vmc-large/root.img
 $ incus exec vmc-large -- df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           391M  652K  391M   1% /run
/dev/sda2        39G  1.1G   38G   3% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            50M   18M   33M  35% /run/incus_agent
/dev/sda1        99M   12M   87M  12% /boot/efi

I got a system with a large 40GB disk. Good!

When I tried to change disk size for existing instance, I got.

 $ incus config device set vmc0 root size=20GB
Error: Device from profile(s) cannot be modified for individual instance. Override device or modify profile instead

OK, so I need to modify profile, instead.

 $ incus config show vmc1
architecture: x86_64
config:
  cloud-init.user-data: |-
    #cloud-config
    users:
    - name: osamu
      groups: adm, mail
  image.architecture: amd64
  image.description: Debian bookworm amd64 (20240314_05:24)
  image.os: Debian
  image.release: bookworm
  image.serial: "20240314_05:24"
  image.type: disk-kvm.img
  image.variant: cloud
  limits.cpu: "4"
  limits.memory: 4GiB
  volatile.base_image: 8836a6135879e0f6d5be849eeaca9eb69290eb780784dfde7f980eb2395e77a2
  volatile.cloud-init.instance-id: 94ade860-4afc-462f-92ab-f5c09baf18e6
  volatile.eth0.hwaddr: 00:16:3e:76:2b:84
  volatile.last_state.power: STOPPED
  volatile.uuid: 9b9f43d6-e371-4516-8404-d76ffeba0030
  volatile.uuid.generation: 9b9f43d6-e371-4516-8404-d76ffeba0030
  volatile.vsock_id: "3154049642"
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: Osamu's default Incus profile 1

Since profile osamu0 and osamu1 only had config: and no devices:, the above lists only default profile.

 $ incus profile add  vmc1 osamu-large
Profile osamu-large added to vmc1
 $ incus profile add  vmc0 osamu-large
Profile osamu-large added to vmc0

These seems to update disk size to 40GB for both vmc0 and vmc1 instances as they are started. With the larger disk space, I could upgrade VM to trixie without problem.

It has been a bit confusing for me but, at least, I have usable VMs from INCUS.

With this experience, I see not much benefit of using cloud-init for my simple use cases.

My next step is to use the official Debian cloud images and other images

I need to learn more on Incus: Storage and Incus: Images.

Previous Post Top Next Post