partutil: Refactor MountEFIPartition output

To allow reading other files on the EFI partition, output the EFI
partition mountpoint instead of just the grub config. A constant for the
grub config path is additionally exported.

BUG=b/465210631
TEST=unit tests

Change-Id: Ib00a696e20de9e777be13e8c60a3c761b962fd9c
Reviewed-on: https://cos-review.googlesource.com/c/cos/tools/+/130122
Reviewed-by: Kevin Berry <kpberry@google.com>
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
Cloud-Build: GCB Service account <228075978874@cloudbuild.gserviceaccount.com>
diff --git a/src/pkg/provisioner/install_gpu_step.go b/src/pkg/provisioner/install_gpu_step.go
index 7b45f19..57fdabb 100644
--- a/src/pkg/provisioner/install_gpu_step.go
+++ b/src/pkg/provisioner/install_gpu_step.go
@@ -85,10 +85,11 @@
 		log.Println("No cmdline changes needed")
 		return nil
 	}
-	grubCfgPath, err := partutil.MountEFIPartition()
+	efiPath, err := partutil.MountEFIPartition()
 	if err != nil {
 		return err
 	}
+	grubCfgPath := filepath.Join(efiPath, partutil.GRUBCfgEFIPath)
 	grubCfg, err := os.ReadFile(grubCfgPath)
 	if err != nil {
 		umountErr := partutil.UnmountEFIPartition()
diff --git a/src/pkg/provisioner/sed_grub_config_step.go b/src/pkg/provisioner/sed_grub_config_step.go
index 5637b63..c8a0491 100644
--- a/src/pkg/provisioner/sed_grub_config_step.go
+++ b/src/pkg/provisioner/sed_grub_config_step.go
@@ -20,6 +20,7 @@
 	"log"
 	"os"
 	"os/exec"
+	"path/filepath"
 
 	"cos.googlesource.com/cos/tools.git/src/pkg/tools/partutil"
 )
@@ -34,10 +35,11 @@
 		return nil
 	}
 	log.Printf("Running sed script %q on grub config", s.SedScript)
-	grubCfgPath, err := partutil.MountEFIPartition()
+	efiPath, err := partutil.MountEFIPartition()
 	if err != nil {
 		return err
 	}
+	grubCfgPath := filepath.Join(efiPath, partutil.GRUBCfgEFIPath)
 	cmd := exec.Command(deps.SedCmd, "-i", "-e", s.SedScript, grubCfgPath)
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
diff --git a/src/pkg/tools/disable_systemd_service.go b/src/pkg/tools/disable_systemd_service.go
index 326bfce..bce8bf9 100644
--- a/src/pkg/tools/disable_systemd_service.go
+++ b/src/pkg/tools/disable_systemd_service.go
@@ -17,6 +17,7 @@
 import (
 	"fmt"
 	"log"
+	"path/filepath"
 
 	"cos.googlesource.com/cos/tools.git/src/pkg/tools/partutil"
 )
@@ -24,11 +25,12 @@
 // DisableSystemdService disables the auto-update service.
 func DisableSystemdService(service string) error {
 	cmd := "systemd.mask=" + service
-	grubPath, err := partutil.MountEFIPartition()
+	efiPath, err := partutil.MountEFIPartition()
 	if err != nil {
 		return fmt.Errorf("cannot mount EFI partition,"+
 			"error msg:(%v)", err)
 	}
+	grubPath := filepath.Join(efiPath, partutil.GRUBCfgEFIPath)
 	defer partutil.UnmountEFIPartition()
 	contains, err := partutil.GRUBContains(grubPath, cmd)
 	if err != nil {
diff --git a/src/pkg/tools/partutil/grub_utils.go b/src/pkg/tools/partutil/grub_utils.go
index 0215438..d76497c 100644
--- a/src/pkg/tools/partutil/grub_utils.go
+++ b/src/pkg/tools/partutil/grub_utils.go
@@ -23,9 +23,10 @@
 )
 
 var efiDevice = "/dev/disk/by-label/EFI-SYSTEM"
+var GRUBCfgEFIPath = "/efi/boot/grub.cfg"
 
 // MountEFIPartition mounts the EFI partition (/dev/sda12)
-// and returns the path where grub.cfg is at.
+// and returns the path where it is mounted.
 func MountEFIPartition() (string, error) {
 	dir, err := ioutil.TempDir("", "")
 	if err != nil {
@@ -39,7 +40,7 @@
 		return "", fmt.Errorf("error in mounting partition 12 at %q, "+
 			"error msg: (%v)", dir, err)
 	}
-	return dir + "/efi/boot/grub.cfg", nil
+	return dir, nil
 }
 
 // UnmountEFIPartition unmounts the EFI partition (/dev/sda12)
diff --git a/src/pkg/tools/seal_oem_partition.go b/src/pkg/tools/seal_oem_partition.go
index 03c643c..5a36492 100644
--- a/src/pkg/tools/seal_oem_partition.go
+++ b/src/pkg/tools/seal_oem_partition.go
@@ -21,6 +21,7 @@
 	"log"
 	"os"
 	"os/exec"
+	"path/filepath"
 	"runtime"
 	"strconv"
 	"strings"
@@ -52,11 +53,12 @@
 		return fmt.Errorf("cannot run veritysetup, input:oemFSSize4K=%d, "+
 			"error msg:(%v)", oemFSSize4K, err)
 	}
-	grubPath, err := partutil.MountEFIPartition()
+	efiPath, err := partutil.MountEFIPartition()
 	log.Println("EFI partition mounted.")
 	if err != nil {
 		return fmt.Errorf("cannot mount EFI partition (partition 12), error msg:(%v)", err)
 	}
+	grubPath := filepath.Join(efiPath, partutil.GRUBCfgEFIPath)
 	defer partutil.UnmountEFIPartition()
 	partUUID, err := partutil.GetPartUUID(oemPath)
 	if err != nil {