Issue with START_SCRIPT on Opennebula 5.10

Hi,

I am trying to implement start_script functionality for a VM but I am facing some issues as listed below:

Opennebula: 5.10 (contextualization package is installed)
VM OS: Ubuntu 18.04

Issue: Start script is not being executed

Example CONTEXT:

CONTEXT=[
    ...
    NETWORK="YES",
    PASSWORD_BASE64="some-pass",
    SET_HOSTNAME="some-name",
    START_SCRIPT="sudo apt update && sudo apt install apache2 && sudo ufw allow 'Apache'",
    TARGET="hda" ]

Issue: /mnt dir in the VM is empty, checked the /etc/one-context.d dir debugging in the net-97-start-script

image

and that’s why my start_script is not being executed because it doesnt exist here

My context file is available here as shown by Opennebula

So, how can I resolve this ? Is there any way that my VM can access this context file in hda ? Or is my approach is wrong ?

Regards
Saksham

The context disk should be a CD-ROM device inside the VM. The context service mounts it, performs the operations then it is unmounted. Here is an example

[root@centos7-context-kvm-5-12-6-666cf-0 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   60G  0 disk 
└─sda1   8:1    0   60G  0 part /
sr0     11:0    1  366K  0 rom  
[root@centos7-context-kvm-5-12-6-666cf-0 ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7-context-kvm-5-12-6-666cf-0 ~]# cat /mnt/context.sh 
# Context variables generated by OpenNebula
DISK_ID='1'
ETH0_CONTEXT_FORCE_IPV4=''
ETH0_DNS='10.0.0.2'
ETH0_EXTERNAL=''
ETH0_GATEWAY='10.0.0.2'
ETH0_GATEWAY6=''
ETH0_IP='10.10.0.102'
ETH0_IP6=''
ETH0_IP6_PREFIX_LENGTH=''
ETH0_IP6_ULA=''
ETH0_MAC='02:00:0a:0a:00:66'
ETH0_MASK='255.0.0.0'
ETH0_MTU=''
ETH0_NETWORK='10.0.0.0'
ETH0_SEARCH_DOMAIN=''
ETH0_VLAN_ID=''
ETH0_VROUTER_IP=''
ETH0_VROUTER_IP6=''
ETH0_VROUTER_MANAGEMENT=''
ETH1_CONTEXT_FORCE_IPV4=''
ETH1_DNS=''
ETH1_EXTERNAL=''
ETH1_GATEWAY=''
ETH1_GATEWAY6=''
ETH1_IP='192.168.150.1'
ETH1_IP6=''
ETH1_IP6_PREFIX_LENGTH=''
ETH1_IP6_ULA=''
ETH1_MAC='02:00:c0:a8:96:01'
ETH1_MASK=''
ETH1_MTU=''
ETH1_NETWORK=''
ETH1_SEARCH_DOMAIN=''
ETH1_VLAN_ID='1158'
ETH1_VROUTER_IP=''
ETH1_VROUTER_IP6=''
ETH1_VROUTER_MANAGEMENT=''
NETWORK='YES'
SET_HOSTNAME='centos7-context-kvm-5-12-6-666cf-0.test'
SSH_PUBLIC_KEY='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDugXwwA/iDAQof3+vYnRA4VUpZxpqwRWXs8g0RENk5AS1ONt01NmxDg4mr7dSQBjx/w6JFDtydfLul/bj96uw8peuAQNP5k2lu2rWV9BBI5ysKMK4MlzEgwfSuztCWMHJZNF4q8JjR/0SF0eTOyumMWsBWS2JKakdyf/YZU+O5S6RcavpiX2bJ0yEaLYXpugLecp73hKoW3B4MpZLpBQwSjk+M668MTAb/SAFd6UALhMorXSTBRmSDByk4JL4OMvLOotyfcFF9va2CCOifqUa6LmOjZvuYi5p/JfT2x/aGOBIXibv9EtjkxkBoqNpkfITvWHm4Gx/91m/5eSYRtxYZ dann1@rocket
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu6O0X7lApjdT0KTBKoxuhB9EGBGpJ33kxAXkF+Yrk337GTxa9SI7aVnu/9wrbBKpKwmoDnD9J9BVSSobXKdLncaA9RrWKbkjnC+Y/vZltYywdHRKDawGJs2uncOtXek4M98dkRJ8vZDYsS90uZZbLU5kVcfE/gQDotcNH4Cf+0OKf8kO2GfTQRYYryUZ+fUU0tpu+HBGvdKUgfcX185NUmj9av+BaIibOAdJ9Sl5UGtL1VlV1oy77BBgpHvMlHD3qFaf6E2FZFse9o8oV/AO7Z+vhNxouu5g4eUIsd+Da5xul48HaAjtB4euZ1bTBquoqdczsIt8iOhdczUe6O3O5 kernel@phobos
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDcnIyd8XFrwetE3H84Bl6eK542sEGacX3IBpNLomRpKL4HOkXFr/pvlDBWr8ZWYbNg2Ny8Z5YnqvDLTRx1trFzE/PC/wv3no1Oa/MjWPV7Jt8oC/de+k7EgDP0u7PnqIo+d5QBitDFjwQ3hhgu/l7S/5aZ0LJNzP2HthQ0RGj/9y2TGiTWh/vYITBpon93qD+2S/aYPNRRBUedjRJbcSYSd8lSXY3mUe30AwpleuC6e/bqayXDY5i2houSrwbZd9Zq14rKvJ+C2GJuc9/fVFrkXatDpO+CAKO5jR9oe01UHrmYOE79XEoz3NERJi1bFoIk//hNdMpIMmLDOJH2zzOh root@infra-client'
TARGET='hda'

It’s OK that is not mounted on /mnt, you can check the context.sh which contains the variables pool fed to the contextualization service.

START_SCRIPT=“sudo apt update && sudo apt install apache2 && sudo ufw allow ‘Apache’”,

Also add -y to the apt commands in order to make them non-interactive and avoid CLI prompts

Hi @dann1, thank you for your time.

Now I have a better understanding of the situation.

I did mount and check the context.sh file and it’s ok.

Then I created a new VM with the START_SCRIPT missing -y flag but it still didn’t execute and then I checked the syslog and found the issue.

Apparently my VM’s dpkg was locked and now I am trying to resolve that issue somehow with the start script itself.

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

I have no problem with or relating to OpenNebula now but with Ubuntu.

1 Like