Saturday, June 13, 2015

Hit Me With a Clue-by-four

There's been an uptick in activity on the zipit IRC channel lately.  I like that because it gives me something interesting to read when I get home from work, and it's usually more entertaining than the TV.  Also, it gets me thinking.  The other day (actually quite a while ago now -- I've fallen behind with the blogging) someone on the IRC said something that really whacked me upside the head with a cluestick.  Truth be told, it was a couple of good whacks. 

The first hit came while were discussing ssh and sshfs (and a bunch of other nonsense) but it got me thinking about the sshd on my Arch zipit.  I remembered doing some memory checks in top while working on gmenu2x and gmu for Arch, and sshd was always there, devouring a rather large pile of the precious few 32 megabytes of RAM on the zipit - 3.8MB for the daemon, 5.1MB for a connection, and maybe another 5MB to run it from systemd.  Holy cow, that leaves almost nothing for compiling.  No wonder it was soooo painfully slow on the zipit.  It must've been swapping like mad just to get anything done.

Arch zipit with an open sshd session

Both IZ2S and openwrt run the dropbear daemon instead of the full blown sshd, and it appears to use significantly less memory, likely by trading slower speed for smaller size.  There's no Arch dropbear package for arm processors, so to save time I attempted to use the static dropbear executable from the aboriginal linux extras folder.  I believe we went that route for IZ2S.  So I grabbed the Arch X86 dropbear package, manually extracted the files into the right place, and replaced the X86 executables with softlinks to the aboriginal dropbear executable.  This gave me the systemd script needed to start and stop dropbear with systemctl, and it also included the man pages, which can be handy.  I'm new to systemd, so I played with systemctl for a while -- stopping sshd, starting dropbear, and so on.  I eventually learned that I could make things easier if I used dropbearconvert to get the two daemons using the same keys.  Nice.  However, I never managed to convince the aboriginal dropbear executable to accept my password.  I was gonna have to endure another glacially slow compile session and build an Arch dropbear executable myself.  Darn it!

I fetched the sources and did a practice compile on my laptop to see what to expect.  Looked like it might be a real bear :) to compile on the zipit.  But, as fate would have it, about this time I got another whack from the cluestick and remembered the Arch zipit was only running at 208MHz.  No wonder things were taking forever!  How could I be so stupid?  So I fetched the cpu speed script from openwrt and bumped the zipit up to 520MHz for the compile.  Also, this time I closed my ssh session and ran systemctl on the zipit to stop the sshd and free up all that RAM normally tied up by sshd and systemd.  Then I started the build.  It was greased lightning compared to my previous compiling sessions on the Arch zipit.  In about an hour (yeah ok, it's not all that fast) I had a working set of dropbear executables.  According to top, dropbear was using about 0.7MB of RAM for the daemon and 1.6MB for an ssh session.  That's a significant savings over sshd.  And if I want the convenience of compiling via ssh from my laptop (for the bigger screen) I can save another 5MB by stopping dropbear in systemd and temporarily running it from the command line instead.

Arch zipit with an open dropbear session

Things are really starting to shape up for a leaner, meaner Arch zipit.  We just need to tackle the other big fat bloated RAM hog in Arch -- systemd itself.  On the IRC channel justplainmike did some work on replacing systemd with the busybox init app, some standalone flavor of udev, and a minimal init script.  I'm not sure if that ever worked out, but he's also got the Arch compiler running in a qemu chroot.  So I've gotta try that, just as soon as I get a bigger hard disk for my laptop.

Meanwhile I need to assemble some sort of package for the Arch arm dropbear.  For now, here's a tarball of the contents of the X86 package with the executables replaced.

dropbear-arch-zipit.tgz

Also, the default all red color scheme and Gigabyte memory units in top makes my head hurt.  Do yourself a favor and fix it.  Just press E several times to get to MiB, then Z7S4 to change the list and status colors, and W to save it in your .toprc file.


Update -- December 2015: 

Dropbear is a real package now for arm in Arch, so the tarball above is pretty much obsolete.  Also, mozzwald has rolled out a new zipit Arch image with the dropbear package pre-installed, so you might want to start with that.  I've updated this older blog post with the details.

No comments:

Post a Comment