Skip to content

Pyoyeongjong/pintfs

Repository files navigation

Pintfs

A tiny educational filesystem module project implemented for Linux 5.10 kernel. Most design and implementation of this project were inspired by Ext2 Filesystem

Project Overview

  • mkfs.pintfs.c – Initializes the file disk.
  • Implemented minimal filesystem components: super, dir, inode, file, namei.
  • Compatible with Linux kernel 5.10.219v.
  • Reference: ext2 filesystem.

Features

  • Supports common Linux file-related commands (e.g., touch, echo, cat, rm, mkdir).
  • Works as a kernel module (pintfs.ko) mountable with loopback devices.
  • ⚠️ Known limitations:
    • vi is not supported for editing files.
    • Bug: after rm file, removing the parent directory with rmdir fails.

How to use

Setup Linux

// Install Linux
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.219.tar.xz
tar -xf linux-5.10.219.tar.xz

// Linux Kernel Image compile
cd linux-5.10.219
make defconfig
make -j$(nproc) bzImage
make modules
make modules_prepare

Module Compile

Update KDIR in Makefile to your kernel source path.

cd ~/project/pintfs
make

Initialize Qemu

// Install Qemu
sudo apt update
sudo apt install qemu-system-x86 qemu-utils

// Minimal Debian
sudo apt install debootstrap
sudo debootstrap --arch=amd64 stable ./rootfs http://deb.debian.org/debian

// Qemu Disk Image
qemu-img create rootfs.img 2G
mkfs.ext4 rootfs.img
sudo mkdir /mnt/tmp
sudo mount -o loop rootfs.img /mnt/tmp
sudo cp -a rootfs/* /mnt/tmp

// Remove ID/Password in Qemu
sudo vi /mnt/rfs/etc/passwd
root:x:0:0:root:/root:/bin/bash -> root::0:0:root:/root:/bin/bash 
sudo umount /mnt/tmp

Make raw disks for pintfs and move into Qemu with kernal module

// Make pintdisk.raw Image
gcc -o mkfs.pintfs mkfs.pintfs.c
dd if=/dev/zero of=pintdisk.raw bs=4k count=64 //256kb
sudo ./mkfs.pintfs pintdisk.raw

// pintfs.ko -> rootfs.img
sudo mount -o loop rootfs.img /mnt/tmp
sudo cp pintfs.ko /mnt/tmp/root

// pintdisk.raw -> rootfs.img
sudo cp pintdisk.raw /mnt/tmp/root/
sudo umount /mnt/rfs

Run Qemu

qemu-system-x86_64 \
  -kernel /root/linux-5.10.219/arch/x86/boot/bzImage \
  -drive file=rootfs.img,format=raw,index=0,media=disk \
  -append "root=/dev/sda console=ttyS0 rw" \
  -nographic

Inside Qemu

Id: root

insmod pintfs.ko
mkdir test
mount -o loop,rw -t pintfs pintdisk.raw test
mount | grep pintfs
cd test

Then, enjoy!

🚀 How to make file

touch file
echo hello >> file
cat file

About

This is very very simple linux filesystem.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published