Day 3: Images and Datastores
Goal: Know where disks live, create your own data disk, and experience what “persistent” means in OpenNebula. · Duration: approx. 60 min · Prerequisite: Day 2
Briefing
- An image is a disk that OpenNebula manages: an operating system, an empty data disk, a CD. It lives in an image datastore.
- When a VM starts, the Transfer Manager copies its disks to the system datastore. That is where the VM works, not on the image itself.
- Whether changes flow back into the image is decided by a switch:
| Image | At start | When the VM is deleted |
|---|---|---|
| non-persistent (default) | copy or qcow2 overlay in the system datastore | copy is discarded |
| persistent | the VM works directly with the image | changes remain in the image |
- Image types:
OS(bootable),DATABLOCK(empty or filled data disk),CDROM(read-only, such as ISO files).
Image-Datastore 1 (default) System-Datastore 0
├─ Alpine Linux 3.20 (OS) ──Kopie──► /var/lib/one/datastores/0/<VM-ID>/disk.0
└─ daten (DATABLOCK, persistent) ────► Verweis, die VM schreibt ins Image
Drill 1: The datastores
onedatastore listExpected:
ID NAME SIZE AVA CLUSTERS IMAGES TYPE DS TM STAT
2 files 28G 76% 0 0 fil fs local on
1 default 28G 76% 0 3 img fs qcow2 on
0 system 28G 76% 0 0 sys - qcow2 on
| Column | Meaning |
|---|---|
TYPE |
sys for running VMs, img for images,
fil for files such as kernels or context scripts |
DS |
how images get in (fs = file system) |
TM |
how disks get to the hosts (qcow2 = overlays in the
shared file system) |
All three live on the same disk here, under
/var/lib/one/datastores. Images are plain files with hash
names there:
sudo ls -la /var/lib/one/datastores/1/Expected (shortened):
-rw-r--r-- 1 oneadmin oneadmin 1398682112 Nov 12 18:47 3004b2effa884b510c08267193825668
-rw-r--r-- 1 oneadmin oneadmin 89182208 Nov 12 18:45 59fed322469dcb8c2b10e5a346059c7f
The 1.4 GB file is the image of the OneKS appliance, the 89 MB one is
Alpine. Which file belongs to which image is revealed by
oneimage show <name> | grep SOURCE.
Save your progress? Sign up for free
Drill 2: A data disk
oneimage create --name daten --type DATABLOCK --size 512 --persistent --datastore default
oneimage listExpected:
ID: 2
ID USER GROUP NAME DATASTORE SIZE TYPE PER STAT RVMS
2 oneadmin oneadmin daten default 512M DB Yes rdy 0
1 oneadmin oneadmin Alpine Linux 3. default 512M OS No rdy 0
0 oneadmin oneadmin OneKS Appliance default 4G OS No rdy 0
PER Yes means persistent, STAT rdy means
ready. RVMS counts the VMs currently using the image.
A VM with an operating system and a data disk. --disk
replaces the template’s disks, which is why Alpine is in the list as
well:
onetemplate instantiate 1 --name speicher --disk "Alpine Linux 3.20,daten"After a minute:
onevm show speicher | grep -A3 '^VM DISKS'Expected:
VM DISKS
ID DATASTORE TARGET IMAGE SIZE TYPE SAVE
0 default vda Alpine Linux 3.20 -/512M file NO
1 default sdb daten -/512M file YES
SAVE YES is the persistent disk. TARGET sdb
is the name OpenNebula gives the disk in libvirt. Inside the VM, it has
a different name:
IP=$(onevm show speicher | grep -o 'ETH0_IP="[0-9.]*' | cut -d'"' -f2)
ssh root@$IP cat /proc/partitionsExpected (shortened):
major minor #blocks name
11 0 370 sr0
8 0 524288 sda
253 0 524288 vda
vdais the operating system (virtio disk).sdais the data disk. Linux numbers SCSI disks inside the VM on its own, and this is the first one.sr0is a small CD drive with the context, the VM’s startup data (Day 4).
Remember: Inside the VM, never rely on the
TARGETname from OpenNebula. If you need fixed names, setDEV_PREFIX=vdon the image. Then the data disk is also calledvdbinside the VM.
Save your progress? Sign up for free
Drill 3: Persistent or not
Format, mount, write two files, one on the data disk and one on the operating system:
ssh root@$IP "apk add -q e2fsprogs; mkfs.ext4 -q /dev/sda; mkdir -p /daten; \
mount /dev/sda /daten; echo Hallo OpenNebula > /daten/notiz.txt; \
echo Weg > /root/fluechtig.txt; sync; df -h /daten | tail -1"Expected:
/dev/sda 488M 156K 452M 1% /daten
Now the VM is deleted and a new one is created with the same images:
onevm terminate speicher
onetemplate instantiate 1 --name speicher2 --disk "Alpine Linux 3.20,daten"After a minute:
IP=$(onevm show speicher2 | grep -o 'ETH0_IP="[0-9.]*' | cut -d'"' -f2)
ssh root@$IP \
"mkdir -p /daten; mount /dev/sda /daten; cat /daten/notiz.txt; ls /root/fluechtig.txt"Expected (shortened):
Hallo OpenNebula
ls: cannot access '/root/fluechtig.txt': No such file or directory
The note survived, the file on the operating system did not.
e2fsprogs is gone again too: the Alpine image is not
persistent, and every VM starts from the original state.
Save your progress? Sign up for free
Checkpoint
oneimage list | grep datenExpected: daten with PER Yes,
STAT used, RVMS 1.
onevm show speicher2 | grep -c 'daten'Expected: 1 or more; the disk is attached to the VM.
Challenge
A second VM should get the same data disk while
speicher2 is running. What happens?
Solution
onetemplate instantiate 1 --name speicher3 --disk "Alpine Linux 3.20,daten"Expected:
[one.template.instantiate] Error allocating a new virtual machine template. DISK 1: Cannot acquire image 2, it is persistent and already in use
OpenNebula refuses even to create it. A persistent image always belongs to exactly one VM. Two VMs writing to the same ext4 at the same time would destroy it. Shared storage for multiple VMs needs a cluster file system or a network service such as NFS.
Clean up:
onevm terminate speicher2The image daten remains. You no longer need it, but you
never delete a persistent image with data by accident. Once you are
sure:
oneimage delete datenSave your progress? Sign up for free
Enterprise Note
- Shared storage: In production, system and image datastores live on Ceph, NFS, or a SAN. Then disks do not have to be copied, and a VM can move to another host without interruption (live migration).
- qcow2 chains: Non-persistent VMs start as a thin overlay on top of the image. Many VMs from one image save space this way, but the image must not change as long as VMs build on it.
- Backups: Persistent images are where data lives. OpenNebula 7 comes with its own backup datastores (Day 7). Images without backups are off-limits in production.