Skip to content

Instantly share code, notes, and snippets.

Created March 13, 2016 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cb32986fd9b85c315ae4 to your computer and use it in GitHub Desktop.
Save anonymous/cb32986fd9b85c315ae4 to your computer and use it in GitHub Desktop.
--- o/supermin-5.1.15/init/init.c 2016-02-17 18:11:24.000000000 +0200
+++ supermin-5.1.15/init/init.c 2016-03-13 15:18:36.430069676 +0200
@@ -149,6 +149,7 @@
*/
char *root, *path;
size_t len;
+ int is_9p = !!strstr(cmdline, "rootfstype=9p");
root = strstr (cmdline, "root=");
if (root) {
root += 5;
@@ -157,14 +158,28 @@
len = strcspn (root, " ");
root[len] = '\0';
+ if (is_9p) {
+ if (verbose)
+ fprintf (stderr, "supermin: mounting new 9p root %son /root\n", root);
+ if (mount (root, "/root", "9p", MS_NOATIME, "trans=virtio,version=9p2000.L,cache=loose")) {
+ perror ("mount /root");
+ exit (EXIT_FAILURE);
+ }
+ if (verbose)
+ fprintf (stderr, "supermin: mounted new 9p root %son /root\n", root);
+ goto mounted;
+ }
+
asprintf (&path, "/sys/block/%s/dev", root);
uint64_t delay_ns = 250000;
int virtio_message = 0;
while (delay_ns <= MAX_ROOT_WAIT * UINT64_C(1000000000)) {
fp = fopen (path, "r");
- if (fp != NULL)
+ if (fp != NULL) {
+ root = NULL;
goto found;
+ }
if (delay_ns > 1000000000) {
fprintf (stderr,
@@ -203,7 +218,7 @@
}
fprintf (stderr,
- "supermin: no ext2 root device found\n"
+ "supermin: no ext2 or 9p root device found\n"
"Please include FULL verbose output in your bug report.\n");
exit (EXIT_FAILURE);
@@ -217,17 +232,6 @@
int minor = atoi (p);
fclose (fp);
- if (umount ("/sys") == -1) {
- perror ("umount: /sys");
- exit (EXIT_FAILURE);
- }
-
- /* Make current process the controlling process of the tty. */
- setsid ();
-#ifdef TIOCSCTTY
- if (ioctl (0, TIOCSCTTY, 1) == -1)
- perror ("ioctl: TIOCSCTTY");
-#endif
if (verbose)
fprintf (stderr, "supermin: creating /dev/root as block special %d:%d\n",
@@ -246,6 +250,18 @@
exit (EXIT_FAILURE);
}
+mounted:
+ if (umount ("/sys") == -1) {
+ perror ("umount: /sys");
+ exit (EXIT_FAILURE);
+ }
+ /* Make current process the controlling process of the tty. */
+ setsid ();
+#ifdef TIOCSCTTY
+ if (ioctl (0, TIOCSCTTY, 1) == -1)
+ perror ("ioctl: TIOCSCTTY");
+#endif
+
/* Note that pivot_root won't work. See the note in
* Documentation/filesystems/ramfs-rootfs-initramfs.txt
* We could remove the old initramfs files, but let's not bother.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment