From e94095b0f35b6c53d8602420edc1943ae2f64eee Mon Sep 17 00:00:00 2001 From: Andrew Rynhard Date: Sat, 1 Dec 2018 15:41:39 -0800 Subject: [PATCH] refactor(init): remove unnecessary unmount/mount (#246) --- src/initramfs/cmd/init/main.go | 9 +-------- src/initramfs/cmd/init/pkg/switchroot/switchroot.go | 7 ++----- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/initramfs/cmd/init/main.go b/src/initramfs/cmd/init/main.go index c1bacd98c..f0db350aa 100644 --- a/src/initramfs/cmd/init/main.go +++ b/src/initramfs/cmd/init/main.go @@ -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 } diff --git a/src/initramfs/cmd/init/pkg/switchroot/switchroot.go b/src/initramfs/cmd/init/pkg/switchroot/switchroot.go index c3ab217f4..8c77b2831 100644 --- a/src/initramfs/cmd/init/pkg/switchroot/switchroot.go +++ b/src/initramfs/cmd/init/pkg/switchroot/switchroot.go @@ -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")