
* Fix: don't need sudo if we're root + other aesthetics
* Heavy refactoring, see PR #28
* Fix: avoid silent fatalities
demo: https://tcp.ac/i/JMSUc.gif
* Fix: Inverse check on `IsRoot`
* D.R.Y: check for permissions error in `common.ErrorCheck`
Reduce cognitive complexity.
* Fix: Issue with copying
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646535918
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646606680 and https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646594105
* Revert "Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646606680 and https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646594105"
This reverts commit ce15213009
.
* Resolve https://github.com/HikariKnight/quickpassthrough/pull/28#discussion_r1646730751
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package configs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
|
)
|
|
|
|
// Set_Dracut writes a dracut configuration file for `/etc/dracut.conf.d/`.
|
|
func Set_Dracut() {
|
|
config := GetConfig()
|
|
|
|
// Set the dracut config file
|
|
dracutConf := fmt.Sprintf("%s/vfio.conf", config.Path.DRACUT)
|
|
|
|
// If the file already exists then delete it
|
|
if exists, _ := fileio.FileExist(dracutConf); exists {
|
|
_ = os.Remove(dracutConf)
|
|
}
|
|
|
|
// Write to logger
|
|
logger.Printf("Writing to %s:\nadd_drivers+=\" %s \"\n", dracutConf, strings.Join(vfio_modules(), " "))
|
|
|
|
// Write the dracut config file
|
|
fileio.AppendContent(fmt.Sprintf("add_drivers+=\" %s \"\n", strings.Join(vfio_modules(), " ")), dracutConf)
|
|
|
|
// 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))
|
|
}
|