Browse Source

boot: switch to tar ramdisks

K. Lange 1 year ago
parent
commit
31af34c73d
5 changed files with 67 additions and 12 deletions
  1. 2 6
      Makefile
  2. 1 1
      boot/cstuff.c
  3. 2 2
      kernel/sys/version.c
  4. 58 0
      util/createramdisk.py
  5. 4 3
      util/qemu.sh

+ 2 - 6
Makefile

@@ -217,12 +217,8 @@ base/bin/%.sh: apps/%.sh
 	chmod +x $@
 
 # Ramdisk
-
-util/devtable: ${RAMDISK_FILES} $(shell find base) util/update-devtable.py
-	util/update-devtable.py
-
-fatbase/ramdisk.img: ${RAMDISK_FILES} $(shell find base) Makefile util/devtable | dirs
-	genext2fs -B 4096 -d base -D util/devtable -U -b `util/calc-size.sh` -N 2048 $@
+fatbase/ramdisk.img: ${RAMDISK_FILES} $(shell find base) Makefile util/createramdisk.py | dirs
+	python3 util/createramdisk.py
 
 # CD image
 

+ 1 - 1
boot/cstuff.c

@@ -34,7 +34,7 @@ EFI_HANDLE ImageHandleIn;
 #define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos"
 
 /* Boot command line strings */
-#define DEFAULT_ROOT_CMDLINE "root=/dev/ram0,nocache "
+#define DEFAULT_ROOT_CMDLINE "root=/dev/ram0 root_type=tar "
 #define DEFAULT_GRAPHICAL_CMDLINE "start=live-session "
 #define DEFAULT_SINGLE_CMDLINE "start=terminal\037-F "
 #define DEFAULT_TEXT_CMDLINE "start=--vga "

+ 2 - 2
kernel/sys/version.c

@@ -17,8 +17,8 @@ char * __kernel_version_format = "%d.%d.%d-%s";
 
 /* Version numbers X.Y.Z */
 int    __kernel_version_major = 1;
-int    __kernel_version_minor = 9;
-int    __kernel_version_lower = 5;
+int    __kernel_version_minor = 10;
+int    __kernel_version_lower = 0;
 
 /* Kernel build suffix, which doesn't necessarily
  * mean anything, but can be used to distinguish

+ 58 - 0
util/createramdisk.py

@@ -0,0 +1,58 @@
+#!/usr/bin/python3
+"""
+Generates, from this source repository, a "tarramdisk" - a ustar archive
+suitable for booting ToaruOS. 
+"""
+
+import tarfile
+
+users = {
+    'root': 0,
+    'local': 1000,
+}
+
+restricted_files = {
+    'etc/master.passwd': 0o600,
+    'etc/sudoers': 0o600,
+    'tmp': 0o777,
+    'var': 0o755,
+    'bin/sudo': 0o4555,
+    'bin/gsudo': 0o4555,
+}
+
+def file_filter(tarinfo):
+    # Root owns files by default.
+    tarinfo.uid = 0
+    tarinfo.gid = 0
+
+    if tarinfo.name.startswith('home/'):
+        # Home directory contents are owned by their users.
+        user = tarinfo.name.split('/')[1]
+        tarinfo.uid = users.get(user,0)
+        tarinfo.gid = tarinfo.uid
+    elif tarinfo.name in restricted_files:
+        tarinfo.mode = restricted_files[tarinfo.name]
+
+    if tarinfo.name.startswith('src'):
+        # Let local own the files here
+        tarinfo.uid = users.get('local')
+        tarinfo.gid = tarinfo.uid
+        # Skip object files
+        if tarinfo.name.endswith('.so') or tarinfo.name.endswith('.o'):
+            return None
+
+    return tarinfo
+
+with tarfile.open('fatbase/ramdisk.img','w') as ramdisk:
+    ramdisk.add('base',arcname='/',filter=file_filter)
+
+    ramdisk.add('.',arcname='/src',filter=file_filter,recursive=False) # Add a src directory
+    ramdisk.add('apps',arcname='/src/apps',filter=file_filter)
+    ramdisk.add('kernel',arcname='/src/kernel',filter=file_filter)
+    ramdisk.add('linker',arcname='/src/linker',filter=file_filter)
+    ramdisk.add('lib',arcname='/src/lib',filter=file_filter)
+    ramdisk.add('libc',arcname='/src/libc',filter=file_filter)
+    ramdisk.add('boot',arcname='/src/boot',filter=file_filter)
+    ramdisk.add('modules',arcname='/src/modules',filter=file_filter)
+
+

+ 4 - 3
util/qemu.sh

@@ -25,9 +25,10 @@ fatbase/mod/pcnet.ko,\
 fatbase/mod/rtl.ko,\
 fatbase/mod/e1000.ko,\
 fatbase/mod/pcspkr.ko,\
-fatbase/mod/portio.ko \
--append "root=/dev/hda vid=qemu" \
--hda fatbase/ramdisk.img \
+fatbase/mod/portio.ko,\
+fatbase/mod/tarfs.ko,\
+fatbase/ramdisk.img \
+-append "root=/dev/ram0 root_type=tar logtoserial=2 vid=qemu" \
 -enable-kvm \
 -serial mon:stdio \
 -m 1G -soundhw ac97,pcspk