Diff

Differences From Artifact [e11582ede8]:

To Artifact [c6b18551fb]:


41
42
43
44
45
46
47


48











49
50




51

























52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

	execv(path, argv);

	exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {


	/*











	 * Remount root filesystem read-write
	 */




	mount("/dev/vda2", "/", "ext4", MS_REMOUNT, NULL);


























	/*
	 * Mount needed filesystems
	 */
	mkdir("/dev", 0755);
	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);

	mkdir("/tmp", 0755);
	mount("tmpfs", "/tmp", "tmpfs", 0, NULL);

	mkdir("/proc", 0755);
	mount("proc", "/proc", "proc", 0, NULL);

	mkdir("/sys", 0755);
	mount("sysfs", "/sys", "sysfs", 0, NULL);

	/*
	 * Setup networking
	 */
	run("/bin/init-networking", "init-networking", NULL);
	run("/bin/init-fuse", "init-fuse", NULL);

	mkdir("/etc", 0755);
	mkdir("/bin", 0755);
	mkdir("/lib", 0755);
	mkdir("/opt", 0755);
	mkdir("/opt/appfs", 0755);

	mkdir("/var", 0755);
	mkdir("/var/cache", 0755);
	mkdir("/var/cache/appfs", 0755);
	mount("/dev/vda3", "/var/cache/appfs", "ext4", 0, NULL);

	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);

	symlink(".", "/usr");
	symlink("lib", "/lib64");

	symlink("/proc/self/mounts", "/etc/mtab");







>
>

>
>
>
>
>
>
>
>
>
>
>
|

>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




















<










<







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
122
123

124
125
126
127
128
129
130

	execv(path, argv);

	exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {
	int mount_ret;

	/*
	 * Load kernel modules (drivers)
	 */
	mkdir("/sys", 0755);
	mount("sysfs", "/sys", "sysfs", 0, NULL);

	run("/bin/init-modules", "init-modules", NULL);

	umount("/sys");
	rmdir("/sys");

	/*
	 * Mount root filesystem
	 */
	mkdir("/dev", 0755);
	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);

	mkdir("/new-root", 0755);
	mount_ret = mount("/dev/vda2", "/new-root", "ext4", 0, NULL);
	if (mount_ret != 0) {
		mount_ret = mount("/dev/sda2", "/new-root", "ext4", 0, NULL);
	}
	if (mount_ret != 0) {
		mount_ret = mount("/dev/hda2", "/new-root", "ext4", 0, NULL);
	}
	umount("/dev");
	rmdir("/dev");

	if (mount_ret == 0) {
		mkdir("/new-root/initramfs", 0755);
		mkdir("/new-root/bin", 0755);
		mkdir("/new-root/lib", 0755);
		symlink("../initramfs/bin/appfsd", "/new-root/bin/appfsd");
		symlink("../initramfs/bin/init", "/new-root/bin/init");
		symlink("../initramfs/bin/init-modules", "/new-root/bin/init-modules");
		symlink("../initramfs/bin/init-networking", "/new-root/bin/init-networking");
		symlink("../initramfs/bin/appfs-cache", "/new-root/bin/appfs-cache");
		symlink("../initramfs/bin/tclkit", "/new-root/bin/tclkit");
		symlink("../initramfs/lib/modules", "/new-root/lib/modules");
		chdir("/new-root");
		mount("/", "/new-root/initramfs", "bind", MS_BIND, NULL);
		chroot("/new-root");
		chdir("/");
	}

	/*
	 * Mount needed filesystems
	 */
	mkdir("/dev", 0755);
	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);

	mkdir("/tmp", 0755);
	mount("tmpfs", "/tmp", "tmpfs", 0, NULL);

	mkdir("/proc", 0755);
	mount("proc", "/proc", "proc", 0, NULL);

	mkdir("/sys", 0755);
	mount("sysfs", "/sys", "sysfs", 0, NULL);

	/*
	 * Setup networking
	 */
	run("/bin/init-networking", "init-networking", NULL);


	mkdir("/etc", 0755);
	mkdir("/bin", 0755);
	mkdir("/lib", 0755);
	mkdir("/opt", 0755);
	mkdir("/opt/appfs", 0755);

	mkdir("/var", 0755);
	mkdir("/var/cache", 0755);
	mkdir("/var/cache/appfs", 0755);


	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);

	symlink(".", "/usr");
	symlink("lib", "/lib64");

	symlink("/proc/self/mounts", "/etc/mtab");
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
	run("/bin/appfs-cache", "appfs-cache", "install", "-lib", "core.appfs.rkeene.org", "glibc", NULL);
	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "coreutils", NULL);
	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "procps-ng", NULL);
	setenv("PATH", "/bin", 1);

	run("/bin/sh", "sh", NULL);

	/*
	 * Remount root filesystem read-only
	 */
	umount("/dev");
	umount("/tmp");
	umount("/proc");
	umount("/sys");
	umount("/opt/appfs");
	umount("/var/cache/appfs");
	mount("/dev/vda2", "/", "ext4", MS_REMOUNT | MS_RDONLY, NULL);
	sync();

	return(0);
}







<
<
<
<
<
<
<
<
<
<




138
139
140
141
142
143
144










145
146
147
148
	run("/bin/appfs-cache", "appfs-cache", "install", "-lib", "core.appfs.rkeene.org", "glibc", NULL);
	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "coreutils", NULL);
	run("/bin/appfs-cache", "appfs-cache", "install", "core.appfs.rkeene.org", "procps-ng", NULL);
	setenv("PATH", "/bin", 1);

	run("/bin/sh", "sh", NULL);











	sync();

	return(0);
}