summaryrefslogtreecommitdiff
path: root/cdinit.c
diff options
context:
space:
mode:
authorElizabeth Myers <elizabeth@interlinked.me>2017-12-12 06:17:38 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2017-12-12 16:17:57 -0600
commit7e161c48db4f3858a660f9ca0cb712d1724bc807 (patch)
tree9ad5eeb65cfb03b93cd5a89f819d5f4a16fd5462 /cdinit.c
parente3d6a5f56823fa375d4432dc1f078ac813618a15 (diff)
downloadimage-7e161c48db4f3858a660f9ca0cb712d1724bc807.tar.gz
image-7e161c48db4f3858a660f9ca0cb712d1724bc807.tar.bz2
image-7e161c48db4f3858a660f9ca0cb712d1724bc807.tar.xz
image-7e161c48db4f3858a660f9ca0cb712d1724bc807.zip
cdinit: use OverlayFS for root
Signed-off-by: A. Wilcox <AWilcox@Wilcox-Tech.com>
Diffstat (limited to 'cdinit.c')
-rw-r--r--cdinit.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/cdinit.c b/cdinit.c
index 2990106..44ba094 100644
--- a/cdinit.c
+++ b/cdinit.c
@@ -45,7 +45,7 @@ bool cdi_invoke(const char *command, const char *path, char * const argv[])
}
else if(our_pid == -1)
{
- fprintf(stdout, "[ !! ] failed to fork: %s\n", strerror(errno));
+ fprintf(stderr, "[ !! ] failed to fork: %s\n", strerror(errno));
return false;
}
else
@@ -55,14 +55,14 @@ bool cdi_invoke(const char *command, const char *path, char * const argv[])
waitpid(our_pid, &status, 0);
if(!WIFEXITED(status))
{
- fprintf(stdout, "[ !! ] %s caught signal\n", command);
+ fprintf(stderr, "[ !! ] %s caught signal\n", command);
return false;
}
code = WEXITSTATUS(status);
if(code != 0)
{
- fprintf(stdout, "[ !! ] %s exited with error code %d\n",
+ fprintf(stderr, "[ !! ] %s exited with error code %d\n",
command, code);
return false;
}
@@ -111,8 +111,8 @@ bool cdi_find_media(void)
first = udev_enumerate_get_list_entry(dev_list);
if(first == NULL)
{
- fprintf(stdout, "No block devices found.\n");
- fprintf(stdout, "This system cannot boot Adélie Linux "
+ fprintf(stderr, "No block devices found.\n");
+ fprintf(stderr, "This system cannot boot Adélie Linux "
"without additional drivers.\n");
return false;
}
@@ -193,7 +193,7 @@ bool cdi_find_media(void)
ioctl(dev_fd, LOOP_SET_FD, squash_fd);
close(squash_fd);
- if(mount("/dev/loop4", "/newroot", "squashfs", MS_RDONLY,
+ if(mount("/dev/loop4", "/lowerroot", "squashfs", MS_RDONLY,
NULL) != 0)
{
#ifdef DEBUG
@@ -216,7 +216,7 @@ bool cdi_find_media(void)
udev_enumerate_unref(dev_list);
udev_unref(udev);
- return (access("/newroot/sbin/init", F_OK) == 0);
+ return (access("/lowerroot/sbin/init", F_OK) == 0);
}
@@ -237,21 +237,21 @@ int main(void)
if(mount("none", "/dev", "devtmpfs", 0, NULL) != 0)
{
- fprintf(stdout, "FATAL: Can't mount devtmpfs at /dev: %s\n",
+ fprintf(stderr, "FATAL: Can't mount devtmpfs at /dev: %s\n",
strerror(errno));
return EXIT_FAILURE;
}
if(mount("none", "/proc", "proc", 0, NULL) != 0)
{
- fprintf(stdout, "FATAL: Can't mount early /proc: %s\n",
+ fprintf(stderr, "FATAL: Can't mount early /proc: %s\n",
strerror(errno));
return EXIT_FAILURE;
}
if(mount("none", "/sys", "sysfs", 0, NULL) != 0)
{
- fprintf(stdout, "FATAL: Can't mount early /sys: %s\n",
+ fprintf(stderr, "FATAL: Can't mount early /sys: %s\n",
strerror(errno));
return EXIT_FAILURE;
}
@@ -299,7 +299,7 @@ int main(void)
*/
if(!cdi_find_media())
{
- fprintf(stdout, "FATAL: no boot media found\n");
+ fprintf(stderr, "FATAL: no boot media found\n");
return EXIT_FAILURE;
}
@@ -308,6 +308,29 @@ int main(void)
cdi_invoke("clean up", "/sbin/udevadm", argv);
}
+ /* Create our OverlayFS mount, so everything is writable.
+ * TODO: USB-based persistence
+ */
+ if(mount("tmpfs", "/upperroot", "tmpfs", 0, NULL) != 0)
+ {
+ fprintf(stderr, "FATAL: could not mount tmpfs: %s\n",
+ strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ /* If this fails, we'll find out below */
+ mkdir("/upperroot/.overlay_work", S_IRWXU);
+
+ if(mount("overlay", "/newroot", "overlay", 0,
+ "lowerdir=/lowerroot,"
+ "upperdir=/upperroot,"
+ "workdir=/upperroot/.overlay_work") != 0)
+ {
+ fprintf(stderr, "FATAL: could not mount overlayfs: %s\n",
+ strerror(errno));
+ return EXIT_FAILURE;
+ }
+
mount("/dev", "/newroot/dev", NULL, MS_MOVE, NULL);
mount("/media", "/newroot/media/live", NULL, MS_MOVE, NULL);
mount("/proc", "/newroot/proc", NULL, MS_MOVE, NULL);
@@ -316,7 +339,7 @@ int main(void)
chdir("/newroot");
if(mount("/newroot", "/", NULL, MS_MOVE, NULL) != 0)
{
- fprintf(stderr, "could not pivot to /newroot: %s\n",
+ fprintf(stderr, "FATAL: could not pivot to /newroot: %s\n",
strerror(errno));
return EXIT_FAILURE;
}
@@ -324,6 +347,6 @@ int main(void)
chroot(".");
execl("/sbin/init", "init", (char *)0);
- fprintf(stdout, "Going nowhere without my new root's init\n");
+ fprintf(stderr, "Going nowhere without my new root's init\n");
return EXIT_FAILURE;
}