Thursday, March 5, 2015

Getting Linux on the Minix Neo Z64

      I have recently received the latest Minix Neo Z64, courtesy of Minix. This TV Box is equipped with an Intel x86 processor, an Atom 3735F, which is not so far off a low-end PC desktop but at just 2.2W making it fanless. You can check its respectable specs at this Intel page, and even compare it against other Intel CPUs.



The Z64 is smaller than previous Minix TV boxes, which is nice. As always, a good quality power adapter, HDMI cable, and remote are bundled in the box. The Wifi antenna design is non-detachable, and this time I have been unable to find a way to open the box in order to take the customary PCB photo. Sorry about that :-(

Apart from that, you get 32 GB fast eMMC flash (instead of the usual slower NAND flash chip), 2 GB DDR3 RAM at 1333 MHz, two (ouch) USB 2.0 ports, Ethernet 10/100 (ouch), Wifi and Bluetooth.

I find several big reasons to prefer this TV box over ARM ones:

- the x86 architecture is completely PC SW compatible (think Adobe Flash)

- Intel has a solid background on Open Source, like its Linux GPU drivers (2D/3D) which are top of the line. You even have 3D support on the HDMI interface (see 5.4.1.3 at the CPU datasheet here).

- For HW accelerated video decoding you have a VPU supporting 1080p60 decoding for H-264,  WMV9, and MPEG-2 (see 1.4 on Type 3 SoC at the CPU datasheet here).
 
- And one important thing: the USB controller. Usually ARM CPUs have DesignWare's USB controller, which has nasty and buggy firmware/driver, leading to lots of problems with USB devices (webcams, external hard disks, 10/100 USB Ethernet and Wifi dongles). However, here we have a good and robust Intel USB controller.

The last reason alone has made me jump into switching my NAS home media server (which has several USB hard disks) to this Minix Neo Z64 with Linux.

This tiny Intel CPU even has virtualization features (VT-x), you could even install Xen on this (or even Qubes-OS, if you are serious about secure computing).

So... sorry Windows 8.1, you look nice and you run fast, but Linux and I...


Hence, find here instructions to get into the Minix Neo Z64 whatever distribution of Linux you prefer. I don't like creating distros when you can very easily install a standard one.



Live Linux USB


     First of all get a USB pendrive that can be erased, so we can start Linux on the Z64 to make a backup of Windows, before removing it.

I've developed a liking for Xubuntu (XFCE based) after Canonical decided to outsmart all of us by inventing their hateable GUI, and then Gnome followed suit with its 3.0 version.

You can use any version of Ubuntu, they'll work the very same way as described here. Just head to the corresponding official Ubuntu page and download the x86_64 version (also called amd64) of the distro.

I wish I could tell you that's it, but truth is somebody messed up somewhere and all Intel Atom boxes/MiniPCs I know happen to have a 32 bits UEFI BIOS, which complicates booting a 64 bits OS, so there is one extra step.

This consists of adding a 32 bits bootloader to the 64 bits one in the Ubuntu distro so it can boot, that's it. You can either download the bootia32.efi bootloader from this link or you can follow the instructions (from the same place) to build it yourself.

Now, about creating a LiveUSB for UEFI systems and modifying it... people around are resorting to using a tool called Rufus that requires you to use Windows... ugly.

However, there is a simple way (thanks lopaka) to do everything from your usual Linux PC (the lines preceded with "#" are just my comments, disregard them):


#first erase the USB pendrive
sgdisk --zap-all /dev/sd_
#create a new GPT partition for booting on UEFI systems
sgdisk --new=1:0:0 --typecode=1:ef00 /dev/sd_

#create a FAT32 partition, as expected by the UEFI BIOS
mkfs.vfat -F32 /dev/sd_1

#create a temporary folder

mkdir image
#mount the FAT32 partition (only root can mount)
sudo mount -t vfat /dev/sd_1 image/

#uncompress Ubuntu onto the mounted USB
sudo 7z x xubuntu-14.10-desktop-amd64.iso -oimage/

#add the 32 bits bootloader (see blog above)
sudo cp bootia32.efi image/EFI/BOOT/

#finish any pending writes
sudo sync

#unmount the USB
sudo umount image

#remove the temporary folder
rmdir image

Please note that ALL references to the USB disk above are in the form "sd_" or "sd_1", this is because you can delete your hard disk if you just copy paste this code, so don't!!! You first have to find if your USB pendrive is at sdb, sdc, sdd, sde, or whatever sd*.
Easy way is, without the USB drive inserted, type in a terminal:
ls /dev/sd*
And then again, after inserting the USB. The new sd_ (without trailing number) is your pendrive. Use that letter instead of the "_" above.



BIOS settings


   In order to boot the Live USB, connect a keyboard to the Minix and as soon as you press the power button, start pressing several times the "Del" key to enter BIOS setup (if screen remains black after 10s, then you'll need a PC monitor instead of a TV to see it).

BTW, the sensible way to forcefully power off the box, if there is nothing on screen, is to keep pressed the power button for a bit more than 5 seconds.

On the BIOS screen, go to "Advanced", then "CPU Configuration" and on the "Execute Disable Bit" hit Enter and select Disabled.


By the way, just in case you dig through the BIOS options, you may see one named "ISP PCI Device Selection", just ignore it. I say this because it mentions that it should be another value for Linux, but never mind that, leave it at Windows.

However, there is a very important change to be done, find the "Quiet boot" item. It must be disabled since there seems to be something missing in the GFX initialization that the BIOS is doing but Linux is missing. Maybe the logo that appears (when Quiet boot is enabled) instead of the usual BIOS text is pushing the GPU into an incompatible video mode, and it prevents booting Linux (black screen).

Head to the last menu page (the one on Boot options) and select the option to Save Settings (without reset or exit, just save).
 
Finally, if the above instructions for the USB preparation were followed, you should see the pendrive's name or brand listed in the "Boot Override" choices at the bottom, select it and hit Enter to boot.

On the grub2 menu that should appear select "Try Ubuntu before installing".
If you get a black screen or Windows, then you may be missing the bootia32.efi file, re-do the instructions above on USB preparation.


Backup Windows 8.1


      Since Minix bundles a fully licensed Windows 8.1 with Bing (as opposed to many other TV boxes that come with a 30 days trial version), it is a good idea to back it up to avoid losing the licensed OS, in case we wanted to switch back to it anytime.

This part of the instructions is based on this CNX-Software's page, the news site for hacking with embedded devices; though there are additional things to make Linux work on the Z64.

We will install "pv" as a convenience, to monitor the copy's progress, since the backup takes several minutes to complete.

Just open a terminal and cd into the folder of another USB pendrive (the Live USB is read only so nothing survives reboot) to execute these commands:

sudo apt-get install pv
sudo dd if=/dev/mmcblk0 bs=16M | pv | gzip -9 > Z64_Win81.gz

Most of the 32 GB flash is empty, so gzip'ing it produces a much smaller file (mine was some 4 GB, instead of 32 GB)

To restore Windows 8.1 from the backup you should follow this section up to the "pv" install, and then do:

gzip -dc Z64_Win81.gz | pv | sudo dd of=/dev/mmcblk0 bs=16M


Installing Linux in Flash


Finally! Click on the icon to Install Ubuntu and start the setup as usual.

When asked about the partitioning select the do "Something else" choice and you'll be presented with the current partitioning of the internal eMMC flash that contains Windows 8.1.

We are going to wipe Windows. But you have to leave the first two partitions untouched, they are mmcblk0p1 and mmcblk0p2. Together they amount to less than 240MB and are needed to boot EFI (at least p1, the FAT32 one).

However, you can perfectly remove the "Win" and "Images" partitions, which together are around 30 GB of space.

I used all but 2 GB for an ext4 partition to be mounted at "/" where Linux will reside, and the remaining 2 GB for swap partition (the ancient recommendation is to match your RAM size in swap).

Even if this is a Flash, it's ok to have a swap partition, it should be seldom used, only when you start filling up the RAM, but a home server should be ok even without it.

On the booloader device dropdown at the bottom of the new window, select "/dev/mmcblk0" not other, just that one (or update-grub2 later may update the wrong place and you'll end up with two "ubuntu" entries on the UEFI BIOS).


Once installation is finished (this is based on Linuxium's great work here), you'll need to boot once more with the Live USB, but when presented with its grub2 menu, press 'c' to go to its console and enter these three lines:

linux (hd1,gpt3)/boot/vmlinuz-3.16.0-31-generic root=/dev/mmcblk0p3
initrd (hd1,gpt3)/boot/initrd-3.16.0-31-generic
boot






If you used a different Linux distro, the version numbers may be different. You can use grub's auto-completion, with the Tab key, to help you find your vmlinuz and initrd files for you.

 The Ubuntu that you have installed on the internal eMMC flash will boot up, connect to the Internet with an Ethernet cable (there is no wireless out of the box) and enter these commands on a terminal:

sudo apt-get install grub-efi-ia32 grub-efi-ia32-bin
sudo cp /boot/efi/EFI/ubuntu/grubia32.efi /boot/efi/EFI/ubuntu/grubx64.efi
sudo update-grub2


Now you can power off, remove the pendrive, and boot again

You should then boot to your Linux.


If you see a Windows bluish screen stating that there is something wrong, then you'll have to enter the BIOS once more and change the Boot priority #1 to "ubuntu".


Limitations


Please note Wifi (Realtek RGN RTL8723BS) is not working out of the box, but CNX-Software's page provides info on compiling its drivers from source.

Also the sound (Realtek ALC5642) is not working, there is one person around that says to have fixed it by using Chromium's Intel firmware (see this page) but I've tried it and, even though a new output appeared in the audio mixer, nothing sounded and the "dmesg" log was full of errors related to audio.

If you google around for ALC5642 and Linux there seems to be a good place to look for the driver (see this page) whenever it appears.


That's it. Enjoy!






15 comments:

  1. What about Linux installing 64bit to the internal storage rather than booting off of USB?

    ReplyDelete
    Replies
    1. You haven't read the full post. See section "Installing Linux in Flash", USB is only for installing 1st time.

      Delete
  2. OK, please ignore the prior comment. I just read it fully and you ARE installing internally! Thanks so much!

    ReplyDelete
  3. just wanted to let you guys know, that i have been able to run Fedora 22 straight from internal emmc:

    - since the z64w UEFI is only 32bits I flashed the BIOS with the z64a firmware (64bit UEFI) to eases the pain of EFI/grub.conf-tweaking
    - Fedora 22 Minimal Install from USB-Stick sees the internal memory (mmblk0), so the Anaconda installer can handle the volume.

    lesson I've learned:
    the internal emmc supports/is CSD struct 7, which is not supported by older kernels (not sure, but i think below 3.18),

    Maybe this helps one or another.

    ReplyDelete
  4. Hi Galland,
    My Windows 8.1 Bing does not boot anymore and I don't have a backup (yeah I know, I should have done one!)...
    Can you share your backup?
    Thanks!

    ReplyDelete
  5. I installed ubuntu 14.04.4 server on my z64. It looks like my BIOS is already 64bit, because I didn't do any trick mentioned in this post. I simply go to BIOS and set boot override with a USB disk then install. When install it, it claims can't detect cd-rom. I fixed it by pull out and plug the usb stick in a different USB port then it continued without problem.

    After reboot it boots to ubuntu without problem.

    The problem is at the login. In any tty, type in the login name for the first time, it doesn't echo the user name on screen, and it shows "Login incorrect". Type in the login name for the 2nd time, it prepend a ^[ before each character of the name, and login still fail.

    Any suggestions?

    Thanks

    ReplyDelete
  6. Can you provide more info about the partitions?
    I have /dev/sda, /dev/mmcblk0boot0, /dev/mmcblk0boot1 and /dev/mmcblk0 partitions in debian.

    Which I have to maintain?

    Thanks

    ReplyDelete
    Replies
    1. Done: https://github.com/somenxavier/neoz64/blob/master/README.md

      Delete
  7. Hi,
    is there any update on the sound issue, is it already solved? What does it exactly mean, if the soundcard does not work, is there no audio over HDMI either?
    Thanks

    ReplyDelete
  8. Hi, have any advice when Ubuntu (and others) just freeze during Installation?

    ReplyDelete
  9. Just installed Ubuntu Mate on the Neo Z64 over the holidays and learned a lot:

    Regarding freezes: there is currently a bug in the linux kernel that causes this on Bay Trail processors. See https://bugzilla.kernel.org/show_bug.cgi?id=109051 for details. Workaround is to add intel_idle.max_cstate=1 to the boot options. See https://help.ubuntu.com/community/BootOptions about boot options, or in the text-based Live CD menu that I used, you can hit 'e' to edit the kernel options. I needed that option in order to successfully complete an installation. And needed to add it to the GRUB configuration so that it is included in each boot (google it).

    Regarding partitioning: I was not intending to backup the exisiting installation, so just told Ubuntu to use the entire disk, and that went well.

    Coming from the Android version of the Neo Z64, no tricks are needed to fix the UEFI, it just works. If trying to flash an ISO to a USB stick on a Mac, you need to convert the image first, otherwise the partition will not be recognized as bootable. For example, see http://www.lewan.com/blog/2012/02/10/making-a-bootable-usb-stick-on-an-apple-mac-os-x-from-an-iso.

    Regarding drivers, I used one of Linuxium's ISO images. I chose the Ubuntu Mate image because it's quite lightweight and it works well. http://www.linuxium.com.au/how-tos/runningubuntuontheintelcomputestick. It still needs the intel_idle.max_cstate=1, but includes working drivers for audio and WiFi.

    Good luck

    ReplyDelete
  10. Hi Is bluetooth working for anyone? I installed Ubuntu and everything except Bluetooth works.

    ReplyDelete
  11. Bluetooth works, I am a regular user of this.

    ReplyDelete
  12. Hey, i'm getting into shell and cannot continue.
    managed to get into grub, but also without luck.
    disabled the executive bit and quick boot.
    how can i start the installation from the shell??
    thanks

    ReplyDelete