diff --git a/internal/configs/config_bootloaders.go b/internal/configs/config_bootloaders.go index d5a1642..d970586 100644 --- a/internal/configs/config_bootloaders.go +++ b/internal/configs/config_bootloaders.go @@ -6,6 +6,8 @@ import ( "github.com/klauspost/cpuid/v2" ) +// This function just adds what bootloader the system has to our config.bootloader value +// Preference is given to kernelstub because it is WAY easier to safely edit compared to grub2 func getBootloader(config *Config) { // Check what bootloader handler we are using // Check for grub-mkconfig @@ -29,6 +31,9 @@ func getBootloader(config *Config) { } } +// This function adds the default kernel arguments we want to the config/cmdline file +// This gives us a file we can read all the kernel arguments this system needs +// in case of an unknown bootloader func set_Cmdline() { // Get the system info cpuinfo := cpuid.CPU @@ -36,7 +41,20 @@ func set_Cmdline() { // Get the configs config := GetConfig() - // Write test file - fileio.AppendContent(cpuinfo.VendorString, config.path.CMDLINE) - fileio.AppendContent(cpuinfo.VendorString, config.path.CMDLINE) + // Write the file containing our kernel arguments to feed the bootloader + fileio.AppendContent("iommu=pt", config.path.CMDLINE) + + // Write the argument based on which cpu the user got + switch cpuinfo.VendorString { + case "AuthenticAMD": + fileio.AppendContent(" amd_iommu=on", config.path.CMDLINE) + case "GenuineIntel": + fileio.AppendContent(" intel_iommu=on", config.path.CMDLINE) + } + + // If the config folder for dracut exists in our configs + if fileio.FileExist(config.path.DRACUT) { + // Add an extra kernel argument needed for dracut users + fileio.AppendContent(" rd.driver.pre=vfio_pci", config.path.CMDLINE) + } } diff --git a/internal/configs/configs.go b/internal/configs/configs.go index d933ece..2dea325 100644 --- a/internal/configs/configs.go +++ b/internal/configs/configs.go @@ -76,9 +76,6 @@ func InitConfigs() { // Make the config folder os.Mkdir("config", os.ModePerm) - // Generate the kernel arguments - set_Cmdline() - // Make a regex to get the system path instead of the config path syspath_re := regexp.MustCompile(`^config`) @@ -136,4 +133,7 @@ func InitConfigs() { } } } + + // Generate the kernel arguments + set_Cmdline() }