fix(init): revert e94095b and fix bad attribute lookups (#274)

This commit is contained in:
Andrew Rynhard 2018-12-04 21:05:13 -08:00 committed by GitHub
parent 1bb002cb47
commit b3f12a23ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -85,6 +85,11 @@ func initram() error {
if err := rootfs.Prepare(constants.NewRoot, data); err != nil {
return err
}
// Unmount the ROOT and DATA block devices.
log.Println("unmounting the ROOT and DATA partitions")
if err := mount.Unmount(); err != nil {
return err
}
// Perform the equivalent of switch_root.
log.Println("entering the new root")
if err := switchroot.Switch(constants.NewRoot); err != nil {

View File

@ -4,6 +4,7 @@ package mount
import (
"fmt"
"log"
"os"
"path"
"strings"
@ -306,7 +307,7 @@ func appendBlockDeviceWithLabel(b *[]*BlockDevice, value string) error {
}
if devname == "" {
return fmt.Errorf("no device with attribute \"PartEntryName=%s\" found", value)
return fmt.Errorf("no device with attribute \"PART_ENTRY_NAME=%s\" found", value)
}
blockDevice, err := ProbeDevice(devname)
@ -319,7 +320,7 @@ func appendBlockDeviceWithLabel(b *[]*BlockDevice, value string) error {
return nil
}
// ProbeDevice looks up UUID/TYPE/LABEL/PartEntryName/PartEntryUUID from a block device
// ProbeDevice looks up UUID/TYPE/LABEL/PART_ENTRY_NAME/PART_ENTRY_UUID from a block device
func ProbeDevice(devname string) (*BlockDevice, error) {
pr, err := blkid.NewProbeFromFilename(devname)
defer blkid.FreeProbe(pr)
@ -336,13 +337,13 @@ func ProbeDevice(devname string) (*BlockDevice, error) {
}
Label, err := blkid.ProbeLookupValue(pr, "LABEL", nil)
if err != nil {
return nil, err
log.Printf("WARNING: %v", err)
}
PartEntryName, err := blkid.ProbeLookupValue(pr, "PartEntryName", nil)
PartEntryName, err := blkid.ProbeLookupValue(pr, "PART_ENTRY_NAME", nil)
if err != nil {
return nil, err
}
PartEntryUUID, err := blkid.ProbeLookupValue(pr, "PartEntryUUID", nil)
PartEntryUUID, err := blkid.ProbeLookupValue(pr, "PART_ENTRY_UUID", nil)
if err != nil {
return nil, err
}

View File

@ -57,15 +57,15 @@ func (b *BareMetal) UserData() (data userdata.UserData, err error) {
if option == constants.UserDataCIData {
var devname string
devname, err = blkid.GetDevWithAttribute("PARTLABEL", constants.UserDataCIData)
devname, err = blkid.GetDevWithAttribute("LABEL", constants.UserDataCIData)
if err != nil {
return data, fmt.Errorf("failed to find %s volume: %v", constants.UserDataCIData, err)
return data, fmt.Errorf("failed to find %s iso: %v", constants.UserDataCIData, err)
}
if err = os.Mkdir(mnt, 0700); err != nil {
return data, fmt.Errorf("failed to mkdir: %v", err)
}
if err = unix.Mount(devname, mnt, "iso9660", unix.MS_RDONLY, ""); err != nil {
return data, fmt.Errorf("failed to mount: %v", err)
return data, fmt.Errorf("failed to mount iso: %v", err)
}
var dataBytes []byte
dataBytes, err = ioutil.ReadFile(path.Join(mnt, "user-data"))

View File

@ -86,6 +86,10 @@ func getDev(fd int) (dev uint64, err error) {
// partitions are already mounted. See
// https://github.com/karelzak/util-linux/blob/master/sys-utils/switch_root.c
func Switch(s string) error {
// Mount the ROOT and DATA block devices at the new root.
if err := mount.Mount(s); err != nil {
return errors.Wrap(err, "error mounting block device")
}
// Move the special mount points to the new root.
if err := mount.Move(s); err != nil {
return errors.Wrap(err, "error moving special devices")