How to fix VirtualBox redhat-7 eth0 ONBOOT=no connectivity issue with vboxmange tools?

时光总嘲笑我的痴心妄想 提交于 2019-12-13 20:19:14

问题


I am creating virtualbox redhat box with packer with the template attached below. Everything is fine except that when the host is created and rebooted, the eth0 network adapter does not start as it is created with ONBOOT=no in /etc/sysconfig/network-scripts. However, if I open the UI of the box and manually trigger ifup eth0, it starts fine, ssh becomes available and the process completes as expected. However, I need to use it in a jenkins pipeline so there is no option someone can go and start the network interface manually. The question, is there any way to change the ONBOOT option to yes for the network adapter with virtualbox manage commands, or trigger the ifup eth0 command somehow. Either option may solve the problem.

  {
  "variables": {
    "build_base": ".",
    "isref_machine":"create-ova-caf",
    "build_name":"virtual-box-jenkins",
    "output_name":"packer-virtual-box",
    "disk_size":"40000",
    "ram":"1024",
    "disk_adapter":"ide"
  },  
  "builders":[
        {   
          "name": "{{user `build_name`}}",
          "type": "virtualbox-iso",
          "guest_os_type": "Other_64",
          "iso_url": "rhelis74_1710051533.iso",
          "iso_checksum": "",
          "iso_checksum_type": "none",
          "hard_drive_interface":"{{user `disk_adapter`}}",
          "ssh_username": "root",
          "ssh_password": "Secret1.0",
          "shutdown_command": "shutdown -P now",
          "guest_additions_mode":"disable",
          "boot_wait": "3s",
          "boot_command": [ "auto<enter>"],
          "ssh_timeout": "40m",
          "headless":
          "true",
          "vm_name": "{{user `output_name`}}",
                    "disk_size": "{{user `disk_size`}}",
          "output_directory":"{{user `build_base`}}/output-{{build_name}}",
          "format": "ovf",
          "vrdp_bind_address": "0.0.0.0",
          "vboxmanage": [
            ["modifyvm", "{{.Name}}","--nictype1","virtio"],
            ["modifyvm", "{{.Name}}","--memory","{{ user `ram`}}"]
          ],
          "skip_export":true,
          "keep_registered": true
        }   
  ],  
  "provisioners": [
    {
      "type":"shell",
      "inline": ["ls"]

    }
  ]

}

回答1:


To change the network interface boot settings to onboot=yes, we need to create an anaconda kickstart script or copy one from an existing machine and change the configurations in it and pass it as

 "boot_command": [ "<esc><wait>",
        "vmlinuz initrd=initrd.img net.ifnames=0 biosdevname=0 ",
        "ks=hd:fd0:/anaconda-ks.cfg",
        "<enter>"
  ],

and in anaconda file

network  --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto --activate


来源:https://stackoverflow.com/questions/54361286/how-to-fix-virtualbox-redhat-7-eth0-onboot-no-connectivity-issue-with-vboxmange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!