installutils: Supply blank /etc/machine-id file (#147)
From https://www.freedesktop.org/software/systemd/man/machine-id.html: For operating system images which are created once and used on multiple machines, for example for containers or in the cloud, /etc/machine-id should be an empty file in the generic file system image. An ID will be generated during boot and saved to this file if possible.
This commit is contained in:
Родитель
3169bfd8c2
Коммит
328cd7b4c1
|
@ -499,24 +499,23 @@ func calculateTotalPackages(packages []string, installRoot string) (totalPackage
|
|||
return
|
||||
}
|
||||
|
||||
// addMachineID creates the /etc/machine-id file in the installChroot
|
||||
func addMachineID(installChroot *safechroot.Chroot) (err error) {
|
||||
const (
|
||||
squashErrors = false
|
||||
setupProgram = "/bin/systemd-machine-id-setup"
|
||||
)
|
||||
// From https://www.freedesktop.org/software/systemd/man/machine-id.html:
|
||||
// For operating system images which are created once and used on multiple
|
||||
// machines, for example for containers or in the cloud, /etc/machine-id
|
||||
// should be an empty file in the generic file system image. An ID will be
|
||||
// generated during boot and saved to this file if possible.
|
||||
|
||||
// Check if systemd-machine-id-setup is present before invoking it,
|
||||
// some images will not use systemd (such as a container)
|
||||
exists, _ := file.PathExists(filepath.Join(installChroot.RootDir(), setupProgram))
|
||||
if !exists {
|
||||
logger.Log.Debugf("'%s' not found inside chroot '%s', skipping adding machine ID", setupProgram, installChroot.RootDir())
|
||||
return
|
||||
}
|
||||
const (
|
||||
machineIDFile = "/etc/machine-id"
|
||||
machineIDFilePerms = 0644
|
||||
)
|
||||
|
||||
ReportAction("Configuring machine id")
|
||||
|
||||
err = installChroot.UnsafeRun(func() error {
|
||||
return shell.ExecuteLive(squashErrors, setupProgram)
|
||||
return file.Create(machineIDFile, machineIDFilePerms)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
|
@ -101,6 +101,18 @@ func ReadLines(path string) (lines []string, err error) {
|
|||
return lines, scanner.Err()
|
||||
}
|
||||
|
||||
// Create creates a new file with the provided Unix permissions
|
||||
func Create(dst string, perm os.FileMode) (err error) {
|
||||
logger.Log.Debugf("Creating (%s) with mode (%v)", dst, perm)
|
||||
|
||||
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_EXCL, perm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer dstFile.Close()
|
||||
return
|
||||
}
|
||||
|
||||
// Write writes a string to the file dst.
|
||||
func Write(data string, dst string) (err error) {
|
||||
logger.Log.Debugf("Writing to (%s)", dst)
|
||||
|
|
Загрузка…
Ссылка в новой задаче