refactor(init): remove unnecessary unmount/mount (#246)

This commit is contained in:
Andrew Rynhard
2018-12-01 15:41:39 -08:00
committed by GitHub
parent c171c51c5c
commit e94095b0f3
2 changed files with 3 additions and 13 deletions

View File

@@ -51,8 +51,7 @@ func initram() error {
return err
}
// Setup logging to /dev/kmsg.
var f *os.File
f, err := kmsg("[talos] [initramfs]")
_, err := kmsg("[talos] [initramfs]")
if err != nil {
return err
}
@@ -86,14 +85,8 @@ 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")
f.Close() // nolint: errcheck
if err := switchroot.Switch(constants.NewRoot); err != nil {
return err
}

View File

@@ -82,13 +82,10 @@ func getDev(fd int) (dev uint64, err error) {
return stat.Dev, nil
}
// Switch performs a switch_root equivalent. See
// Switch performs a switch_root. The caller must ensure that the ROOT and DATA
// 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")