Tutorial on how to create you own very simple Operating System I have created an indepth detailed instructions on how to install the packages needed. Hopefully, this simplifies the process so that you may be on your journey to further learn on how and OS works at the most basic, simplistic of levels, if there is such a thing.
cfenollosa/os-tutorial Also special thanks to my mentor Swati Gupta github/guptaNswati Who guided me along through my bumps in creating my very first simple OS.
- Open a terminal and run vagrant box list will print the list of boxes available on the computers.
vagrant box list
- #1
vagrant init
- #2
Open
Vagrantfile
and replace where it saysbase
withubuntu/trusty64
as we are running Ubuntu in this VM. Save file - #3
Run
vagrant up
- #4
Run
vagrant ssh
- You are in your Virtual Machine!!!
- More Info:
- VM wiki
QEMU is a generic and open source machine emulator and virtualizer. The Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture. It can be used to write 16-bit, 32-bit (IA-32) and 64-bit (x86-64) programs. NASM is considered to be one of the most popular assemblers for Linux.
sudo apt-get install build-essential qemu nasm
- QEMU
The GNU Compiler Collection is an advanced piece of software with dependencies. You need to install certain dependencies in order to build gcc.
- installing gmp
sudo apt-get install libgmp3-dev
- installing mpfr
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-db
- installing libmpc
sudo apt-get install libmpc-dev
- installing Make
sudo apt-get install make
- installing Texinfo
sudo apt-get install Texinfo
- installing Flex
sudo apt-get install Flex
- installing Bison
sudo apt-get install Bison
- More Info:
- GCC-CrossCompiler
we will put them into /usr/local/cross-compiler, so let's export some paths now. Feel free to change them to your liking.
export PREFIX="/usr/local/cross-compiler"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
mkdir /tmp/src
cd /tmp/src
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.30.tar.gz
tar xf binutils-2.30.tar.gz
mkdir binutils-build
cd binutils-build
../binutils-2.24/configure --target=$TARGET --enable-interwork --enable-multilib --disable-nls --disable-werror --prefix=$PREFIX 2>&1 | tee configure.log
sudo make all install 2>&1 | tee make.log
- More Info:
- GNU ORG
If the peak RAM used during installation is greater than that of EC2 micro instance. Use a larger instance or use swap. If you are using VM like myself you will need this step before proceeding with gcc.
SWAP=/tmp/swap
dd if=/dev/zero of=$SWAP bs=1M count=500
mkswap $SWAP
sudo swapon $SWAP
- More Info:
- StackOverFlow/Error
cd /tmp/src
curl -O https://ftp.gnu.org/gnu/gcc/gcc-4.9.1/gcc-4.9.1.tar.bz2
tar xvfj gcc-4.9.1.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.9.1/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-libssp --enable-languages=c --without-headers
sudo make all-gcc
sudo make all-target-libgcc
sudo make install-gcc
sudo make install-target-libgcc
ls /usr/local/cross-compiler/bin
, prefixed by i686-elf-
i686-elf-gcc -ffreestanding -c kernel.c -o kernel.o
nasm kernel_start.asm -f elf -o kernel_start.o
i686-elf-ld -o kernel.bin -Ttext 0x1000 kernel_start.o kernel.o --oformat binary
nasm bootsector.asm -f bin -o bootsector.bin
cat bootsector.bin kernel.bin > os-image.bin
directly copy kernel.bin to the first sector of the floppy disk image
dd status=noxfer conv=notrunc if=os-image.bin of=disk.flp
qemu-system-x86_64 -curses -fda os-image.bin
alt+2
, enter quit
rm *.bin *.o *.img *.flp *.iso
rm -rf cdromiso