diff --git a/Chapter-2/README.md b/Chapter-2/README.md index 9902b37..d50cb01 100644 --- a/Chapter-2/README.md +++ b/Chapter-2/README.md @@ -17,27 +17,26 @@ Vagrant needs Virtualbox to work, Download and install for your system at https: ### Start and test your development environment -Once Vagrant and Virtualbox are installed, you need to download the ubuntu lucid32 image for Vagrant: +Once Vagrant and Virtualbox are installed, you need to download the ubuntu xenial64 image for Vagrant: ``` -vagrant box add lucid32 http://files.vagrantup.com/lucid32.box +vagrant init ubuntu/xenial64 ``` -Once the lucid32 image is ready, we need to define our development environment using a *Vagrantfile*, [create a file named *Vagrantfile*](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/Vagrantfile). This file defines what prerequisites our environment needs: nasm, make, build-essential, grub and qemu. - -Start your box using: - +Once the xenial64 image is ready, you only need to start your box with: ``` vagrant up ``` +The box should've been defined and configured automatically using the *Vagrantfile* created as part of the initialization of the xenial64 box. [This file](https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/src/Vagrantfile) defines what prerequisites our environment needs: nasm, make, build-essential, kpartx, grub-pc and qemu. + You can now access your box by using ssh to connect to the virtual box using: ``` vagrant ssh ``` -The directory containing the *Vagrantfile* will be mounted by default in the */vagrant* directory of the guest VM (in this case, Ubuntu Lucid32): +The directory containing the *Vagrantfile* will be mounted by default in the */vagrant* directory of the guest VM (in this case, Ubuntu xenial64): ``` cd /vagrant diff --git a/src/Makefile b/src/Makefile index a2f9073..4eb734a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ SDKDIR=./sdk help: @echo "Makefile for Building Dev Operating System." - @echo "Usage: make [ all | clean | help | build | run] " + @echo "Usage: make [ all | clean | help | build | run ]" @echo "" @echo diff --git a/src/Vagrantfile b/src/Vagrantfile index 046ab4c..1b4df4b 100644 --- a/src/Vagrantfile +++ b/src/Vagrantfile @@ -1,38 +1,38 @@ + # -*- mode: ruby -*- # vi: set ft=ruby : -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. - # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "lucid32" + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "ubuntu/xenial64" - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - config.vm.box_url = "http://files.vagrantup.com/lucid32.box" + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network :forwarded_port, guest: 80, host: 8080 + # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network, which allows host-only access to the machine # using a specific IP. - # config.vm.network :private_network, ip: "192.168.33.10" + # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. - # config.vm.network :public_network - - # If true, then any SSH connections made will enable agent forwarding. - # Default value: false - # config.ssh.forward_agent = true + # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is @@ -44,84 +44,29 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # - # config.vm.provider :virtualbox do |vb| - # # Don't boot with headless mode + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine # vb.gui = true # - # # Use VBoxManage to customize the VM. For example to change memory: - # vb.customize ["modifyvm", :id, "--memory", "1024"] + # # Customize the amount of memory on the VM: + # vb.memory = "1024" # end # - # View the documentation for the provider you're using for more + # View the documentation for the provider you are using for more # information on available options. - # Enable provisioning with Puppet stand alone. Puppet manifests - # are contained in a directory path relative to this Vagrantfile. - # You will need to create the manifests directory and a manifest in - # the file base.pp in the manifests_path directory. - # - # An example Puppet manifest to provision the message of the day: - # - # # group { "puppet": - # # ensure => "present", - # # } - # # - # # File { owner => 0, group => 0, mode => 0644 } - # # - # # file { '/etc/motd': - # # content => "Welcome to your Vagrant-built virtual machine! - # # Managed by Puppet.\n" - # # } - # - # config.vm.provision :puppet do |puppet| - # puppet.manifests_path = "manifests" - # puppet.manifest_file = "init.pp" - # end - - # Enable provisioning with chef solo, specifying a cookbooks path, roles - # path, and data_bags path (all relative to this Vagrantfile), and adding - # some recipes and/or roles. - # - # config.vm.provision :chef_solo do |chef| - # chef.cookbooks_path = "../my-recipes/cookbooks" - # chef.roles_path = "../my-recipes/roles" - # chef.data_bags_path = "../my-recipes/data_bags" - # chef.add_recipe "mysql" - # chef.add_role "web" - # - # # You may also specify custom JSON attributes: - # chef.json = { :mysql_password => "foo" } + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end - $script = %Q{ + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", inline: <<-SHELL sudo apt-get update - sudo apt-get install nasm make build-essential grub qemu zip -y - } - - - config.vm.provision :shell, :inline => $script - - - # Enable provisioning with chef server, specifying the chef server URL, - # and the path to the validation key (relative to this Vagrantfile). - # - # The Opscode Platform uses HTTPS. Substitute your organization for - # ORGNAME in the URL and validation key. - # - # If you have your own Chef Server, use the appropriate URL, which may be - # HTTP instead of HTTPS depending on your configuration. Also change the - # validation key to validation.pem. - # - # config.vm.provision :chef_client do |chef| - # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME" - # chef.validation_key_path = "ORGNAME-validator.pem" - # end - # - # If you're using the Opscode platform, your validator client is - # ORGNAME-validator, replacing ORGNAME with your organization name. - # - # If you have your own Chef Server, the default validation client name is - # chef-validator, unless you changed the configuration. - # - # chef.validation_client_name = "ORGNAME-validator" + sudo apt-get install -y build-essential make kpartx nasm qemu grub-pc grub-pc-bin + SHELL end diff --git a/src/sdk/bootdisk/boot/grub/device.map b/src/sdk/bootdisk/boot/grub/device.map new file mode 100644 index 0000000..08b70b9 --- /dev/null +++ b/src/sdk/bootdisk/boot/grub/device.map @@ -0,0 +1,2 @@ +(hd0) /dev/loop0 +(hd0,1) /dev/mapper/loop0p1 diff --git a/src/sdk/bootdisk/boot/grub/grub.cfg b/src/sdk/bootdisk/boot/grub/grub.cfg new file mode 100644 index 0000000..8ece05f --- /dev/null +++ b/src/sdk/bootdisk/boot/grub/grub.cfg @@ -0,0 +1,8 @@ +menuentry 'Dev Operating System (with init)'--class os { + insmod ext2 + linux /kernel.elf module /bin/hello +} +menuentry 'Dev Operating System'--class os { + insmod ext2 + linux /kernel.elf +} diff --git a/src/sdk/bootdisk/boot/grub/grub.conf b/src/sdk/bootdisk/boot/grub/grub.conf deleted file mode 100644 index 3e52044..0000000 --- a/src/sdk/bootdisk/boot/grub/grub.conf +++ /dev/null @@ -1,13 +0,0 @@ -default=0 -timeout=30 - -root (hd0,0) - -title=Dev Operating System (with init) - kernel /kernel.elf - module /bin/hello - boot - -title=Dev Operating System - kernel /kernel.elf - boot diff --git a/src/sdk/bootdisk/boot/grub/menu.lst b/src/sdk/bootdisk/boot/grub/menu.lst deleted file mode 100644 index dcdfe4b..0000000 --- a/src/sdk/bootdisk/boot/grub/menu.lst +++ /dev/null @@ -1,13 +0,0 @@ -default=0 -timeout=30 - -root (cd) - -title=Dev Operating System (with init) - kernel /kernel.elf - module /bin/hello - boot - -title=Dev Operating System - kernel /kernel.elf - boot diff --git a/src/sdk/bootdisk/boot/grub/stage1 b/src/sdk/bootdisk/boot/grub/stage1 deleted file mode 100644 index e5c292c..0000000 Binary files a/src/sdk/bootdisk/boot/grub/stage1 and /dev/null differ diff --git a/src/sdk/bootdisk/boot/grub/stage2 b/src/sdk/bootdisk/boot/grub/stage2 deleted file mode 100644 index 76483d4..0000000 Binary files a/src/sdk/bootdisk/boot/grub/stage2 and /dev/null differ diff --git a/src/sdk/bootdisk/boot/grub/stage2_eltorito b/src/sdk/bootdisk/boot/grub/stage2_eltorito deleted file mode 100644 index 558d4bb..0000000 Binary files a/src/sdk/bootdisk/boot/grub/stage2_eltorito and /dev/null differ diff --git a/src/sdk/c.img b/src/sdk/c.img deleted file mode 100644 index 0366a09..0000000 Binary files a/src/sdk/c.img and /dev/null differ diff --git a/src/sdk/diskimage.sh b/src/sdk/diskimage.sh index 6d1d3d5..5b9f7bf 100755 --- a/src/sdk/diskimage.sh +++ b/src/sdk/diskimage.sh @@ -1,36 +1,23 @@ #!/bin/bash -qemu-img create c.img 2M +qemu-img create c.img 16M fdisk ./c.img << EOF -x -c -4 -h -16 -s -63 -r n p 1 -1 -4 +2048 +32767 a -1 w EOF -fdisk -l -u ./c.img -losetup -o 32256 /dev/loop1 ./c.img - -mke2fs /dev/loop1 -mount /dev/loop1 /mnt/ -cp -R bootdisk/* /mnt/ -umount /mnt/ -grub --device-map=/dev/null << EOF -device (hd0) ./c.img -geometry (hd0) 4 16 63 -root (hd0,0) -setup (hd0) -quit -EOF - -losetup -d /dev/loop1 +kpartx -a ./c.img +echo ---------------------------------- +echo Detected loop partitions: +lsblk /dev/loop0 +mkfs.ext4 /dev/mapper/loop0p1 +mount /dev/mapper/loop0p1 /mnt +cp -R bootdisk/* /mnt +# TODO: Install grub2 +# As of now, nothing I've tried works. +# Still, the kernel sould be bootable, just not this image. +umount /mnt +kpartx -d /dev/loop0 diff --git a/src/sdk/qemu.sh b/src/sdk/qemu.sh index 753cf7b..a59ff9e 100755 --- a/src/sdk/qemu.sh +++ b/src/sdk/qemu.sh @@ -1,2 +1,2 @@ #!/bin/bash -qemu -m 1024 -s -hda ./c.img -curses -serial /dev/tty -redir tcp:2323::23 +qemu-system-i386 -m 512 -s -hda ./c.img -curses -serial /dev/tty -redir tcp:2323::23