Posts

Showing posts from January, 2023

Creating a bootable hard-disk image with Grub2

Here's a shell script for creating a bootable hard-disk image with Grub2 (v2.06). You need parted, kpartx and grub2. It's a derived version of original script here . # Create the actual disk image - 20MB dd if=/dev/zero of=disk.img count=20 bs=1048576   # Make the partition table, partition and set it bootable. parted --script disk.img mklabel msdos mkpart p ext2 1 100% set 1 boot on   # Map the partitions from the image file kpartx -a disk.img   # sleep a sec, wait for kpartx to create the device nodes sleep 1   # Make an ext2 filesystem on the first partition. mkfs.ext2 /dev/mapper/loop0p1   # Make the mount-point mkdir -p /mnt   # Mount the filesystem via loopback mount /dev/mapper/loop0p1 /mnt   # Copy in the files from the staging directory # cp -r build/* /mnt   # Create a device map for grub mkdir -p /mnt/boot/grub echo "(hd0) /dev/loop0" > /mnt/boot/grub/device.map # Use grub2-install to actually install Grub. The options are: #   * No floppy polling. #   *

Towards GNU/MINIX - Cross-compiler

Image
Cross-compiled executable running on Minix   In this post, we will cross compile a binary on Linux using GNU tools and run the same in Minix with a minimal setup. Build a generic cross-compiler You can build a generic ELF compiler for x86 platform following the instructions here .   Copy C runtime files from the distribution CD. $PREFIX and $TARGET are variables set in previous step. $ sudo kpartx -a myos.iso $ sudo mount /dev/mapper/loop0p3 -t minix /mnt $ mkdir usr $ cp /mnt/lib usr $ cp /mnt/include usr $ sudo umount /mnt $ ln -s $PWD/usr $PREFIX/$TARGET/   Create hello.c  #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) {  printf("Hello\n");  return 0; }   Compile and link hello.c . Use -static for static linking and -dynamic-linker /usr/libexec/ld.elf_so (use appropriate ld path) for dynamic linking. $ i686-elf-gcc -o hello.o -c hello.c $ i686-elf-ld -static -m elf_i386 -o hello -L./usr/lib ./usr/lib/crt0.o ./usr/lib/crti.o ./usr/

Towards GNU/MINIX - Bootloader

Image
  GNU/MINIX = GNU Tools with MINIX kernel Repackage MINIX 3.3 kernel to boot with GRUB 2.06 MINIX CD has three partitions - boot, ramdisk image and usr filesystem image. It uses NetBSD bootloader and userland tools. $ sudo sfdisk -l minix.iso  Disk minix.iso: 577.53 MiB, 605581312 bytes, 1182776 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x00000000 Device     Boot Start     End Sectors   Size Id Type minix.iso1          0   12287   12288     6M 81 Minix / old Linux minix.iso2      12288   82087   69800  34.1M 81 Minix / old Linux minix.iso3      82088 1182775 1100688 537.4M 81 Minix / old Linux   Extract files required for booting from boot partition by mounting it and copy the files to isodir . $ sudo mount minix.iso /mnt mount: /mnt: WARNING: source write-protected, mounted read-only. $ ls /mnt boot      mod01_ds  mod04_sched   mod07_tty  m