Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <error.h>
- #include <limits.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/mount.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- extern char **environ;
- #define _error error
- int main (int argc, const char * const argv[])
- {
- static const char * const root = "/dev/md/Volume0_0p3";
- static const char * const rootfs = "xfs";
- char real_root[PATH_MAX];
- int retval = EXIT_SUCCESS;
- pid_t child;
- // mount /sys and /proc
- if (mount("proc", "/proc", "proc", MS_MGC_VAL, NULL) == -1)
- { _error(0, errno, "mount -t proc proc /proc failed with error %d", errno); return errno; }
- if (mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL) == -1)
- { _error(0, errno, "mount -t sysfs sysfs /sys failed with error %d", errno); return errno; }
- _error(0, 0, "Success mounting /proc and /sys\n");
- // run mdadm
- child = vfork();
- if (child == 0) { execl("/sbin/mdadm", "/sbin/mdadm", "--assemble", "--scan", "--auto=mdp", NULL); }
- else
- {
- siginfo_t info;
- waitid(P_PID, child, &info, WEXITED);
- retval = info.si_status;
- }
- if (retval != EXIT_SUCCESS) { _error(0, 0, "mdadm --assemble --scan --auto=mdp exited with status %d, aborting.\n", retval); return retval; }
- _error(0, 0, "Finished assembling RAID arrays\n");
- sync();
- // mount /
- if (realpath(root, real_root) == NULL)
- { _error(0, errno, "realpath %s failed with error %d", root, errno); return errno; }
- if (mount(real_root, "/mnt", rootfs, MS_MGC_VAL, NULL) == -1)
- _error(0, 0, "Success mounting /\n");
- sync();
- // run init
- retval = execl("/sbin/switch_root", "/sbin/switch_root", "/mnt", "sbin/init", NULL);
- if (retval == -1) { _error(0, errno, "/sbin/switch_root /mnt /sbin/init failed with error %d", errno); return errno; }
- else if (retval != EXIT_SUCCESS) { _error(0, 0, "/sbin/switch_root /mnt /sbin/init exited with status %d, aborting.\n", retval); return retval; }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement