Skip to content

Instantly share code, notes, and snippets.

@patham9
Last active October 10, 2019 01:12
Show Gist options
  • Save patham9/0ff5f7e4e8867237179b5e46f856fb58 to your computer and use it in GitHub Desktop.
Save patham9/0ff5f7e4e8867237179b5e46f856fb58 to your computer and use it in GitHub Desktop.
Automatic creation of a customized core linux with compact JRE and OpenNARS v3.0.3 (30MB including OS, JRE and OpenNARS), running on NarNode
#Host script for TinyCore, automatic ~30 MB Core linux client setup to run an OpenNARS NarNode with custom input:
#get tinycore, openjdk-8 minimal opennars, if not already there:
ls Core-10.1.iso || wget http://www.tinycorelinux.net/10.x/x86/release/Core-10.1.iso
ls openjdk-8-jre-compact2.tcz || wget www.tinycorelinux.net/10.x/x86/tcz/openjdk-8-jre-compact2.tcz
ls intial_input.nal || echo -e "*volume=0\n<{nars} --> [good]>.\n<{?who} --> [good]>?" > initial_input.nal
ls opennars-3.0.3-SNAPSHOT.jar || wget 91.203.212.130/opennars-3.0.3-SNAPSHOT.jar
#make new iso directories
sudo mkdir newiso
sudo mkdir ./newiso/filedir/
#copy over tc iso contents
mkdir isomount
sudo mount Core-10.1.iso isomount
sudo cp -a isomount/* ./newiso/filedir/
sudo umount isomount
rm -rf isomount
#extract core.gz:
cd ./newiso/filedir/
sudo mv boot ./../
sudo zcat ../boot/core.gz | sudo cpio -i -H newc -d
cd ..
cd ..
#copy over openjdk:
mkdir jdkmount
sudo mount openjdk-8-jre-compact2.tcz jdkmount
sudo cp -a jdkmount/* ./newiso/filedir/
sudo umount jdkmount
rm -rf jdkmount
#copy over opennars
sudo cp initial_input.nal ./newiso/filedir/home/
sudo cp opennars-3.0.3-SNAPSHOT.jar ./newiso/filedir/home/
#create startup script that starts OpenNARS and copy it over, making it executable:
echo 'cat /home/initial_input.nal | /usr/local/openjdk-8/jre/bin/java -cp "/home/*" org.opennars.main.Shell null null null null 64001 127.0.0.1 64002 0.5 null True' > bootlocal.sh
sudo mv bootlocal.sh ./newiso/filedir/opt/
sudo chmod +x ./newiso/filedir/opt/bootlocal.sh
#create core.gz, replacing the old core.gz of standard TC:
cd ./newiso/filedir/
find | sudo cpio -o -H newc | gzip -9 > ./../../core.gz
cd ./../../
sudo mv core.gz ./newiso/boot/
mkdir newisoDEBUG
sudo cp -r newiso ./newisoDEBUG/
sudo rm -rf ./newiso/filedir
#create the iso
tce-load -wi mkisofs-tools.tcz
echo -e "default narslinux\r\nlabel narslinux\nkernel /boot/vmlinuz\ninitrd /boot/core.gz" > isolinux.cfg
sudo mv isolinux.cfg ./newiso/boot/isolinux/isolinux.cfg
sudo mkisofs -l -J -V TC-custom -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinuxboot.cat -o TC-nars.iso newiso
sudo rm -rf newiso
#start the customized tinycore that will run OpenNARS on startup automatically using qemu with kvm support:
tce-load -wi qemu
sudo modprobe kvm-intel
qemu-system-x86_64 -enable-kvm -m 3G -cdrom TC-nars.iso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment