This works on the v3 firmware of the Moxa UC-8100(-LX)
Log into Moxa
Edit /etc/network/interfaces to enable DHCP on LAN1
iface eth0 inet dhcp
#iface eth0 inet static
# address 192.168.3.127
# network 192.168.3.0
# netmask 255.255.255.0
# broadcast 192.168.3.255
Reboot. Update available packages.
sudo apt-get update && sudo apt-get upgrade -y
To ensure that DHCP works even if network cable is not plugged in at boot time:
sudo apt-get install netplug ntpdate
Set time zone to UTC
dpkg-reconfigure tzdata
select 13 > 33. UTC
Install snapd
sudo apt-get install snapd -y
Install and test squashfs module
cd /lib/modules/4.4.0-cip-uc8100+/
sudo mkdir extra
sudo cp /path/to/squashfs.ko extra/
sudo depmod
sudo modprobe squashfs
Install snaps
sudo snap install ammp-edge
sudo snap install --dangerous --devmode /path/to/ammp-tunnel_1.1_multi.snap
Verify that services are running and that SSH tunnel is up.
Remove unnecessary packages, e.g. apache2.
Shut down Moxa. Grab SD card and make an image of it. Mount it.
sudo dd if=/dev/sdb of=moxa.img bs=4M
sudo losetup -Pfv moxa.img
losetup -j moxa.img
# Note the device name associated with the image, e.g. loop8
mkdir moxaroot
sudo mount /dev/loop8p2 ./moxaroot
cd moxaroot
The following are run from within the moxaroot directory.
Remove snap configuration (which contains node ID) and SSH tunnel log file.
sudo rm var/snap/ammp-edge/common/*
sudo rm var/snap/ammp-tunnel/common/*
Clean home directory and temporary folders
sudo rm -rf home/moxa/* home/moxa/.*
sudo rm -rf tmp/* tmp/.*
sudo rm -rf var/tmp/* var/tmp/.*
If desired, remove logs from var/log.
In a minute, we're going to unmount and shrink the filesystem. But before we do that, we need to ensure that it will be expanded again on boot. The Moxa image has a built-in script to do that, which we can reactivate. Note the service etc/systemd/system/multi-user.target.wants/uc8100_init.service which runs /sbin/uc8100_platform_init start on bootup. That script checks whether the file /sbin/expand2f exists, and if it does it carries out a one-time system initialization + partition expansion; then it moves the file to /sbin/expand2f.bak. So with
sudo mv sbin/expand2fs.bak sbin/expand2fs
we can reset this and force the expansion. The only thing to keep in mind is that this would also lead to a recreation of /etc/network/interfaces. The easiest way to avoid this is to comment out line 99 of /sbin/uc8100_platform_init, which states
set_network_config 2 > /etc/network/interfaces
Now we can unmount and shrink the filesystem. The script for shrinking (https://gist.github.com/svet-b/426c25886be9aa13a9919c0de3b15a20) is adapted from https://github.com/Drewsif/PiShrink/blob/master/pishrink.sh
cd ..
# Replace with actual loop device wherepartition was mounted
sudo umount /dev/loop8p2
wget https://gist.githubusercontent.com/svet-b/426c25886be9aa13a9919c0de3b15a20/raw/e2c339a083b0598ca55a19fddc07204754710daf/moxashrink.sh
chmod a+x moxashrink.sh
sudo ./moxashrink.sh moxa.img
Done. The resulting moxa.img file should be around 1GB and can be compressed to ~500MB.