Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

I installed VirtualBox into chroot environment. But problem is I need rerun…

  1. User

    I installed VirtualBox into chroot environment. But problem is I need rerun /sbin/vboxconfig every host machine reboot because vboxconfig script runs vbox modules which not in autorun. What simple solution for this problem?

    Contents of /sbin/vboxconfig is: #!/bin/sh

    Id:postinst−common.sh1552442023−01−1714:15:46ZbirdId: postinst-common.sh 155244 2023-01-17 14:15:46Z bird

    @file

    Oracle VM VirtualBox

    VirtualBox Linux post-installer common portions

    Copyright (C) 2015-2023 Oracle and/or its affiliates.

    This file is part of VirtualBox base platform packages, as

    available from https://www.virtualbox.org.

    This program is free software; you can redistribute it and/or

    modify it under the terms of the GNU General Public License

    as published by the Free Software Foundation, in version 3 of the

    License.

    This program is distributed in the hope that it will be useful, but

    WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

    General Public License for more details.

    You should have received a copy of the GNU General Public License

    along with this program; if not, see https://www.gnu.org/licenses.

    SPDX-License-Identifier: GPL-3.0-only

    Put bits of the post-installation here which should work the same for all of

    the Linux installers. We do not use special helpers (e.g. dh_* on Debian),

    but that should not matter, as we know what those helpers actually do, and we

    have to work on those systems anyway when installed using the all

    distributions installer.

    We assume that all required files are in the same folder as this script

    (e.g. /opt/VirtualBox, /usr/lib/VirtualBox, the build output directory).

    The below is GNU-specific. See VBox.sh for the longer Solaris/OS X version.

    TARGET=readlink -e -- "${0}" || exit 1 MY_PATH="{TARGET%/[!/]*}" cd "{MY_PATH}" . "./routines.sh"

    START=true while test -n "1";docase"{1}"; do case "{1}" in --nostart) START= ;; *) echo "Bad argument ${1}" >&2 exit 1 ;; esac shift done

    Remove any traces of DKMS from previous installations.

    for i in vboxhost vboxdrv vboxnetflt vboxnetadp; do rm -rf "/var/lib/dkms/${i}"* done

    Install runlevel scripts and systemd unit files

    echo "My path is MYPATH"installinitscript"{MY_PATH}" install_init_script "{MY_PATH}/vboxdrv.sh" vboxdrv install_init_script "MYPATH/vboxballoonctrl−service.sh"vboxballoonctrl−serviceinstallinitscript"{MY_PATH}/vboxballoonctrl-service.sh" vboxballoonctrl-service install_init_script "{MY_PATH}/vboxautostart-service.sh" vboxautostart-service install_init_script "${MY_PATH}/vboxweb-service.sh" vboxweb-service finish_init_script_install

    delrunlevel vboxdrv addrunlevel vboxdrv delrunlevel vboxballoonctrl-service addrunlevel vboxballoonctrl-service delrunlevel vboxautostart-service addrunlevel vboxautostart-service delrunlevel vboxweb-service addrunlevel vboxweb-service

    ln -sf "${MY_PATH}/postinst-common.sh" /sbin/vboxconfig

    Set SELinux permissions

    XXX SELinux: allow text relocation entries

    if [ -x /usr/bin/chcon ]; then chcon -t texrel_shlib_t "{MY_PATH}"/*VBox* > /dev/null 2>&1 chcon -t texrel_shlib_t "{MY_PATH}"/VBoxAuth.so
    > /dev/null 2>&1 chcon -t texrel_shlib_t "{MY_PATH}"/VirtualBox.so \ > /dev/null 2>&1 chcon -t texrel_shlib_t "{MY_PATH}"/components/VBox*.so
    > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VirtualBox > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VBoxSDL > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VBoxHeadless \ > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VBoxNetDHCP
    > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VBoxNetNAT \ > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/VBoxExtPackHelperApp
    > /dev/null 2>&1 chcon -t java_exec_t "{MY_PATH}"/vboxwebsrv > /dev/null 2>&1 chcon -t bin_t "{MY_PATH}"/src/vboxhost/build_in_tmp
    > /dev/null 2>&1 chcon -t bin_t /usr/share/virtualbox/src/vboxhost/build_in_tmp
    > /dev/null 2>&1 fi

    test -n "{START}" && { if ! "{MY_PATH}/vboxdrv.sh" setup; then "${MY_PATH}/check_module_dependencies.sh" >&2 echo >&2 echo "There were problems setting up VirtualBox. To re-start the set-up process, run" >&2 echo " /sbin/vboxconfig" >&2 echo "as root. If your system is using EFI Secure Boot you may need to sign the" >&2 echo "kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load" >&2 echo "them. Please see your Linux system's documentation for more information." >&2 else start_init_script vboxdrv start_init_script vboxballoonctrl-service start_init_script vboxautostart-service start_init_script vboxweb-service fi }

  2. Assistant

    To automate the execution of /sbin/vboxconfig after every reboot, you can create a systemd service or add the command to your crontab or an init script. Here I'm going to show you the method using systemd, which is the more modern approach for most Linux distributions.

    Step-by-Step Guide for Using systemd:

    1. Create a systemd service file: Create a new service file in /etc/systemd/system/. You can name it vboxconfig.service:

      sudo nano /etc/systemd/system/vboxconfig.service
      
    2. Edit the service file: Add the following content to the file to define the service:

      [Unit]
      Description=Run VirtualBox vboxconfig
      After=network.target
      
      [Service]
      Type=oneshot
      ExecStart=/sbin/vboxconfig
      RemainAfterExit=true
      
      [Install]
      WantedBy=multi-user.target
      
    3. Reload the systemd manager configuration: This is necessary for the system to recognize the new service.

      sudo systemctl daemon-reload
      
    4. Enable the service: This ensures that the service is started at boot.

      sudo systemctl enable vboxconfig.service
      
    5. Start the service: You can start the service immediately without needing to reboot.

      sudo systemctl start vboxconfig.service
      
    6. Check the status of the service: To verify if the service is running correctly, you can use the status command.

      sudo systemctl status vboxconfig.service
      

    By following these steps, the /sbin/vboxconfig script will be executed automatically every time the system reboots, ensuring that the VirtualBox modules are loaded properly without manual intervention.

    Alternative Method Using cron:

    If you prefer using cron, you can add an entry to root's crontab to execute the script at every reboot.

    1. Open root's crontab file:

      sudo crontab -e
      
    2. Add the following line to the end of the crontab file:

      @reboot /sbin/vboxconfig
      
    3. Save and exit the editor. If you're using nano, this usually means CTRL+O to write out the file and CTRL+X to exit.

    Using either method, you will ensure that /sbin/vboxconfig runs at every boot, and thus, the VirtualBox modules are configured automatically.