Prevent appending multiple times to the file

This commit is contained in:
HikariKnight 2023-04-11 02:44:00 +02:00
parent ff5d20f4f9
commit 68aec7fdb8
2 changed files with 39 additions and 9 deletions

View file

@ -27,8 +27,14 @@ func Set_Dracut() {
// Write the dracut config file
fileio.AppendContent(fmt.Sprintf("add_drivers+=\" %s \"\n", strings.Join(vfio_modules(), " ")), dracutConf)
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
// Get the current kernel arguments we have generated
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
// If the kernel argument is not already in the file
if !strings.Contains(kernel_args, "rd.driver.pre=vfio_pci") {
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
}
// Make a backup of dracutConf if there is one there
backupFile(strings.Replace(dracutConf, "config", "", 1))