0

I want to create 100 Ubuntu VM's with virtualbox via commandline. Each Ubuntu VM should have its own unique /etc/machine-id value and unique mac address of the network adapter. There is a file with 100 hostnames (password doesn't matter) and every new Ubuntu VM should get a name assigned from this list.

If i clone 100 times an existing VM then all the new cloned VM's hav the same /etc/machine-id + username + mac address and i have to manually change everything to a new unique one - i dont like that.

Any ideas?

2 Answers 2

0

Clone, and change the IDs in the .vbox file using sed. Example,

sed -i -e "s/\(MACAddress=\"......\)....../\1$(openssl rand -hex 3)/" vm.vbox
sed -i -e "s/\(Machine uuid=\".........-....-....-....-\)............/\1$(openssl rand -hex 6)/" vm.vbox

You can tidy up the sed and make more complete UUID's, but this is the basic principle. Script it for each .vbox.

7
  • .vbox file editing the macs and UUID's does not work: I've cloned via the GUI an Ubuntu VM. I've compared the original .vbox file and the cloned .vbox file. Machine uuid, HardDisk uuid, MACAddress values are already different in .vbox files but cat /etc/machine-id on each Ubuntu VM shows identical values. So changing UUID's in .vbox file doesnt effect the /etc/machine-id
    – mankind86
    Commented Sep 10, 2020 at 0:25
  • Mount the vmdk and change it there too.
    – tater
    Commented Sep 10, 2020 at 0:38
  • Sorry i don't get it. The clone.vdi is already mounted in the VM. And the file itself is on a windows partition and i don't think i can edit this clone.vdi file with an editor (at least in windows it is not possible. clone.vdi has a file size of 3gb ). Sorry, im a total noob and im totally confused. I don't know what to do.
    – mankind86
    Commented Sep 10, 2020 at 1:07
  • Or do you man i have to change the UUID's in the .vbox file and then .vdi file8 (vmdk) needs to be updated (rewritten) and then Virtualbox needs to remount this updated .vdi file?
    – mankind86
    Commented Sep 10, 2020 at 1:29
  • /etc/machine-id is set at the installation of ubuntu so i think i have to use dbus-uuidgen for each virtual machine to have different uuids on each vm. i can write a script which opens an openssh connection to each vm, use dbus-uuidgen to generate a unique uuid for /etc/machine-id - what do you think?
    – mankind86
    Commented Sep 10, 2020 at 1:55
0

You can use Vagrant to provision many machines at once by creating a “Multi-Machine” environment: https://www.vagrantup.com/docs/multi-machine

Vagrant uses a config file that defines the environment and individual machines. It’s trivial to add additional machines:

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"

  config.vm.define "web" do |web|
    web.vm.box = "apache"
  end

  config.vm.define "db" do |db|
    db.vm.box = "mysql"
  end
end

With some clever text processing in vscode, it’s trivial to turn your list into a config section.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .