Regular reader will know about the script (original blog material now ditched though the old script is still on BitBucket) that Aidan Ruff and I originally developed to put Node-Red and several other packages onto the Raspberry Pi for our own home control purposes.
Well, that original script continues to mutate to run on several different boards and my one big gripe has been the amount of interaction once the script starts.
Originally designed to run under Debian – reader Antonio and I have also made the script compatible with Xenial. So now Raspbian, DietPi (Debian) and the Armbian versions of Debian and Xenial (Ubuntu) as well as the DietPi VM.
Before I begin... no, we’re not a support shop – you may or may not end up having to tweak things for your system but please don’t write in to say “I tried this on a Mac and it doesn’t work”).
The level of interaction after the beginning is now zero thanks to a new menu-driven approach and many improvements including using a VM (virtual machine) to test the whole thing at accelerated speeds. We continue to add/modify features as appropriate.
What is this about?
What we have here is an explanation of how to get Xenial running in a VM – the purpose of this is merely as a base to test the new script mentioned below which will install somewhat more than the original script (designed originally for Raspberry Pi but now working on several Debian-based devices and now Xenial) – namely:
- Node-Red at port 1880 and lots of useful NODES
- Mosquitto (MQTT) with Websockets
- Webmin at port 10000
- Apache at port 80
- HA-Bridge at port 82 (suitable for Amazon Alexa)
- SQLite and PHPLiteAdmin
- MC File manager and editor
- Lots more – see the menu screen
Typically this setup would be used as the basis of a nerve-centre to control and monitor home control gadgets such as the ESP8266 units we discuss in this blog, Sonoff controllers and much more. Armed with this software, controlling the home is easy – and more importantly can be done YOUR WAY.
The Virtual Machine
Let’s take a look at what we did – you can of course duplicate all of this as you go along. We used the excellent VMware of VirtualBox on Windows PCs. This explanation covers VMware.
So – first things first – as I’ve done a video of the Virtualbox installation complete with sample use of Node-Red, here we’ll discuss the VMWARE version. Both of these were done as test mechanisms before using the script on real devices such as the Orange Pi Zero, Raspberry Pi, Odroid and other devices discussed at length in the blog.
We loaded up a copy of VMware (I used VirtualBox but the procedure is similar – VMware player is free of you can use the full commercial workstation) and made sure it works. That much is up to you. There is a wizard for creating new virtual machines - we chose a CUSTOM machine. Steps from that point on were:
NEXT - NEXT – “I will install the operating system later” – NEXT
Linux / Ubuntu 64-bit – NEXT – d:\test - NEXT
Number of processors – 1 - number of cores – 1 – NEXT
Memory for this machine – 1024MB – NEXT
Use Bridged Connection - NEXT
I/O Controller type LSI Logic - NEXT
Disk Type SCSI - NEXT
Create a new virtual Disk - NEXT
12GB (I used 16GB – 8GB would have done) – Store virtual disk as a single file - NEXT
At this point we gave the file a name – in our case d:\test\Ubuntu 640bit.vmdk - NEXT – FINISH
Under settings – hardware – CD/DVD we ticked “Use ISO image file” and selected the file we loaded from the Ubuntu website – “Ubuntu-16.04.1-server-amd64.iso” – OK.
At this point you’ll note reference to AMD64 – that had me as well but it works a treat on INTEL hardware.
Start off the VM – you get asked which language to use (ENGLISH) and various options will come up – the first being “Install Ubuntu Server” – that’s the one.
Once again you’ll get a language question – English. Location – in my case “United Kingdom” – if you don’t fit into the rules use “Other”.
Time Zone in my case – EUROPE and then country. Locale – in my case United Kingdom.
Hostname – we went with the default “Ubuntu” – but call it whatever you want.
At this point you get asked to create a user – it is important you make a user “pi”. Enter password also (though the new script will create user PI if it does not exist).
Partitioning – “use entire disk” (remember this is a virtual disk – not your real disk). You are then asked to confirm erasing disk – go with that. You then get asked to confirm AGAIN. YES.
HTTP Proxy just leave blank – CONTINUE.
Install security updates automatically.
Add OpenSSH server and CONTINUE (important for remote access)
Install GRUB bootloader – YES.
Installation is complete – CONTINUE. Let it run.
And voilà – one working copy of Ubuntu. You have a pi user – at this point you’ll want to give ROOT user a password (sudo passwd root).
You need ROOT user for the next step.
No matter what machine you are using – you need a “pi” user and to make life simple – and compatible with that of the original Raspberry Pi user, a little command line work is needed. The rest is handled in the script.
So as ROOT user…
adduser --quiet --disabled-password --shell /bin/bash --home /home/pi --gecos "User" pi echo "pi:password" | chpasswd usermod pi -g sudo echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/pi chmod 0440 /etc/sudoers.d/pi
The FIRST and SECOND lines are not needed if you followed the instructions above as you already a “pi” user.
The BASH Script
This part is about running the script and assumes a “pi” user with SUDO capability though if you have a system that does not have this user, run as ROOT initially and the user will be created.
Create a file called script.sh in the pi directory and populate it from the script.
Ensure it has EXECUTE permissions.
and that is that. as PI user, in the /home/pi directory you should now have this script.
At this point BACK EVERYTHING UP to avoid disappointment – no, REALLY.
You will see a menu which will vary slightly depending on which system you are using – you won’t be asked about GPIO on a Raspberry Pi for example.
For the VM we left everything as you see here and tabbed to OK.
At this point you will be asked for a USER and ADMIN names (which can be user and admin if you like) and corresponding passwords. From there on – everything should happen with no user interaction.
After maybe 15 minutes – or an hour - ore a lot longer on a Raspberry Pi Zero WIFI – you’ll see an invite to REBOOT – so REBOOT. When the board/VM boots up you will find hopefully a working system.
Assuming you've installed everything:
- Node-Red runs at port 1880
- Webmin at port 10000 (Webmin needs Pi or ROOT username and pass until we figure out how to add in the ADMIN user).
- Apache runs at port 80
- HA-BRIDGE will run at port 82 – It seems that Amazon Echo is quite happy with this but the Google product wants port 80!
Node-Red should include MQTT which will need admin username and password as will Node-Red itself. USER name and password is used by Node-Red Dashboard.
There is also the excellent MC – a file manager and editor.
I hope this brief introduction sets you off in the right direction and of course no doubt there will be discussing in the notes below.
Update Dec 29: Early start this morning - just for the sake of it I’ve just taken the Ubuntu desktop image, installed it on a laptop (a very old laptop) and ran the script – perfect – everything installed. My thanks to Mr Shark for filling in the blanks in my Linux knowledge.
Update 05 Jan 2017: At the time of writing I'm having issues with PIXEL in VirtualBox and DEBIAN on VirtualBox in terms of Apache not loading.. I'm sure we'll sort that - meantime some useful links. Debian may not some with SUDO depending on which installation - here's a fix link that worked for me in my VirtualBox image.. If SSH setup won't allow remote access using passwords, here's a link that helped me. Pixel of course will run in Virtualbox but by default it runs of a virtual DVD which is about as much use as an ashtray on a motorbike as nothing gets saved. Once running however it is a breeze to move over to the Virtual hard disk - you'll find that part way down the comments in this link. So right now I have VirtualBox running Xenial, Pixel and Debian and the only issues I have are with Pixel and Debian - Apache - watch this space. I’ve also improved the input for user and admin.
Important: Whatever you are using should have the SUDO command built in – it may not be obvious but Debian often does NOT have this installed by default – sort this FIRST. You should also make sure you have Pi user with SUDO group privilage – PI already has this of course and you may have added a user Pi – if not..
su -c "bash makepi"
Or, Here’s a useful link – takes seconds and is easy… basically – as root you can do - apt-get install –y sudo….. and you should make sure that your PI user is part of the sudo group.
Update March 31, 2017: the new version of the script "the script" works with the brand new NanoPi NEO2 and the NanoPi M1+ and features temperature monitoring and other improvements.
If doing this as a non-Pi user – ie ROOT on a machine with no Pi user – follow instructions above OR a slightly easier way…
Having uploaded the script and given permissions… as ROOT
as before – but when it has completed and wants you to log in as PI – stay where you are and:
su - pi -c /home/pi/script.sh
That might save you a little hassle.