Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Ubuntu Xenial/Grub2 #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Chapter-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
125 changes: 35 additions & 90 deletions src/Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions src/sdk/bootdisk/boot/grub/device.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(hd0) /dev/loop0
(hd0,1) /dev/mapper/loop0p1
8 changes: 8 additions & 0 deletions src/sdk/bootdisk/boot/grub/grub.cfg
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 0 additions & 13 deletions src/sdk/bootdisk/boot/grub/grub.conf

This file was deleted.

13 changes: 0 additions & 13 deletions src/sdk/bootdisk/boot/grub/menu.lst

This file was deleted.

Binary file removed src/sdk/bootdisk/boot/grub/stage1
Binary file not shown.
Binary file removed src/sdk/bootdisk/boot/grub/stage2
Binary file not shown.
Binary file removed src/sdk/bootdisk/boot/grub/stage2_eltorito
Binary file not shown.
Binary file removed src/sdk/c.img
Binary file not shown.
43 changes: 15 additions & 28 deletions src/sdk/diskimage.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/sdk/qemu.sh
Original file line number Diff line number Diff line change
@@ -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