title: Correct way to create /etc/machine-id from python
body: <p>I want to create systemd's <code>/etc/machine-id</code> from a python script instead of using <code>systemd-machine-id-setup</code>. I am preparing a rootfs and I don't want to depend on systemd being installed on the host.</p>
  
  <p>My current code looks like this:</p>
  
  <pre><code>from uuid import uuid4
  f = open("machine-id", "w")
  f.write(uuid4().hex + "\n")
  f.close()
  </code></pre>
  
  <p>Is this the correct way of doing it? Is it the correct byteorder? Did I miss anything?</p>
  
  <p>If needed, please provide correct code and/or references.</p>