diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..697314a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* -crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add122c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vagrant +.idea +.DS_Store +sunos/*.iso + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..660c4f4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License + +Copyright 2018 Andrew Liles + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d563341 --- /dev/null +++ b/README.md @@ -0,0 +1,597 @@ +sunboot +------- + +sunboot makes it easy to get an operating system running on Sun hardware. This is the sister project to a similar utility for Silicon Graphics computers called [irixboot](https://github.com/halfmanhalftaco/irixboot). + +## Contents + +- [How it works](#howitworks) +- [Features](#features) +- [Requirements](#requirements) +- [Configuration](#configuration) + - [Vagrantfile](#config_vagrant) + - [sunboot-settings](#sunboot-settings) + - [targets](#config_targets) +- [Security](#security) +- [Operating System-specific Examples](#examples) + - [Diskless SunOS 4.1.4 on SPARCstation IPC](#sunos_ipc) + - [Diskful Solaris 2.3 on SPARCclassic](#sol_classic) +- [Maintenance](#maint) +- [License](#license) + + +## How it works + +Sun hardware was designed with the network in mind and nearly every Sun machine I've come across has baked-in support for booting from Ethernet devices. The code in PROM knows enough to be able to initialize the ethernet adapter and send a broadcast request for its IP address via RARP. Once the machine has its IP address it sends a request via TFTP (UDP port 69) to the address that replied to RARP for a file whose name is the hexadecimal representation of the IP address. This file is the bootloader (often called 'boot' or 'inetboot') and is loaded into RAM and executed. + +The bootloader program knows how to use RPC to call BOOTPARAMS and retrieve information about which filesystems to mount via NFS. It contains enough code to download the kernel via NFS. Control is then passed over to the kernel which then brings the system up the rest of the way. + +Later hardware supports the more modern DHCP for booting but most machines can fall back to RARP/TFTP. + +--- + +## Features + +- Simple configuration +- Supports multiple simultaneous clients running different OS versions +- Diskless-client install & autoconfiguration +- Remote install for diskful-client systems + - Emulates remote tape and CD-ROM devices as install sources + - Supports netbooting the miniroot environment for formatting local disks and running the installer +- Supports both SunOS and Solaris (diskless support for Solaris is in the works) +- Boots (probably) any RARP/TFTP/BOOTPARAMS/NFS capable Sun workstation and operating system + +This project is in its early stages so right now it only supports the following: + +- Only SunOS 4.1.4 (Solaris 1.1.2) and Solaris 2.3 have been tested at this point. +- CD-based operating systems (SunOS 4.1.x, Solaris) +- Diskful (remote install) and Diskless support for SunOS 4.1.x +- Diskful (remote install) support for Solaris + +### Planned features + +- Diskless Solaris installs +- Tape-based SunOS installs (including pre-SPARC systems) +- Non-Sun OS support (netbsd, Linux) +- Centralized user/group/host management (yp/NIS/NIS+) +- Support for installing sunboot on other non-x86 systems (Raspberry Pi, etc.) + +--- + +## Requirements + +- [VirtualBox](https://www.virtualbox.org/wiki/Downloads) +- [Vagrant](https://www.vagrantup.com/) + +Hardware-wise, any virtualization-capable Intel-based computer should work. VirtualBox and Vagrant support Linux, MacOS and Windows. + +--- + +## Configuration + +sunboot has configuration distributed in a few locations. To fully configure sunboot, the following will need to be edited to suit your environment: + +- [Vagrantfile](#vagrantfile) +- [sunboot-settings](#sunboot-settings) +- [targets directory](#config_targets) + +### Vagrantfile + +First, the `Vagrantfile` has one item that needs to be configured: the bridge interface. sunboot must be bridged to (not NAT-ed) to the network where the Sun machine(s) are connected. This is to support the broadcast traffic required to bring these machines up. Fill in your network interface name (can be determined with `VBoxManage list bridgedifs`, the `Name` is the field it looks for). In this example, `eth1` is the interface to be bridged. If this is not filled out, Vagrant will ask at startup which interface to use. + +```ruby + config.vm.network "public_network", auto_config: false, bridge: "eth1" +``` + +### sunboot-settings + +The next configuration step is the server configuration. This contains the hostname, IP address, netmask and gateway of the server. This should be chosen to not interfere with existing machines on the bridged network and be outside of any DHCP address ranges that may be present on the network. + +```bash +# General environment settings + +SERVERNAME=sunboot +SERVERADDR=10.94.42.7 +NETMASK=255.255.255.0 +GATEWAY=10.94.42.1 +``` + +### targets directory + +Files in this directory specify the settings for individual machines to enable netbooting for. + +Example: + +```bash +# SPARCstation IPC SunOS 4.1.4 Diskless Install Example + +TARGETARCH=sun4c +TARGETNAME=hobbes +TARGETETHER=8:0:20:a:7d:8f +TARGETADDR=10.94.42.208 +TARGETSWAPSIZE=64 + +# options: DISKLESS or DISKFUL +INSTALLMETHOD=DISKLESS + +# options: CDROM or TAPE +INSTALLMEDIA=CDROM + +# path (within 'sunos' directory) to the install CD-ROM or directory that contains 'tape1', 'tape2', etc. dirs +INSTALLMEDIAPATH=solaris1.1.2.iso +``` + +`TARGETARCH` should be set to the correct kernel architecture required for your machine. + +Examples: + +- Sun-2 machines are always `sun2` +- Sun-3 machines are either `sun3` or later 68030-based machines are `sun3x` +- Early SPARC machines are `sun4`, while SPARCstation 1-era machines are `sun4c`. Machines based on the multiprocessor-capable architecture (SPARCstation 10, 20 and relatives) are `sun4m`. + - There are some fairly esoteric derivatives of these such as `sun4d`, `sun4e`, `sun4u1` and `sun4us` +- UltraSPARC I, II, III and IV machines are `sun4u` +- UltraSPARC T1 and later are `sun4v` + +`TARGETSWAPSIZE` is the size of the swapfile allocated to the machine, in megabytes. A general rule of thumb is RAM * 2. + +A `DISKFUL` install will configure the machine to boot into the installer for the operating system media provided. For SunOS 4.1.x this will boot the machine into `miniroot` and boot to a shell where one can run `format` to label local disks and then `suninstall` to perform an installation. For Solaris this will boot into the graphical installer if a keyboard is present. + +A `DISKFUL` install tries to emulate a full install of the operating system. Currently this is only supported for SunOS 4.1.x. All of the available software sets are extracted to disk and exported via NFS. The operating system is customized per the target configuration to set the IP address and hostname. + +Install media should be placed in the provided `sunos` directory. Paths specified in `INSTALLMEDIAPATH` are relative to this directory. + +--- + +## Security + +sunboot configures the virtual machine in a way that is inherently insecure. The boot process was designed in an era where the network was considered fully trusted so security on the modern Linux-based operating system that sunboot uses must be bypassed in several cases to make things work. + +It is recommended to airgap or at minimum heavily firewall the network that sunboot is configured on. + +- `rsh` is enabled and allows passwordless root login to SunOS diskful installs. This is required to support remote media access. +- read-write NFS exports are restricted by IP address only, there is no other authentication in place which means other machines on the network could potentially access NFS on these exports as root or any other user without restriction. Static ARP entries are entered on the sunboot VM to mitigate. + +The sunboot VM does require internet access during `vagrant up` in order to download the required Debian packages. After the initial configuration is complete it can be disconnected from the internet. + +--- + +## Operating System-specific Examples + +### Diskless SunOS 4.1.4 on a SPARCstation IPC + +Using the following target configuration, here are the steps to start up sunboot and boot the SPARCstation. + +`targets/hobbes`: + +```bash +# SPARCstation IPC SunOS 4.1.4 Diskless Install Example + +TARGETARCH=sun4c +TARGETNAME=hobbes +TARGETETHER=8:0:20:a:7d:8f +TARGETADDR=10.94.42.208 +TARGETSWAPSIZE=64 + +# options: DISKLESS or DISKFUL +INSTALLMETHOD=DISKLESS + +# options: CDROM or TAPE +INSTALLMEDIA=CDROM + +# path (within 'sunos' directory) to the install CD-ROM or directory that contains 'tape1', 'tape2', etc. dirs +INSTALLMEDIAPATH=solaris1.1.2.iso +``` + +On host machine: +``` +$ git clone https://github.com/halfmanhalftaco/sunboot.git +$ cd sunboot +$ vi Vagrantfile sunboot-settings targets/hobbes # edit the configurations +$ vagrant up +Bringing machine 'default' up with 'virtualbox' provider... +==> default: Importing base box 'debian/contrib-jessie64'... +==> default: Matching MAC address for NAT networking... +==> default: Checking if box 'debian/contrib-jessie64' is up to date... +==> default: Setting the name of the VM: sunboot_default_1531929476572_79046 +==> default: Clearing any previously set network interfaces... +==> default: Preparing network interfaces based on configuration... + default: Adapter 1: nat + default: Adapter 2: bridged +==> default: Forwarding ports... + default: 22 (guest) => 2222 (host) (adapter 1) +==> default: Running 'pre-boot' VM customizations... +==> default: Booting VM... + +==> default: Mounting shared folders... + default: /vagrant => F:/src/sunboot +==> default: Running provisioner: initialize (shell)... + default: Running: C:/Users/sunboot/AppData/Local/Temp/vagrant-shell20180718-6128-1w9bupk + default: Renaming machine to 'sunboot'... + default: Installing packages... + default: Adjusting kernel settings... + default: Enable rdate service... + default: Creating server directories... + default: Configuring NFS daemons... + default: Setting up rsh shims... + default: Configuring bridge interface... + default: sunboot initialization complete. +==> default: Running provisioner: provision (shell)... + default: Running: C:/Users/sunboot/AppData/Local/Temp/vagrant-shell20180718-6128-3rk3gf + default: -------------------------------------- + default: Installing target "hobbes"... + default: -------------------------------------- + default: Mounting CD-ROM image... + default: Found SunOS 4.1.4 + default: -------------------------------------- + default: SunOS 4.1.4 SUNBIN + default: sun4c, sun4, sun4m + default: CD-ROM (boot format) 1 of 1 + default: 258-4662 + default: Solaris(R) 1.1.2 + default: Sun-4(TM), Sun-4c, Sun-4m, SPARC(R) + default: Part Number: 258-4662 + default: CD-ROM (1 of 1) ISO 9660 format + default: -------------------------------------- + default: Available architectures on this media: + default: sun4.sun4c.sunos.4.1.4 + default: sun4.sun4.sunos.4.1.4 + default: sun4.sun4m.sunos.4.1.4 + default: Detected version: 4.1.4 + default: Selected architecture: sun4.sun4c.sunos.4.1.4 + default: Creating diskless install... + default: Extracting "debugging" set... + default: Extracting "demo" set... + default: Extracting "games" set... + default: Extracting "graphics" set... + default: Extracting "install" set... + default: Extracting "networking" set... + default: Extracting "openwindows_demo" set... + default: Extracting "openwindows_fonts" set... + default: Extracting "openwindows_programmers" set... + default: Extracting "openwindows_users" set... + default: Extracting "rfs" set... + default: Extracting "security" set... + default: Extracting "shlib_custom" set... + default: Extracting "sunview_demo" set... + default: Extracting "sunview_programmers" set... + default: Extracting "sunview_users" set... + default: Extracting "system_v" set... + default: Extracting "text" set... + default: Extracting "tli" set... + default: Extracting "user_diag" set... + default: Extracting "usr" set... + default: Extracting "uucp" set... + default: Extracting "versatec" set... + default: Extracting "manual" set... + default: -------------------------------------- + default: Install complete for "hobbes". + default: -------------------------------------- + +==> default: Machine 'default' has a post `vagrant up` message. This is a message +==> default: from the creator of the Vagrantfile, and not from Vagrant itself: +==> default: +==> default: ["sunboot initialization complete."] + +``` + +At this stage the server is now ready to boot the target machine. From the target machine, all that should be required is a `boot net` command. The following is the output from the serial console: + +``` +not nvramrc +SPARCstation IPC, No keyboard. +ROM Rev. 1.6, 32 MB memory installed, Serial #687503. +Ethernet address 8:0:20:a:7d:8f, Host ID: 520a7d8f. + + +Testing +Type b (boot), c (continue), or n (new command mode) +>n +ok boot net +Booting from: le(0,0,0) +1ee00 Using IP Address 10.94.42.208 = 0A5E2AD0 +hostname: hobbes +domainname: (none) +server name 'sunboot' +root pathname '/export/root/hobbes' +root on sunboot:/export/root/hobbes fstype nfs +Boot: vmunix +Size: 1343488+218832+131992 bytes +SunOS Release 4.1.4 (GENERIC) #2: Fri Oct 14 11:08:06 PDT 1994 +Copyright (c) 1983-1993, Sun Microsystems, Inc. +mem = 32768K (0x2000000) +avail mem = 30531584 +Ethernet address = 8:0:20:a:7d:8f +cpu = Sun 4/40 +zs0 at obio 0xf1000000 pri 12 +zs1 at obio 0xf0000000 pri 12 +fd0 at obio 0xf7200000 pri 11 +audio0 at obio 0xf7201000 pri 13 +sbus0 at SBus slot 0 0x0 +dma0 at SBus slot 0 0x400000 +esp0 at SBus slot 0 0x800000 pri 3 +esp0: Warning- no devices found for this SCSI bus +le0 at SBus slot 0 0xc00000 pri 5 +dma1 at SBus slot 1 0x81000 +esp1 at SBus slot 1 0x80000 pri 3 +esp1: Warning- no devices found for this SCSI bus +lebuffer0 at SBus slot 1 0x40000 +le1 at SBus slot 1 0x60000 pri 5 +cgsix0 at SBus slot 2 0x0 pri 7 +cgsix0: screen 1152x900, single buffered, 1M mappable, rev 6 +bwtwo0 at SBus slot 3 0x0 pri 7 +hostname: hobbes +domainname: (none) +root on sunboot:/export/root/hobbes fstype nfs +swap on sunboot:/export/swap/hobbes fstype nfs size 65536K +dump on sunboot:/export/swap/hobbes fstype nfs size 65524K + + + +hobbes login: root +Jul 18 16:23:52 hobbes login: ROOT LOGIN console +Last login: Wed Jul 18 16:17:19 from 10.94.42.30 +SunOS Release 4.1.4 (GENERIC) #2: Fri Oct 14 11:08:06 PDT 1994 +hobbes# + +``` + + +### Diskful install of Solaris 2.3 on a SPARCclassic + +`targets/ssx`: + +```bash +# SPARCclassic Solaris 2.3 Diskful Install Example + +TARGETARCH=sun4m +TARGETNAME=ssx +TARGETETHER=8:0:20:5:61:c2 +TARGETADDR=10.94.42.209 +TARGETSWAPSIZE=64 + +# options: DISKLESS or DISKFUL +INSTALLMETHOD=DISKFUL + +# options: CDROM or TAPE +INSTALLMEDIA=CDROM + +# path (within 'sunos' directory) to the install CD-ROM or directory that contains 'tape1', 'tape2', etc. dirs +INSTALLMEDIAPATH=solaris_2.3_sparc.iso +``` + +``` +$ git clone https://github.com/halfmanhalftaco/sunboot.git +$ cd sunboot +$ vi Vagrantfile sunboot-settings targets/ssx # edit the configurations +$ vagrant up +Bringing machine 'default' up with 'virtualbox' provider... +==> default: Importing base box 'debian/contrib-jessie64'... +==> default: Matching MAC address for NAT networking... +==> default: Checking if box 'debian/contrib-jessie64' is up to date... +==> default: Setting the name of the VM: sunboot_default_1531931457995_66060 +==> default: Clearing any previously set network interfaces... +==> default: Preparing network interfaces based on configuration... + default: Adapter 1: nat + default: Adapter 2: bridged +==> default: Forwarding ports... + default: 22 (guest) => 2222 (host) (adapter 1) +==> default: Running 'pre-boot' VM customizations... +==> default: Booting VM... + +==> default: Mounting shared folders... + default: /vagrant => F:/src/sunboot +==> default: Running provisioner: initialize (shell)... + default: Running: C:/Users/sunboot/AppData/Local/Temp/vagrant-shell20180718-20392-1ylgzm6 + default: Renaming machine to 'sunboot'... + default: Installing packages... + default: Adjusting kernel settings... + default: Enable rdate service... + default: Creating server directories... + default: Configuring NFS daemons... + default: Setting up rsh shims... + default: Configuring bridge interface... + default: sunboot initialization complete. +==> default: Running provisioner: provision (shell)... + default: Running: C:/Users/sunboot/AppData/Local/Temp/vagrant-shell20180718-20392-1yn3bxy + default: -------------------------------------- + default: Installing target "ssx"... + default: -------------------------------------- + default: Mounting CD-ROM image... + default: Found Solaris 2.3 + default: -------------------------------------- + default: Solaris(TM) 2.3 Hardware: 8/94, Binary + default: SPARC SUNBIN + default: CD-ROM (Rockridge Format) + default: Part Number: 258-4455 + default: -------------------------------------- + default: Available architectures on this media: + default: sparc.sol5.Solaris_2.3 + default: sparc.sol6.Solaris_2.3 + default: sparc.sun4c.Solaris_2.3 + default: sparc.sun4d.Solaris_2.3 + default: sparc.sun4e.Solaris_2.3 + default: sparc.sun4m1.Solaris_2.3 + default: sparc.sun4m.Solaris_2.3 + default: sparc.sun4.Solaris_2.3 + default: Detected version: Solaris_2.3 + default: Selected architecture: sparc.sun4m.Solaris_2.3 + default: Copying sun4m miniroot to /export/root/ssx + default: Configuring NFS exports... + default: Configuring bootparams... + default: -------------------------------------- + default: Install complete for "ssx". + default: -------------------------------------- + +==> default: Machine 'default' has a post `vagrant up` message. This is a message +==> default: from the creator of the Vagrantfile, and not from Vagrant itself: +==> default: +==> default: ["sunboot initialization complete."] + +``` + +Serial console: +``` +SPARCclassic, No Keyboard +ROM Rev. 2.12, 72 MB memory installed, Serial #190146. +Ethernet address 8:0:20:5:61:c2, Host ID: 8002e6c2. + + + +Type help for more information +ok boot net +Boot device: /iommu/sbus/ledma@4,8400010/le@4,8c00000 File and args: +hostname: ssx +domainname: (none) +root server: sunboot +root directory: /export/root/ssx +SunOS Release 5.3 Version Generic [UNIX(R) System V Release 4.0] +Copyright (c) 1983-1993, Sun Microsystems, Inc. +WARNING: TOD clock not initialized -- CHECK AND RESET THE DATE! +Configuring the /devices directory +Configuring the /dev directory +The system is coming up. Please wait. + +What type of terminal are you using? + 1) ANSI Standard CRT + 2) DEC VT52 + 3) DEC VT100 + 4) Heathkit 19 + 5) Lear Siegler ADM31 + 6) PC Console + 7) Sun Command Tool + 8) Sun Workstation + 9) Televideo 910 + 10) Televideo 925 + 11) Wyse Model 50 + 12) Other +Type the number of your choice and press Return:3 +starting rpc services: rpcbind sysidnis + + +Do you want to configure this system as a client of a name service? If so, +which name service do you want to use? If you do not want to use a name +service select `none' and consult your Install documentation. + + + + lqqqqqqqqqqqqqqqqqqqqqqqqqk + x>NIS+ Client x + x NIS (formerly yp) Clientx + x None - use /etc files x + mqqqqqqqqqqqqqqqqqqqqqqqqqj + + + + +Use the arrow keys to select an item. (CTRL-n next, CTRL-p previous) + +Press Return to continue. + +Does this workstation's network have sub-networks? + + + + lqqqqk + x>No x + x Yesx + mqqqqj + + + + +Use the arrow keys to select an item. (CTRL-n next, CTRL-p previous) + +Press Return to continue. + +This is your default netmask value. You may change it if necessary, but the +format must remain as four numbers separated by periods. + + + lqqqqqqqqqqqqqqqqqqqqqqqqqqqqk + x x + x Netmask: 255.255.255.0___ x + x x + mqqqqqqqqqqqqqqqqqqqqqqqqqqqqj + + + + +Press Return to continue. + +Is the following information correct? + +Name service: none +Network is sub-netted: Yes +Netmask: 255.255.255.0 + + + + lqqqqqqqqqqqqqqqqqqqqqqqqqk + x No, re-enter informationx + x>Yes, continue x + mqqqqqqqqqqqqqqqqqqqqqqqqqj + + + + +Use the arrow keys to select an item. (CTRL-n next, CTRL-p previous) + +Press Return to continue. + +< time zone selection screens, etc. snipped > + +lqqqqqqqqqqqqqqqqqqqqqqqqqqq[ Solaris Installation ]qqqqqqqqqqqqqqqqqqqqqqqqqqqk +x x +x x +x x +x x +x x +x ( Quick Install... ) x +x x +x ( Custom Install... ) x +x x +x ( Exit Install... ) x +x x +x ( Help... ) x +x x +x x +x x +x x +x x +x x +x x +tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu +x Select; Next Field; Help x +mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj +``` + +--- + +## Maintenance + +Since sunboot supports diskless clients you probably don't want to be destroying/recreating the VM very often. There's a couple commands built in that help add new clients and remove old ones. + +To run these commands you'll need to log into the Vagrant VM with `vagrant ssh`. + +### Commands + +- `sudo target_rm ` + - This will remove all of the install artifacts for the given target, including its NFS exports, root filesystem, etc. It does *not* remove the target configuration file or the generic miniroot/exec/protoroot environment for the target's operating system. + - This is particularly recommended for SunOS diskful targets after the OS has been installed to disable root rsh capability to the boot server. +- `sudo install_targets` + - Run this command to reprocess all the target files in the `targets` directory. It skips any targets that already have root filesystems in place (in `/export/root/`) +- `sudo mount_media ` + - When multiple machines are configured for diskful installs, the correct install media may not be ready for the client. Run this to ensure that the appropriate media for this target is configured. + +--- + +## License +The MIT License + +Copyright 2018 Andrew Liles + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..eee653c --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,12 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.vm.box = "debian/contrib-jessie64" + config.vm.box_version = "8.11.0" + config.vm.network "public_network", auto_config: false, bridge: "eth1" + config.vm.provision "initialize", type: "shell", path: "scripts/sunboot_init", run: "once" + config.vm.provision "provision", type: "shell", path: "scripts/install_targets", run: "always" + + config.vm.post_up_message = [ "sunboot initialization complete." ] +end diff --git a/scripts/functions.sh b/scripts/functions.sh new file mode 100644 index 0000000..1a66b06 --- /dev/null +++ b/scripts/functions.sh @@ -0,0 +1,288 @@ +#!/bin/bash + +# sunboot functions.sh +CDROM=/cdrom + +. /vagrant/scripts/utils.sh + +function cdrom_detect() { + if [ -f $CDROM/.cdtoc ]; then + if [ $(grep PRODNAME $CDROM/.cdtoc | cut -d '=' -f 2 | tr a-z A-Z) = "SOLARIS" ]; then + SOLARIS=1 + SUNOS=0 + SOLARIS_VERSION=$(grep PRODVERS $CDROM/.cdtoc | cut -d '=' -f 2) + echo "Found Solaris $SOLARIS_VERSION" + fi + elif [ -f $CDROM/avail_arches ]; then + SUNOSTMP=$(grep sunos $CDROM/avail_arches | head -1) + if [[ $SUNOSTMP =~ sunos\.(.*)$ ]]; then + SUNOS_VERSION="${BASH_REMATCH[1]}" + SUNOS=1 + SOLARIS=0 + echo "Found SunOS $SUNOS_VERSION" + fi + else + error_exit "Unable to detect SunOS or Solaris on the CD-ROM." + fi +} + +function cdrom_select_arch_sunos() { + # Read version/architecture info + if [ -f $CDROM/_copyright ]; then + echo "--------------------------------------" + sed -e '/^$/,$d' $CDROM/_copyright + echo "--------------------------------------" + fi + + if [ -f $CDROM/avail_arches ]; then + echo "Available architectures on this media:" + cat $CDROM/avail_arches + fi + + # select architecture + case $TARGETARCH in + sun4*) + SELECTEDARCH=$(grep sun4.$TARGETARCH $CDROM/avail_arches) + SELECTEDVERSION=$(expr $SELECTEDARCH : ".*\.sunos\.\(.*\)$") + ;; + *) + error_exit "Target arch $TARGETARCH is not supported for CD-ROM releases." + ;; + esac + + echo "Detected version: $SELECTEDVERSION" + echo "Selected architecture: $SELECTEDARCH" + + if ! grep -q $TARGETARCH $CDROM/avail_arches; then + error_exit "This media does not support the $TARGETARCH architecture specified in the target." + fi +} + +function cdrom_select_arch_solaris() { + if [ -f $CDROM/Copyright ]; then + echo "--------------------------------------" + sed -e '/Copyright/,$ d' -e '/^$/d' $CDROM/Copyright + echo "--------------------------------------" + fi + + if [ -d $CDROM/archinfo ]; then + echo "Available architectures on this media:" + ls -1 $CDROM/archinfo + fi + + if [ -d $CDROM/export/exec/kvm/*.$TARGETARCH.* ]; then + SELECTEDARCH=$(basename $CDROM/export/exec/kvm/*.$TARGETARCH.*) + SELECTEDVERSION=$(expr $SELECTEDARCH : "[a-zA-Z0-9]*\.$TARGETARCH\.\(.*\)") + echo "Detected version: $SELECTEDVERSION" + echo "Selected architecture: $SELECTEDARCH" + else + error_exit "This media does not support the $TARGETARCH architecture specified in the target." + fi +} + +function cdrom_select_arch() { + if [ $SOLARIS -eq 1 ]; then + cdrom_select_arch_solaris + elif [ $SUNOS -eq 1 ]; then + cdrom_select_arch_sunos + fi +} + +function cdrom_mount() { + # mount the cdrom, checking if it's already mounted + lmount=$(mount | grep $CDROM | cut -d ' ' -f 1) + if [ ! -z $lmount ]; then + # check if this is the CDROM we want + lfile=$(losetup -l -n -O NAME,BACK-FILE | grep $lmount | cut -d ' ' -f 2-) + if [ $lfile != "/vagrant/sunos/$INSTALLMEDIAPATH" ]; then + umount $lmount || error_exit "Failed to unmount existing CD-ROM" + losetup -d $lmount || error_exit "Failed to unconfigure loop device" + losetup -r -P /dev/loop0 /vagrant/sunos/$INSTALLMEDIAPATH || error_exit "Failed to configure loop device" + mount -o ro /dev/loop0 $CDROM || error_exit "Failed to mount CD-ROM" + fi + else + losetup -d /dev/loop0 >/dev/null 2>&1 + losetup -r -P /dev/loop0 /vagrant/sunos/$INSTALLMEDIAPATH || error_exit "Failed to configure loop device" + mount -o ro /dev/loop0 $CDROM || error_exit "Failed to mount CD-ROM" + fi +} + +function cdrom_unmount() { + umount /dev/loop0 + losetup -d /dev/loop0 +} + +function cdrom_copy_miniroot() { + # copy from disc if we don't already have a copy + if [ ! -d /export/miniroot/$SELECTEDARCH ]; then + mkdir -p /export/miniroot/$SELECTEDARCH + + # different steps if Solaris vs. SunOS + + if [ $SUNOS -eq 1 ]; then + losetup -r /dev/loop1 $CDROM/export/exec/kvm/$TARGETARCH_sunos_*/miniroot_$TARGETARCH + mount -o ro,ufstype=sun /dev/loop1 /mnt + rsync -a /mnt/ /export/miniroot/$SELECTEDARCH + umount /mnt + mv /export/miniroot/$SELECTEDARCH/boot.$TARGETARCH /export/miniroot/$SELECTEDARCH/boot + elif [ $SOLARIS -eq 1 ]; then + pushd $CDROM/export/exec/kvm/$SELECTEDARCH + find . -depth -print | cpio -pdm /export/miniroot/$SELECTEDARCH >/dev/null 2>&1 + popd + AARCH=$(expr $SELECTEDARCH : "\(.*\)\.$TARGETARCH\.$SELECTEDVERSION") + pushd $CDROM/export/exec/$AARCH.$SELECTEDVERSION/lib/fs/nfs + if [ -f inetboot.$SELECTEDARCH ]; then + cp inetboot.$SELECTEDARCH /export/miniroot/$SELECTEDARCH/inetboot + elif [ -f inetboot ]; then + cp inetboot /export/miniroot/$SELECTEDARCH/inetboot + else + error_exit "Could not find Solaris bootloader." + fi + popd + else + error_exit "Unknown operating system." + fi + + fi + if [ -d /export/root/$TARGETNAME ]; then + echo "Root directory /export/root/$TARGETNAME already exists, not overwriting." + exit 1 + fi + mkdir -p /export/root/$TARGETNAME + rsync -a /export/miniroot/$SELECTEDARCH/ /export/root/$TARGETNAME +} + +function cdrom_install_diskless() { + # for SunOS 4.1.4 (possibly any 4.1.x CD-ROM release) this should do: + # if new version/arch combo, extract proto root to /export/proto/arch_sunos_version + # create new /export/root dir for target host from proto + # untar distribution on top + # move /usr into /export/exec/version_arch + # configure hostname, network, etc in target root + + if [ $SOLARIS -eq 1 ]; then error_exit "Solaris not yet supported"; fi + + ARCHTMP=sunos_$(echo $SELECTEDVERSION | tr . _) + + if [ -z $SELECTEDARCH ]; then + echo "No distribution architecture has been selected." + exit 1 + fi + + if [ ! -d /export/proto/$SELECTEDARCH ]; then + mkdir -p /export/proto/$SELECTEDARCH + pushd /export/proto/$SELECTEDARCH + tar xf $CDROM/export/exec/proto_root_$ARCHTMP + # untar kvm, sys + mkdir -p usr/kvm + pushd usr/kvm + tar xf $CDROM/export/exec/kvm/${TARGETARCH}_${ARCHTMP}/kvm + tar xf $CDROM/export/exec/kvm/${TARGETARCH}_${ARCHTMP}/sys + popd + pushd usr + # untar rest of distribution sets here (in export/exec/sun4_sunos_4_1_4) + for tarfile in $CDROM/export/exec/*sunos*/* $CDROM/export/share/*/* ; do + echo "Extracting \"$(basename $tarfile)\" set..." + tar xf $tarfile + done + popd + + cp usr/kvm/stand/{kadb,vmunix} . + cp usr/kvm/stand/boot.$TARGETARCH ./boot + cp usr/kvm/boot/* ./sbin + cp usr/stand/sh ./sbin + cp usr/bin/hostname ./sbin + popd + + if [ -d /export/exec/$SELECTEDARCH ]; then rm -rf /export/exec/$SELECTEDARCH; fi + mv /export/proto/$SELECTEDARCH/usr /export/exec/$SELECTEDARCH + mkdir -p /export/proto/$SELECTEDARCH/usr + fi + + # create new install for $TARGETNAME + + ROOT=/export/root/$TARGETNAME + + if [ -d $ROOT ]; then + echo "Existing root for \"$TARGETNAME\" exists, moving it to $ROOT.old" + rm -rf $ROOT.old + mv $ROOT $ROOT.old + fi + + mkdir -p $ROOT + rsync -a /export/proto/$SELECTEDARCH/ $ROOT + + pushd $ROOT + + # customize for our target + + # edit hosts, hostname.xxx, fstab + printf "$TARGETADDR $TARGETNAME\n$SERVERADDR $SERVERNAME\n" >> etc/hosts + echo "$TARGETNAME" > etc/hostname.le0 + cat << EOF > etc/fstab +$SERVERNAME:$ROOT / nfs rw 0 0 +$SERVERNAME:/export/exec/$SELECTEDARCH /usr nfs ro 0 0 +$SERVERNAME:/export/home /home nfs rw 0 0 +EOF + # todo: find out how to make sunos respect subnet netmask + + # patch/run MAKEDEV std pty0 pty1 pty2 win0 win1 win2 + pushd dev + sed -e 's#^PATH=.*$#PATH=/vagrant/shims:$PATH#' MAKEDEV > MAKEDEV.sunboot && chmod u+x MAKEDEV.sunboot + ./MAKEDEV.sunboot std pty0 pty1 pty2 win0 win1 win2 >/dev/null + popd + # move 'yp' dir out of place + mv var/yp var/yp.disabled + popd + + echo "$SELECTEDARCH" > $ROOT/.sunboot + +} + +# setup NFS exports +function configure_nfs() { + # setup swap space for client + rm -f /export/swap/$TARGETNAME + dd if=/dev/zero of=/export/swap/$TARGETNAME bs=1M count=$TARGETSWAPSIZE >/dev/null 2>&1 + + cat << EOF >> /etc/exports +/export/root/$TARGETNAME $TARGETADDR(rw,sync,no_root_squash,no_subtree_check) +/export/swap/$TARGETNAME $TARGETADDR(rw,sync,no_root_squash,no_subtree_check) +EOF + + exportfs -ra +} + +# Setup rarp, bootparams and rsh +function config_boot() { + ETHER=$(normal_ether $TARGETETHER) + BOOTPARAMS="root=$SERVERNAME:/export/root/$TARGETNAME swap=$SERVERNAME:/export/swap/$TARGETNAME" + BOOTPROGRAM="boot" + + if [ $SOLARIS -eq 1 ]; then + BOOTPROGRAM="inetboot" + if [ $INSTALLMETHOD = "DISKFUL" ]; then + BOOTPARAMS="root=$SERVERNAME:/export/root/$TARGETNAME install=$SERVERNAME:$CDROM" + fi + fi + + if [ $SUNOS -eq 1 ]; then + echo "$TARGETNAME root" > /root/.rhosts + fi + + # todo - remove existing entries before blindly adding them + echo "$TARGETNAME $BOOTPARAMS" >> /etc/bootparams + echo "$ETHER $TARGETNAME" >> /etc/ethers + echo "$TARGETADDR $TARGETNAME" >> /etc/hosts + arp -s $TARGETADDR $ETHER + + # Link bootloader + IPHEX=$(iphex $TARGETADDR) + pushd /srv/tftp + cp -f /export/root/$TARGETNAME/$BOOTPROGRAM ./$BOOTPROGRAM.$SELECTEDARCH + ln -s $BOOTPROGRAM.$SELECTEDARCH $IPHEX + ln -s $BOOTPROGRAM.$SELECTEDARCH $IPHEX.$(echo $TARGETARCH | tr a-z A-Z) + popd + + systemctl restart bootparamd +} diff --git a/scripts/insecure_disable b/scripts/insecure_disable new file mode 100644 index 0000000..3408e7a --- /dev/null +++ b/scripts/insecure_disable @@ -0,0 +1,13 @@ +#!/bin/bash + +# insecure_disable +# +# Turn off obviously-insecure services that are not necessary +# for running diskless clients (only for running diskful installs). +# +# Affects: rsh + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi diff --git a/scripts/insecure_enable b/scripts/insecure_enable new file mode 100644 index 0000000..f9b41ac --- /dev/null +++ b/scripts/insecure_enable @@ -0,0 +1,13 @@ +#!/bin/bash + +# insecure_disable +# +# Turn on obviously-insecure services needed for running network +# installs for SunOS. +# +# Affects: rsh + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi \ No newline at end of file diff --git a/scripts/install_targets b/scripts/install_targets new file mode 100644 index 0000000..652032d --- /dev/null +++ b/scripts/install_targets @@ -0,0 +1,78 @@ +#!/bin/bash + +# sunboot install_targets +# run this script to automatically process the targets directory + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +. /vagrant/sunboot-settings +. /vagrant/scripts/functions.sh + +DISKFUL_COUNT=0 + +function do_install() { + case $INSTALLMEDIA in + CDROM) + echo "Mounting CD-ROM image..." + cdrom_mount + cdrom_detect + cdrom_select_arch + ;; + TAPE) + echo "Tape media not yet supported." + exit 1 + ;; + esac + + case $INSTALLMETHOD in + DISKFUL) + echo "Copying $TARGETARCH miniroot to /export/root/$TARGETNAME" + cdrom_copy_miniroot + echo "Configuring NFS exports..." + configure_nfs + echo "Configuring bootparams..." + config_boot + DISKFUL_COUNT=$(($DISKFUL_COUNT+1)) + DISKFUL_TARGET=$(basename $target) + ;; + DISKLESS) + echo "Creating diskless install..." + cdrom_install_diskless + configure_nfs + config_boot + ;; + esac +} + +tcount=$(ls -1 /vagrant/targets | wc -l) +if [ $tcount -eq 0 ]; then + echo "No targets specified." + exit 1 +fi + +for target in /vagrant/targets/* ; do + DISABLED=0 + . $target + if [ $DISABLED -eq 1 ]; then continue; fi + if [ ! -d /export/root/$TARGETNAME ]; then + echo "--------------------------------------" + echo "Installing target \"$TARGETNAME\"..." + echo "--------------------------------------" + do_install + echo "--------------------------------------" + echo "Install complete for \"$TARGETNAME\"." + echo "--------------------------------------" + else + echo "Skipping \"$TARGETNAME\", root dir already exists" + fi +done + +if [ $DISKFUL_COUNT -gt 1 ]; then + echo "More than one diskful install is configured!" + echo "use \"sudo mount_media \" to switch which target media is mounted to correctly install these targets." +elif [ $DISKFUL_COUNT -eq 1 ]; then + /vagrant/scripts/mount_media $DISKFUL_TARGET # ensure the media for the diskful install is mounted +fi \ No newline at end of file diff --git a/scripts/iphex b/scripts/iphex new file mode 100644 index 0000000..ff8d223 --- /dev/null +++ b/scripts/iphex @@ -0,0 +1,6 @@ +#!/bin/bash + +. /vagrant/scripts/functions.sh + +iphex $1 +echo \ No newline at end of file diff --git a/scripts/mount_media b/scripts/mount_media new file mode 100644 index 0000000..c53419a --- /dev/null +++ b/scripts/mount_media @@ -0,0 +1,34 @@ +#!/bin/bash + +# mount_media +# +# When more than one diskful install is configured in 'targets', which media +# should be mounted at any given time is ambiguous. This script ensures that +# the media specified for the given target is available for a diskful install. +# +# Usage: +# mount_media +# +# where target is one of the files in the 'target' subdirectory of sunboot. + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +. /vagrant/scripts/functions.sh + +if [ ! -f /vagrant/targets/$1 ]; then + error_exit "Target \"$1\" not found." +fi + +. /vagrant/targets/$1 + +case $INSTALLMEDIA in + CDROM) + cdrom_mount + ;; + TAPE) + error_exit "Not yet supported" + ;; +esac \ No newline at end of file diff --git a/scripts/proto_install b/scripts/proto_install new file mode 100644 index 0000000..c29d223 --- /dev/null +++ b/scripts/proto_install @@ -0,0 +1,24 @@ +#!/bin/bash + +# sunboot proto_install +# Installs root filesystem prototypes and exec directories +# for all of the architectures on the provided media. + +# Usage: +# proto_install [-t CDROM|TAPE] path_to_media +# +# In the case of CDROM media, path_to_media should be a CDROM image (ISO9660) +# For tape, the path should be a directory that contains subdirectories named +# tape1, tape2, etc, each containing numbered files representing the tape +# file layout. +# +# The script will inspect the media and take the appropriate steps to copy +# everything needed to support booting clients. + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +echo "Not yet implemented!" +exit 1 \ No newline at end of file diff --git a/scripts/sunboot_init b/scripts/sunboot_init new file mode 100644 index 0000000..4ca3ce4 --- /dev/null +++ b/scripts/sunboot_init @@ -0,0 +1,82 @@ +#!/bin/bash + +. /vagrant/sunboot-settings + +echo "Renaming machine to '$SERVERNAME'..." +cp /etc/hosts /etc/hosts.orig +echo "$SERVERNAME" > /etc/hostname +printf "127.0.0.1 localhost\n$SERVERADDR $SERVERNAME\n" > /etc/hosts +/etc/init.d/hostname.sh +invoke-rc.d rsyslog restart + +# Install required packages +echo "Installing packages..." +apt-get install -y rsync openbsd-inetd rsh-server rsh-client bootparamd \ + nfs-kernel-server tftpd-hpa rarpd tcpdump >/dev/null 2>&1 +modprobe -a ufs + +# todo make rarpd/tftpd/bootparamd only listen on eth1 (and possibly only respond to our targets) + +echo "Adjusting kernel settings..." +echo << EOF >> /etc/sysctl.conf +net.ipv4.ip_no_pmtu_disc=1 +net.ipv4.ip_local_port_range = 2048 32767 +EOF +sysctl -p + +echo "Enable rdate service..." +sed -i 's/^#time/time/' /etc/inetd.conf +systemctl restart openbsd-inetd + +# Set up server directories +echo "Creating server directories..." +mkdir -p /cdrom /usr/etc/install /export/{root,exec,swap,home,proto,miniroot,opt} /srv/tftp +ln -sf /cdrom /usr/etc/install/tar + +# Setup NFS for v2/v3 support +echo "Configuring NFS daemons..." +sed -i 's/^RPCMOUNTDOPTS.*/RPCMOUNTDOPTS="--manage-gids --no-nfs-version 4"/' /etc/default/nfs-kernel-server +sed -i 's/^NEED_STATD.*/NEED_STATD=yes/' /etc/default/nfs-common +# todo: limit exports to our subnet +echo "/export/exec *(ro,sync,no_root_squash,no_subtree_check)" >> /etc/exports +echo "/export/home *(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports +echo "/cdrom *(ro,sync,no_root_squash,no_subtree_check)" >> /etc/exports +systemctl enable nfs-kernel-server >/dev/null 2>&1 +systemctl enable rpcbind >/dev/null 2>&1 +systemctl restart nfs-kernel-server +systemctl restart rpcbind + +# Enable $SERVERNAME shims for rsh (mount, dd, mt) +echo "Setting up rsh shims..." +cat << EOF >> /root/.bashrc +if [ $(ps -o comm= -p $PPID) == "in.rshd" ]; then + export PATH=/vagrant/shims:\$PATH + export HISTFILE=/vagrant/rsh_history.txt + set -o history +fi +EOF + +# add our scripts to PATH in the user acct and in sudo +sed -i 's#secure_path="#secure_path="/vagrant/scripts:#' /etc/sudoers +echo 'export PATH=/vagrant/scripts:$PATH' >> ~vagrant/.bashrc + +# ensure our scripts are executable +chmod 755 /vagrant/scripts/* /vagrant/shims/* + +# do dumb things; SunOS installers expect classful IP addressing +# todo: change so this is only applied when SunOS <= 4.x.x targets are present +echo "Configuring bridge interface..." +IFS=. read -r i1 i2 i3 i4 <<< $SERVERADDR +echo "iface eth1 inet static" >> /etc/network/interfaces +echo " address $SERVERADDR" >> /etc/network/interfaces +if [ $i1 -lt 128 ]; then + echo " netmask 255.0.0.0" >> /etc/network/interfaces +elif [ $i1 -lt 192 ]; then + echo " netmask 255.255.0.0" >> /etc/network/interfaces +else + echo " netmask 255.255.255.0" >> /etc/network/interfaces +fi +ifup eth1 + + +echo "sunboot initialization complete." \ No newline at end of file diff --git a/scripts/target_add b/scripts/target_add new file mode 100644 index 0000000..75bae08 --- /dev/null +++ b/scripts/target_add @@ -0,0 +1,15 @@ +#!/bin/bash + +# sunboot target_add +# +# This script adds a new target to the system, prompting for +# the critical variables if they are not specified on the command +# line. + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +echo "Not yet implemented!" +exit 1 diff --git a/scripts/target_rm b/scripts/target_rm new file mode 100644 index 0000000..19277a6 --- /dev/null +++ b/scripts/target_rm @@ -0,0 +1,72 @@ +#!/bin/bash + +# sunboot target_rm +# +# This script removes all traces of a given target from sunboot, +# including its root filesystem, swap file, NFS exports, bootparams +# entries, hostfile entries and ethers entries. +# This does not delete the actual 'target' file, just the resulting install. +# +# Usage: target_rm [-f] target_name +# +# -f performs the operation without asking for confirmation. + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" + exit 1 +fi + +. /vagrant/scripts/utils.sh + +FORCE=0 + +usage() { + >&2 echo "Usage: $(basename $0) [-f] target_name" + exit 1 +} + +if [ $# -eq 2 ] && [ $1 = '-f' ]; then + FORCE=1; TARGET=$2; +elif [ $# -eq 2 ] && [ $2 = '-f' ]; then + FORCE=1; TARGET=$1; +elif [ $# -eq 1 ] && [ $1 != '-f' ]; then + TARGET=$1 +else + usage +fi + +if [ ! -f /vagrant/targets/$TARGET ]; then + >&2 echo "No target \"$TARGET\" specified in targets directory." + exit 1 +fi + +if [ $FORCE -eq 0 ]; then + while true; do + read -p "Really delete all settings and data associated with target \"$TARGET\"? yes/[no]: " yn + case $yn in + [yY]*) break;; + *) exit;; + esac + done +fi + +. /vagrant/targets/$TARGET + +if [ -z $TARGETNAME ]; then + >&2 echo "TARGETNAME is blank, exiting" + exit 1 +fi + +sed -i "/$TARGETADDR $TARGETNAME\$/d" /etc/hosts >/dev/null 2>&1 +sed -i "/^$TARGETNAME /d" /etc/bootparams >/dev/null 2>&1 +sed -i "/$(normal_ether $TARGETETHER) $TARGETNAME\$/d" /etc/ethers >/dev/null 2>&1 +sed -i "/ $TARGETADDR(/d" /etc/exports >/dev/null 2>&1 +sed -i "/^$TARGETNAME /d" /root/.rhosts >/dev/null 2>&1 + +IPHEX=$(iphex $TARGETADDR) + +rm -f /srv/tftp/$IPHEX* +rm -f /export/swap/$TARGETNAME +rm -rf /export/root/$TARGETNAME + +echo "Target \"$TARGET\" removed." \ No newline at end of file diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100644 index 0000000..8426955 --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +pushd () { + command pushd "$@" > /dev/null +} +popd () { + command popd "$@" > /dev/null +} +error_exit() { + echo $@ + exit 1 +} +normal_ether() { + local e1 e2 e3 e4 e5 e6 + IFS=: read -r e1 e2 e3 e4 e5 e6 <<< $1 + printf "%02X:%02X:%02X:%02X:%02X:%02X" 0x$e1 0x$e2 0x$e3 0x$e4 0x$e5 0x$e6 +} +iphex() { + local i1 i2 i3 i4 + IFS=. read -r i1 i2 i3 i4 <<< $1 + printf "%02X%02X%02X%02X" $i1 $i2 $i3 $i4 +} \ No newline at end of file diff --git a/scripts/xdrtoc.py b/scripts/xdrtoc.py new file mode 100644 index 0000000..cd51039 --- /dev/null +++ b/scripts/xdrtoc.py @@ -0,0 +1,10 @@ +#!/usr/bin/python + +# xdrtoc.py +# +# Read Sun XDRTOC files to determine contents/layout of tape and CD-ROM install media +# These are a binary-packed data format so we are using Python struct() to read it. + +import struct + +# header/magic: 0x674D2309 diff --git a/shims/arch b/shims/arch new file mode 100644 index 0000000..d0960e5 --- /dev/null +++ b/shims/arch @@ -0,0 +1,5 @@ +#!/bin/bash + +. /vagrant/sunboot-settings + +echo $TARGETARCH diff --git a/shims/dd b/shims/dd new file mode 100644 index 0000000..e32e338 --- /dev/null +++ b/shims/dd @@ -0,0 +1,34 @@ +#!/bin/bash + +# sunboot 'dd' - shim to read distribution files +# depending on the if= path, either use the current linked tapefile +# or read the actual file from a mounted CD-ROM + +echo "dd $@" >> /vagrant/cmd_history.txt + +BLOCKSIZE=512 + +for p in $@ +do + IFS='=' read -r cmd param <<< $p + case $cmd in + bs) + BLOCKSIZE=$param + ;; + if) + INPUTFILE=$param + ;; + esac +done + +case $INPUTFILE in + /dev*) + /bin/dd bs=$BLOCKSIZE if="/root/tapefile" + # increment the tape file + ;; + /usr/etc/install*) + /bin/dd bs=$BLOCKSIZE if=$INPUTFILE + ;; +esac + + diff --git a/shims/mount b/shims/mount new file mode 100644 index 0000000..443bb4d --- /dev/null +++ b/shims/mount @@ -0,0 +1,4 @@ +#!/bin/bash + +# CD-ROM media should already be mounted to /usr/etc/install/tar +echo "mount $@" >> /vagrant/cmd_history.txt diff --git a/shims/mt b/shims/mt new file mode 100644 index 0000000..3eb9b40 --- /dev/null +++ b/shims/mt @@ -0,0 +1,44 @@ +#!/bin/bash + +# sunboot 'mt' - emulate tape control commands (rewind/fastforward) +# +# mt [-f ] [command [parameter]] +# +# The -f parameter is accepted but is ignored. +# +# Commands implemented: +# fsf +# rew +# + +echo "mt $@" >> /vagrant/cmd_history.txt + +while getopts "f:" opt; do + case opt in + f) + echo "Option -f specified, value: $OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires a value." >&2 + exit 1 + ;; + esac +done + +shift $((OPTIND-1)) + +case $1 in + fsf) + FILENUM=$2 + echo "Fast forward to file number $FILENUM" + # link correct tape file to /root/tapefile + ;; + rew) + echo "Rewind tape" + # link first tape file to /root/tapefile + ;; +esac diff --git a/sunboot-settings b/sunboot-settings new file mode 100644 index 0000000..0a1f6cc --- /dev/null +++ b/sunboot-settings @@ -0,0 +1,6 @@ +# General environment settings + +SERVERNAME=sunboot +SERVERADDR=10.94.42.7 +NETMASK=255.255.255.0 +GATEWAY=10.94.42.1 diff --git a/sunos/.gitkeep b/sunos/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/targets-disabled/.gitkeep b/targets-disabled/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/targets-disabled/ssx b/targets-disabled/ssx new file mode 100644 index 0000000..5f2cce8 --- /dev/null +++ b/targets-disabled/ssx @@ -0,0 +1,16 @@ +# SPARCclassic Solaris 2.3 Diskful Install Example + +TARGETARCH=sun4m +TARGETNAME=ssx +TARGETETHER=8:0:20:5:61:c2 +TARGETADDR=10.94.42.209 +TARGETSWAPSIZE=64 + +# options: DISKLESS or DISKFUL +INSTALLMETHOD=DISKFUL + +# options: CDROM or TAPE +INSTALLMEDIA=CDROM + +# path (within 'sunos' directory) to the install CD-ROM or directory that contains 'tape1', 'tape2', etc. dirs +INSTALLMEDIAPATH=solaris_2.3_sparc.iso diff --git a/targets/.gitkeep b/targets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/targets/hobbes b/targets/hobbes new file mode 100644 index 0000000..8962edd --- /dev/null +++ b/targets/hobbes @@ -0,0 +1,16 @@ +# SPARCstation IPC SunOS 4.1.4 Diskless Install Example + +TARGETARCH=sun4c +TARGETNAME=hobbes +TARGETETHER=8:0:20:a:7d:8f +TARGETADDR=10.94.42.208 +TARGETSWAPSIZE=64 + +# options: DISKLESS or DISKFUL +INSTALLMETHOD=DISKLESS + +# options: CDROM or TAPE +INSTALLMEDIA=CDROM + +# path (within 'sunos' directory) to the install CD-ROM or directory that contains 'tape1', 'tape2', etc. dirs +INSTALLMEDIAPATH=solaris1.1.2.iso