Towards GNU/MINIX - Filesystem


In this post, we will look at populating Minix filesystem with some files of our own (specifically the welcome message) using GNU tools.

Extract files from distribution CD into three folders - isodir, root.dir and usr.dir.

Create a text file grub-hd.cfg . p0 denotes first partition.

insmod part_msdos

menuentry "GNU MINIX 3" {

    multiboot /kernel rootdevname=c0d0p0 verbose=1
    
    module /mod01_ds
    module /mod02_rs
    module /mod03_pm
    module /mod04_sched
    module /mod05_vfs
    module /mod06_memory
    module /mod07_tty
    module /mod08_mfs
    module /mod09_vm
    module /mod10_pfs
    module /mod11_init
}
 

Create a text file partition.txt for your partition definition .

label: dos
label-id: 0x40fbf996
device: minix.img
unit: sectors
sector-size: 512

minix.img1 : start=        2048, size=         +64M, type=81, bootable
 

 

The script below will create a disk image. Then create a Minix partition (code 81). For creating the filesystem (MinixFS v3), you'll need a patched version (mfs branch) of mkfs.minix.

# Create the actual disk image - 20MB
dd if=/dev/zero of=minix.img count=137586 bs=1024
 
# Make the partition table, Minix partition and set it bootable.
sfdisk minix.img < partition.txt

# Map the partitions from the image file
kpartx -a minix.img
 
# sleep a sec, wait for kpartx to create the device nodes
sleep 1
 
# Make a Minix filesystem on the first partition.
../util-linux/mkfs.minix -3 /dev/mapper/loop0p1 -i 8000 137586
# mkfs.minix -3 /dev/mapper/loop0p1 -i 8000 137586

# Make the mount-point
# mkdir -p /mnt
 
# Mount the filesystem via loopback
mount /dev/mapper/loop0p1 -t minix /mnt
 
# Copy in the files from the staging directory
cp isodir/* /mnt
cp -r root.dir/* /mnt
cp -r usr.dir/libexec /mnt/usr/
echo "Welcome to GeM OS" > /mnt/etc/issue
echo "/dev/c0d0p0 / minix rw,relatime,errors=remount-ro 0 0" > /mnt/etc/fstab

# Create a device map for grub
rm /mnt/boot
mkdir -p /mnt/boot/grub
echo "(hd0) /dev/loop0" > /mnt/boot/grub/device.map
cp grub-hd.cfg /mnt/boot/grub/grub.cfg

# Use grub2-install to actually install Grub. The options are:
#   * No floppy polling.
#   * Use the device map we generated in the previous step.
#   * Include the basic set of modules we need in the Grub image.
#   * Install grub into the filesystem at our loopback mountpoint.
#   * Install the MBR to the loopback device itself.
grub-install --no-floppy               \
         --target=i386-pc          \
             --root-directory=/mnt     \
             /dev/loop0
 
# Unmount the loopback
# umount /mnt

# mount /dev/mapper/loop0p2 /mnt
# cp -r hddir/* /mnt
umount /mnt

# Unmap the image
kpartx -d minix.img
 


Now you can boot the image in Qemu.

$ kvm minix.img
 

Lessons learnt

  • Main differences between various MinixFS versions are - magic number and block size. Version 3 supports block size of 4k bytes whereas previous versions support only 1k blocks.
  • Filesystem dictates the maximum size of object it can store. MinixFS v3 limit is 64M.
  • Number of Inodes decides the maximum number of files and directories that can be created in a partition. This is specified/decided at the time of creation of filesystem.
  • If you are seeing an unrelated malloc.c issue while using GDB, chances are you are overwriting some memory blocks.
  • /etc/issue is displayed before the login prompt and /etc/motd is displayed after login.
 

References



 

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

Tinylisp and Multi-threaded Emacs

GNU Emacs as a Shopping App