diff --git a/.gitignore b/.gitignore index 63ce824..217cb8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /starter/alpine-make-rootfs/ /run +/starter/shared /starter/starter /starter/minrootfs /pkg/go/gen diff --git a/Makefile b/Makefile index 755f2f8..5db88f0 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ all: make generate init: git clone https://github.com/alpinelinux/alpine-make-rootfs + rm -rf starter/minrootfs mv alpine-make-rootfs starter/alpine-make-rootfs mkrootfs: starter/create_rootfs.sh diff --git a/starter/create_rootfs.sh b/starter/create_rootfs.sh index ea1349b..6bf6e9b 100755 --- a/starter/create_rootfs.sh +++ b/starter/create_rootfs.sh @@ -2,7 +2,7 @@ if [[ $(whoami) != root ]] then - echo "run as root please" + echo -e "\e[38;5;1mrun as root please\e[0m" exit fi diff --git a/starter/ns_exec.c b/starter/ns_exec.c index e7c9a09..23e0154 100644 --- a/starter/ns_exec.c +++ b/starter/ns_exec.c @@ -20,12 +20,12 @@ void mnt_prepare(char* rootfs, char* shared_mountpoint) { char* shared_folder=NULL; asprintf(&shared_folder,"../%s",shared_mountpoint); if (mount(rootfs,rootfs,"ext4",MS_BIND,"")) die("failed to mount %s: %m", rootfs); - //if (mount(shared_mountpoint,shared_mountpoint,"ext4",MS_BIND,"")) die("failed to mount %s: %m",shared_mountpoint); + //if (mount(shared_mountpoint,shared_mountpoint,"ext4",MS_BIND,"")) die("failed to mount %s: %m",shared_mountpoint); if (chdir(rootfs)) die("falied to cd:%m"); - if (mount("/sys","sys","sysfs",0,"")) die("failed to mount: %m"); - //if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m"); - if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir %s: %m\n", shared_mountpoint); - if (mount(shared_folder,"shared","ext4",MS_BIND,"")) die("failed to mount: %m"); + //if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m"); + //if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m"); + if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir %s: %m\n", shared_mountpoint); + if (mount(shared_folder,"shared","ext4",MS_BIND,"")) die("failed to mount shared folder: %m"); if (mkdir(put_old, 0000) && errno != EEXIST) die("Failed to mkdir %s: %m\n", put_old); if (syscall(SYS_pivot_root, ".", put_old)) die("Failed to pivot_root from %s to %s: %m\n", rootfs, put_old); if (chdir("/")) die("Failed to chdir to new root: %m\n"); @@ -57,9 +57,9 @@ static int nsrun(void* arg) { struct params *params = (struct params*) arg; await_setup(params->fd[0]); if(chdir("shared")) die("failed to chdir: %m"); - int out_fd=open("out",O_WRONLY|O_CREAT); - if(out_fd==-1) die("unable to open out file:%m"); - else dup2(out_fd,STDOUT_FILENO); + //int out_fd=open("out",O_WRONLY|O_CREAT); + //if(out_fd==-1) die("unable to open out file:%m"); + //else dup2(out_fd,STDOUT_FILENO); if(chdir("..")) die("failed to chdir: %m"); mnt_prepare("minrootfs",params->shared_folder); sethostname(hostname,sizeof(hostname));