[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Make sure we still have an elf interpreter after unmounting fs (#598222)



When moving to stage2 we rename the initrd /lib to /lib_old and add
a symlink from /lib to /mnt/runtime/lib. When shutting down we unmount
filesystems and then after unmount try to run mdadm to wait for
any Intel BIOS RAID arrays to have their metadata updated that they
were cleanly shutdown to avoid a resync of the entire array on the next boot.

But at this point /lib is a dangling symlink, so no elf interpreter gets
found (nor libc) and the mdadm call we do fails, leaving the array unclean.
---
 loader/shutdown.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/loader/shutdown.c b/loader/shutdown.c
index 3b481f2..8177399 100644
--- a/loader/shutdown.c
+++ b/loader/shutdown.c
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <sys/reboot.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 #include "init.h"
@@ -50,6 +51,7 @@ static void performTerminations(void) {
 
 static void performUnmounts(void) {
 	int ignore;
+	struct stat st_buf;
 
 	printf("disabling swap...\n");
 	disableSwap();
@@ -57,6 +59,24 @@ static void performUnmounts(void) {
 	printf("unmounting filesystems...\n"); 
 	unmountFilesystems();
 
+	/* We've lost /mnt/runtime where /lib is a link to put the old
+	   /lib back so that our mdadm invocation below works. */
+	if (stat("/lib64", &st_buf) == 0) {
+		if (unlink("/lib64"))
+			perror("unlink /lib64");
+		if (rename("/lib64_old", "/lib64"))
+			perror("rename /lib64_old /lib64");
+	} else {
+		if (unlink("/lib"))
+			perror("unlink /lib");
+		if (rename("/lib_old", "/lib"))
+			perror("rename /lib_old /lib");
+	}
+	if (unlink("/usr"))
+		perror("unlink /usr");
+	if (rename("/usr_old", "/usr"))
+		perror("rename /usr_old /usr");
+
 	printf("waiting for mdraid sets to become clean...\n"); 
 	ignore = system("/sbin/mdadm --wait-clean --scan");
 }
-- 
1.7.0.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]