Start work on an install script and add a Vagrantfile for a VM to run it
This commit is contained in:
parent
81fd21da2a
commit
86bdf24671
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ initrd/*
|
|||||||
sysroot/boot/initrd.tar
|
sysroot/boot/initrd.tar
|
||||||
serout
|
serout
|
||||||
vga_drv/vga_drv
|
vga_drv/vga_drv
|
||||||
|
.vagrant
|
||||||
|
69
Vagrantfile
vendored
Normal file
69
Vagrantfile
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# -*- mode: ruby -*-
|
||||||
|
# vi: set ft=ruby :
|
||||||
|
|
||||||
|
# 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 development environment requires a box. You can search for
|
||||||
|
# boxes at https://vagrantcloud.com/search.
|
||||||
|
config.vm.box = "ubuntu/bionic64"
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
# NOTE: This will enable public access to the opened port
|
||||||
|
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
||||||
|
|
||||||
|
# Create a forwarded port mapping which allows access to a specific port
|
||||||
|
# within the machine from a port on the host machine and only allow access
|
||||||
|
# via 127.0.0.1 to disable public access
|
||||||
|
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
# the path on the guest to mount the folder. And the optional third
|
||||||
|
# argument is a set of non-required options.
|
||||||
|
# config.vm.synced_folder "../data", "/vagrant_data"
|
||||||
|
|
||||||
|
# Provider-specific configuration so you can fine-tune various
|
||||||
|
# backing providers for Vagrant. These expose provider-specific options.
|
||||||
|
# Example for VirtualBox:
|
||||||
|
#
|
||||||
|
config.vm.provider "virtualbox" do |vb|
|
||||||
|
# Do not display the VirtualBox GUI when booting the machine
|
||||||
|
vb.gui = false
|
||||||
|
|
||||||
|
# Customize the amount of memory on the VM:
|
||||||
|
vb.memory = "4096"
|
||||||
|
end
|
||||||
|
#
|
||||||
|
# View the documentation for the provider you are using for more
|
||||||
|
# information on available options.
|
||||||
|
|
||||||
|
# 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
|
||||||
|
apt install ruby
|
||||||
|
SHELL
|
||||||
|
end
|
94
install.rb
Normal file
94
install.rb
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#! /usr/bin/env ruby
|
||||||
|
require "tempfile"
|
||||||
|
usbdisks=`for devlink in /dev/disk/by-id/usb*; do readlink -f ${devlink}; done`
|
||||||
|
raws=usbdisks.split("\n")
|
||||||
|
parts=[]
|
||||||
|
for disk in raws
|
||||||
|
if /(\w+)\d+/.match disk
|
||||||
|
parts.push disk
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for disk in raws
|
||||||
|
if /(\w+)\d+/.match disk
|
||||||
|
raws.delete("/dev/#{$1}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if raws.length==0
|
||||||
|
puts "No disks detected. Aborting."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
if parts.length>1
|
||||||
|
puts "Multiple partitions detected."
|
||||||
|
i=0
|
||||||
|
for part in parts
|
||||||
|
puts "#{i}: #{part}"
|
||||||
|
i+=1
|
||||||
|
end
|
||||||
|
print "Please choose partition to install to:"
|
||||||
|
num=gets.chomp.to_i
|
||||||
|
part=parts[num]
|
||||||
|
/(\w+)\d+/.match part
|
||||||
|
raw="/dev/#{$1}"
|
||||||
|
elsif parts.length==0
|
||||||
|
puts "No partitions detected."
|
||||||
|
i=0
|
||||||
|
for raw in raws
|
||||||
|
puts "#{i}: #{raw}"
|
||||||
|
i+=1
|
||||||
|
end
|
||||||
|
print "Please choose disk to install to:"
|
||||||
|
num=gets.chomp.to_i
|
||||||
|
raw=raws[num]
|
||||||
|
print "Getting disk size..."
|
||||||
|
origsize=`sudo blockdev --getsize64 #{raw}`.chomp.to_i
|
||||||
|
unit="MB"
|
||||||
|
fullsize=(origsize/1024.to_f)/1024
|
||||||
|
if fullsize%1024==0 or fullsize>2048
|
||||||
|
fullsize=fullsize/1024.to_f
|
||||||
|
unit="GB"
|
||||||
|
end
|
||||||
|
fullsize=fullsize.floor(1)
|
||||||
|
puts "#{fullsize}#{unit}"
|
||||||
|
print "Partition size: (return for whole disk)"
|
||||||
|
size=gets.chomp.downcase
|
||||||
|
if size.match /(\d)+m/ or size.match /(\d+)mb/
|
||||||
|
size=(size.to_i)*1024*1024
|
||||||
|
elsif size.match /(\d)+g/ or size.match /(\d+)gb/
|
||||||
|
size=(size.to_i)*1024*1024*1024
|
||||||
|
elsif size==""
|
||||||
|
size=origsize
|
||||||
|
else
|
||||||
|
puts "Could not parse size. Aborting."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
sfdisk_input="label: dos\n- #{size/1024}KiB L"
|
||||||
|
tmp=Tempfile.new("myosinstall")
|
||||||
|
tmp.puts sfdisk_input
|
||||||
|
tmp.close
|
||||||
|
print "Partitioning..."
|
||||||
|
`cat #{tmp.path} | sudo sfdisk #{raw} 2>/dev/null`
|
||||||
|
puts "Done"
|
||||||
|
tmp.unlink
|
||||||
|
exit 1
|
||||||
|
puts `sudo mkfs.ext2 #{raw}`
|
||||||
|
part="#{raw}1"
|
||||||
|
raw="#{raw}"
|
||||||
|
else
|
||||||
|
part=parts[0]
|
||||||
|
/(\w+)\d+/.match parts[0]
|
||||||
|
raw="/dev/#{$1}"
|
||||||
|
end
|
||||||
|
`mkdir -p usb`
|
||||||
|
print "Mounting the disk..."
|
||||||
|
`sudo mount #{part} usb`
|
||||||
|
puts "Done"
|
||||||
|
if !File.exists?("usb/boot")
|
||||||
|
puts "Installing GRUB..."
|
||||||
|
`sudo grub-install --boot-directory=usb/boot #{raw}`
|
||||||
|
end
|
||||||
|
print "Installing the OS..."
|
||||||
|
`sudo cp -r /vagrant/sysroot/* usb`
|
||||||
|
puts "Done"
|
||||||
|
print "Umounting disk..."
|
||||||
|
`sudo umount usb`
|
||||||
|
puts "Done"
|
Loading…
Reference in New Issue
Block a user