Score:0

configure an interface, which i want to survive reboot

in flag

I want to configure an interface for the virtual box, which is installed within my ubuntu machine. When i create it manually it works:

vboxmanage hostonlyif create
vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1

by checking ifconfig, It is there :

enter image description here

I want to make these changes survive a reboot and set automatically during system startup.For that what i did is:

sudo mkdir /opt/systemd/ then sudo mkdir /opt/systemd/ then sudo nano /opt/systemd/vboxhostonly and copy the following code into the file:

#!/bin/bash
vboxmanage hostonlyif create
vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1

then Ctrl + X to exit , Y to save and enter to write file.

Then I make the file executable

cd /opt/systemd/ then sudo chmod a+x vboxhostonly

the I create a service so

sudo touch /etc/systemd/system/vboxhostonlynic.service

Then I Edit the file by typing sudo nano /etc/systemd/system/vboxhostonlynic.service and then typing in:

Description=Setup VirtualBox Hostonly Adapter
After=vboxdrv.service
[Service]
Type=oneshot
ExecStart=/opt/systemd/vboxhostonly
[Install]
WantedBy=multi-user.target

then Ctrl + X to exit , Y to save and enter to write file.

Now to install the service and ensure it loads at boot time I type:

systemctl daemon-reload
systemctl enable vboxhostonlynic.service

But when i reboot the machine the interface is not there, any help would be appreciated?

Score:0
it flag

Your bash script can't find vboxmanage, because vboxmanage isn't in any directory in the script's $PATH. Try using the full path to vboxmanage (type -p vboxmanage), but you might have to move more of your environment to the script.

Jobs run through systemd startup scripts aren't run in the same runtime environment that you have on your desktop. systemd startup scripts are run as root. None of your PATH changes, or other environment variable settings from ~/.bashrc are automatically propagated to your systemd job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost). Other needed environment variables may need help, too.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.