Packer: Mac address setting error using "qemuargs"

Created on 19 Apr 2017  路  15Comments  路  Source: hashicorp/packer

I'm using packer to build kvm images, I want to set a static mac address using qemuargs option in the template but there isn't much information available regarding that. I tried few times but the build fails. This is my template https://gist.github.com/sippala/f7b29e534fcaab41ab3fc96fae509c7e and this is the debug log https://gist.github.com/sippala/96ab04d2b1f7847bc1f80b2b59dd5ab5 [see lines 50-55 in the debug log for errors] I faced similar issues for vmware images as well but able to figure it out. Can someone post the list of "vmx_data" , "vbox_manage" and "qemuargs" options.

packer version : v0.12.3

buildeqemu question

Most helpful comment

@sippala I would suggest running qemu-system-x86_64 -net nic,model=? to see what are the supported NIC models on your system.

This is also what i have for one of my VM's:

-netdev tap,fd=32,id=hostnet0 -device e1000,netdev=hostnet0,id=net0,mac=xx:xx:xx:xx:xx:xx,bus=pci.0,addr=0x7 -vnc 127.0.0.1:3

All 15 comments

I found this http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/cannot-set-mac-address-with-qemu-4175490716/

I'm not a qemu expert so I'm not sure how much I can help, but probably something like

{
"qemuargs": [
    [ "-m", "1024M" ],
    [ "--no-acpi", "" ],
    [
       "-netdev",
      "user,id=mynet0,",
      "hostfwd=hostip:hostport-guestip:guestport",
      ""
    ],
    [ "-device", "virtio-net,netdev=mynet0,mac=00:00:00:11:11:11" ]
  ]
}

(example taken from https://www.packer.io/docs/builders/qemu.html#qemuargs)

{
"qemuargs": [
[ "-m", "2048M" ],
[ "-netdev", "user,id=mynet0,", "" ],
["-device", "virtio-net, netdev=mynet0, mac=00:0C:29:1C:F8:46"]
]
}
These parameters give this error

2017/04/19 10:09:53 packer: 2017/04/19 10:09:53 Executing /usr/libexec/qemu-kvm: []string{"-netdev", "user,id=mynet0,", "-boot", "once=d", "-vnc", "127.0.0.1:9", "-name", "kvm_API", "-m", "2048M", "-drive", "file=/var/tmp/VM-kvm/kvm_API,if=ide,cache=writeback,format=qcow2", "-cdrom", "/usr/local/packer/IDS-18.0.0.0-47-developer.iso", "-machine", "type=pc,accel=kvm", "-device", "virtio-net, netdev=mynet0, mac=00:0C:29:1C:F8:46"}
2017/04/19 10:09:53 packer: 2017/04/19 10:09:53 Started Qemu. Pid: 13668
2017/04/19 10:09:54 packer: 2017/04/19 10:09:54 Qemu stderr: qemu-kvm: -device virtio-net, netdev=mynet0, mac=00:0C:29:1C:F8:46: Parameter 'driver' expects a driver name
2017/04/19 10:09:54 packer: 2017/04/19 10:09:54 Qemu stderr: Try with argument '?' for a list.

@sippala I would suggest running qemu-system-x86_64 -net nic,model=? to see what are the supported NIC models on your system.

This is also what i have for one of my VM's:

-netdev tap,fd=32,id=hostnet0 -device e1000,netdev=hostnet0,id=net0,mac=xx:xx:xx:xx:xx:xx,bus=pci.0,addr=0x7 -vnc 127.0.0.1:3

qemu-system-x86_64 -net nic,model=?
qemu: Supported NIC models: ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio

I used ["-device", "ne2k-pci, netdev=mynet0, mac=00:0C:29:1C:F8:46"] in qemuargs
but I still get this error
Qemu stderr: qemu-kvm: -device ne2k-pci, netdev=mynet0, mac=00:0C:29:1C:F8:46: Parameter 'driver' expects a driver name
Qemu stderr: Try with argument '?' for a list.

Can someone please post the qemuargs part, I'm a beginner

@sippala I believe you're line should look like this: ["-device", "ne2k-pci, netdev=mynet0, mac=00:0C:29:1C:F8:46",id=net0"]

I still get
qemu-kvm: -device virtio, netdev=mynet0, mac=00:0C:29:1C:F8:46, id=net0: Parameter 'driver' expects a driver name

I checked the same with -device ne2k-pci but gives the same error, what is meant by a driver here ?

@sippala What OS are you running packer on? Please re-attach your template and debug log. The gist links return 404's

I'm running packer on CentOS (centos-release-6-7.el6.centos.12.3.x86_64). I've reattached the gists, template is https://gist.github.com/sippala/f7b29e534fcaab41ab3fc96fae509c7e and debug log is https://gist.github.com/sippala/96ab04d2b1f7847bc1f80b2b59dd5ab5

"qemuargs": [
[ "-m", "2048M" ],
[ "-device", "virtio-net-pci,netdev=mynet0,mac=52:54:00:12:34:56," ],
[ "-netdev", "user,id=mynet0,hostfwd=tcp::2222-:22," ]
],

This worked for me

Curious to know if this is related to the device being pci vs non-pci? that's one of the major differences as well as commas. Glad you were able to figure it out!

I don't know the exact reason but MAC addresses for kvm start with 52:54:00, initially I was giving 00:00:00,

I created a script to change the variables of template.json file without having to hard code the iso_url and iso_checksum fields. This will be useful for running nightly build sanity tests using packer (at least for people new to packer). This is the script https://gist.github.com/sippala/b7fb7990d373be85c0219102dc319145

just run the script, it will run packer after making necessary changes to the template

@sippala https://www.packer.io/docs/templates/user-variables.html. Will make your life a lot easier

@lfarnell user variables have to be defined in the template and I guess they have to be hard coded too. My purpose is to change the iso_url and iso_checksum for each nightly build. This script I wrote will use 'sed' to replace those values in the template file. I guess we can't do that with variables. or am I wrong ?

@sippala you can get the variables from the environment: https://www.packer.io/docs/templates/user-variables.html

closing since this looks like it's resolved. thanks all

Was this page helpful?
0 / 5 - 0 ratings