minix/commands/simple/newroot.c
Thomas Veerman b47483433c Added a hack to start binaries from the boot image only. In particular, setting
bin_img=1 in the boot monitor will make sure that during the boot procedure the
mfs binary that is part of the boot image is the only binary that is used to
mount partitions. This is useful when for some reason the mfs binary on disk 
malfunctions, rendering Minix unable to boot. By setting bin_img=1, the binary
on disk is ignored and the binary in the boot image is used instead.

- 'service' now accepts an additional flag -r. -r implies -c. -r instructs RS
  to first look in memory if the binary has already been copied to memory and
  execute that version, instead of loading the binary from disk. For example,
  the first time a MFS is being started it is copied (-c) to memory and
  executed from there. The second time MFS is being started this way, RS will
  look in memory for a previously copied MFS binary and reuse it if it exists.
- The mount and newroot commands now accept an additional flag -i, which
  instructs them to set the MS_REUSE flag in the mount flags.
- The mount system call now supports the MS_REUSE flag and invokes 'service'
  with the -r flag when MS_REUSE is set.
- /etc/rc and the rc script that's included in the boot image check for the
  existence of the bin_img flag in the boot monitor, and invoke mount and 
  newroot with the -i flag accordingly.
2009-08-18 11:36:01 +00:00

45 lines
829 B
C

/*
newroot.c
Replace the current root with a new one
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
void usage(void) {
fprintf(stderr, "Usage: newroot [-i] <block-special>\n");
fprintf(stderr, "-i: copy mfs binary from boot image to memory\n");
exit(1);
}
int main(int argc, char *argv[])
{
int r;
char *dev;
int mountflags;
r = 0;
mountflags = 0; /* !read-only */
if (argc != 2 && argc != 3) usage();
if(argc == 2) {
dev = argv[1];
} else if(argc == 3) {
/* -i flag was supposedly entered. Verify.*/
if(strcmp(argv[1], "-i") != 0) usage();
mountflags |= MS_REUSE;
dev = argv[2];
}
r = mount(dev, "/", mountflags, NULL, NULL);
if (r != 0) {
fprintf(stderr, "newroot: mount failed: %s\n",strerror(errno));
exit(1);
}
return 0;
}