install.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package install
  2. import (
  3. "os"
  4. "os/exec"
  5. "path/filepath"
  6. "strings"
  7. "github.com/rancher/os/config"
  8. "github.com/rancher/os/log"
  9. "github.com/rancher/os/util"
  10. )
  11. const BootDir = "boot/"
  12. type MenuEntry struct {
  13. Name, BootDir, Version, KernelArgs, Append string
  14. }
  15. type BootVars struct {
  16. BaseName, BootDir string
  17. Timeout uint
  18. Fallback int
  19. Entries []MenuEntry
  20. }
  21. func MountDevice(baseName, device, partition string, raw bool) (string, string, error) {
  22. log.Debugf("mountdevice %s, raw %v", partition, raw)
  23. if partition == "" {
  24. if raw {
  25. log.Debugf("util.Mount (raw) %s, %s", partition, baseName)
  26. cmd := exec.Command("lsblk", "-no", "pkname", partition)
  27. log.Debugf("Run(%v)", cmd)
  28. cmd.Stderr = os.Stderr
  29. device := ""
  30. // TODO: out can == "" - this is used to "detect software RAID" which is terrible
  31. if out, err := cmd.Output(); err == nil {
  32. device = "/dev/" + strings.TrimSpace(string(out))
  33. }
  34. log.Debugf("mountdevice return -> d: %s, p: %s", device, partition)
  35. return device, partition, util.Mount(partition, baseName, "", "")
  36. }
  37. //rootfs := partition
  38. // Don't use ResolveDevice - it can fail, whereas `blkid -L LABEL` works more often
  39. cfg := config.LoadConfig()
  40. if d, _ := util.Blkid("RANCHER_BOOT"); d != "" {
  41. partition = d
  42. baseName = filepath.Join(baseName, BootDir)
  43. } else {
  44. if dev := util.ResolveDevice(cfg.Rancher.State.Dev); dev != "" {
  45. // try the rancher.state.dev setting
  46. partition = dev
  47. } else {
  48. if d, _ := util.Blkid("RANCHER_STATE"); d != "" {
  49. partition = d
  50. }
  51. }
  52. }
  53. cmd := exec.Command("lsblk", "-no", "pkname", partition)
  54. log.Debugf("Run(%v)", cmd)
  55. cmd.Stderr = os.Stderr
  56. // TODO: out can == "" - this is used to "detect software RAID" which is terrible
  57. if out, err := cmd.Output(); err == nil {
  58. device = "/dev/" + strings.TrimSpace(string(out))
  59. }
  60. }
  61. os.MkdirAll(baseName, 0755)
  62. cmd := exec.Command("mount", partition, baseName)
  63. //cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
  64. log.Debugf("mountdevice return2 -> d: %s, p: %s", device, partition)
  65. return device, partition, cmd.Run()
  66. }