Saturday, February 8, 2014

Debian 7.3.0 PowerPC

Getting something running under QEMU Alpha the other day inspired me to try to get something running under QEMU PowerPC too. I've piddled around with it before and I was able to get a uClibc/Buildroot system running once but that's as far as I ever got. Aaaand, considering that Buildroot has a board definition specifically for a QEMU-emulated Beige G3, it didn't seem like much of an accomplishment.

Long story short, I was able to get Debian 7.3.0 running.

Long story long, here's how...

I downloaded an install DVD from ftp://cdimage.debian.org/cdimage/release/current/powerpc/iso-dvd/debian-7.3.0-powerpc-DVD-1.iso. Modern Debian still supports PowerPC, so this time I didn't have to go digging around for old copies.

I created a disk image...

qemu-img create debian_powerpc.img 6G

...and the adventure began.

To install in text mode, I usually extract the kernel and initrd from the ISO, aim the kernel at the emulated serial port and use QEMU's -nographic option, but that proved impossible with Debian PowerPC. No matter what options I passed in, the kernel ended up aimed at the VGA console. At first I just used that but eventually realized that the arrow keys didn't work and ended up using VNC. This was tricky too as my VNC viewer would reliably crash when I aimed it at QEMU. After a great deal of googling, the internet revealed that most VNC clients don't have this issue, but mine does and one solution is to go into expert mode and set the ColourLevel to pal8. Ok. Got it... and it worked. Yay!

So, to summarize, I ran QEMU with...

qemu-system-ppc -M g3beige -hda debian_powerpc.img -cdrom debian-7.3.0-powerpc-DVD-1.iso -boot d -net bridge -net nic,macaddr=aa:00:00:00:00:16 -vnc :1

...then aimed my reconfigured VNC client at port 5901 and began the installation.

Things went smoothly from there, albeit slowly. The bootloader wouldn't install though, so I couldn't boot from the drive image directly. Like on the Alpha, I had to extract the kernel and initrd and aim QEMU at them directly.

This involved creating another drive image...

dd if=/dev/zero of=fakedisk.img bs=1024 count=20000

...restarting QEMU...

qemu-system-ppc -M g3beige -hda debian_powerpc.img -hdb fakedisk.img -cdrom debian-7.3.0-powerpc-DVD-1.iso -boot d -vnc :1

...then letting the installation proceed until the "Loading additional components" phase finished, then hitting Alt-F2 and return to get a shell on the second virtual screen. There I was able to mount the boot partition...

modprobe ext4
mount /dev/hda2 /media

...and dd the kernel from it to the other drive image.

dd if=/media/vmlinux-3.2.0-4-powerpc of=/dev/sdb

Then, on the host, outside of the vm I could extract it...

dd if=fakedisk.img of=vmlinux-3.2.0-4-powerpc bs=1587497 count=1

...and do the same for the initrd with...

dd if=/media/initrd.img-3.2.0-4-powerpc of=/dev/hdb

...and outside of the vm:

dd if=fakedisk.img of=initrd.img-3.2.0-4-powerpc bs=11060461 count=1

It seems like a lot of work, but knowing what to do from having done it before, it wasn't so bad.

Kernel and ramdisk extracted, I tried to boot to the drive image but ran into trouble with the Gnome Desktop Manager. It failed to start outright when using VNC and the mouse didn't work when I tried using QEMU's VGA console directly. Dangit!

The solution was to boot into single user mode and disable GDM. This was trickier than I expected though, as the system didn't appear to be honoring the "single" boot option at all. The best I could do was boot to a shell using init=/bin/sh:

qemu-system-ppc -M g3beige -kernel vmlinux-3.2.0-4-powerpc -initrd initrd.img-3.2.0-4-powerpc -append "root=/dev/sda3 init=/bin/sh" -hda debian_powerpc.img -vnc :1

From there I was able to remount the root filesystem read-write and disable gdm though.

mount -o remount,rw /
/usr/sbin/update-rc.d gdm3 disable

Neither halt nor shutdown worked from the shell though, so I had to just sync a few times and power off the vm.

Ok... So. After all that. One more try:

qemu-system-ppc -M g3beige -kernel vmlinux-3.2.0-4-powerpc -initrd initrd.img-3.2.0-4-powerpc -append "root=/dev/sda3 init=/bin/sh" -hda debian_powerpc.img -net bridge -net nic,macaddr=aa:00:00:00:00:16 -vnc :1

Success!

debian 7.3.0 powerpc - 1. first login

From there, I disabled various services I didn't plan on using, installed bits of development software and apt-get upgraded everything. I had to comment-out the DVD it /etc/apt/sources.list to get apt to ignore it, but after doing that, the system felt like any other Debian distro.

Getting some kind of working graphical interface (other than twm) was tricky. Debian 7.3.0 comes with Gnome 3, which requires hardware acceleration to run at all, and it failed pretty miserably. I was eventually able to get xfce running by installing the xfce4 package and aiming it at a nested X server running on my PC.

debian 7.3.0 powerpc - 2. xfce

It ran fairly slowly, but it ran. Bumping the memory up to 256M from whatver the default was (128 I think) helped.

The only issue I had was that the xfce terminal defaults to "use colors from system theme" which, for some reason, gave me black text on a black background. Unchecking that box gave me black on white. Aside from that, everything worked as expected.

Being a modern distro, I could browse the web, no problem.

debian 7.3.0 powerpc - 3. web

The local apache install worked too.

I was able to build and install all of my software. The SQL Relay server components ran fine against MySQL and PostgreSQL. I was able to access a remote Oracle database using the client components.

debian 7.3.0 powerpc - 4. sqlrsh

I tried and tried and tried to get a getty to run on the serial port but nothing I did had any effect. Ditto for aiming the kernel output at the serial port. It was odd. I know that both QEMU and the linux kernel both support the serial port because the uClibc/Buildroot distro worked with it just fine. It's very strange. Maybe I'll look into it someday. For now, I'm stuck with VNC, but really, that's not so bad.

QEMU's idle-loop detection appeared to work reasonably well. I never heard the fan screaming on the server like it does with some VM's and when I wasn't doing anything useful with the VM, top on the host showed minimal CPU usage. So, if I had the memory to spare, I guess I could leave it running and put it in my build farm.

Ok... So, one more platform running successfully in emulation. Woohoo! On to the next one.

Sunday, February 2, 2014

Debian 5.0.10 Alpha

I've been trying to get qemu-alpha working for years now. The furthest I ever got was partially booting a Debian ramdisk. It would boot into the installer as long as I didn't specify a CD to install from. If I did, qemu would crash right after detecting it. If I didn't, there was nothing to install from. I might have somehow installed from the internet but version 5.0.10 was the end of the line for Alpha support by the time I figured out how to get the installer to boot, the online repositories were long gone.

DVD's are still available at http://cdimage.debian.org/mirror/cdimage/archive/5.0.10/alpha/iso-dvd/ though, so if I could get qemu to keep from crashing, maybe I could install from the DVD.

Qemu 1.7.0 came out a little while ago and yesterday I gave it a try. I didn't notice anything in the release notes about updates to the alpha emulation but hey, you never know... Much to my surprise, the kernel detected the cdrom, didn't crash and began the installation. Woohoo!

It wasn't totally smooth though. The kernel reported the DVD but the installer couldn't find it later. I had to play around a bit, but eventually I was able to get the installation to work using:

qemu-system-alpha -kernel vmlinux -append 'console=ttyS0' -initrd initrd.gz -drive file=debian_alpha.img,if=ide -drive file=debian-5010-alpha-DVD-1.iso,if=ide,media=cdrom -net bridge -net nic,macaddr=aa:00:00:00:00:16 -nographic

I had to extract the kernel and ramdisk from the iso and unzip the kernel. The -drive parameters were necessary instead of -hda/-cdrom parameters too. Without them, the installer can't see the DVD. I'm not sure why.

Before long I was installing.

debian 5.0.10 alpha - 1. Installation

The installation was familiar. I told it to install all packages and aside from having to ignore a few warnings about not being able to access security updates, it went pretty smooth.

I hit my first roadblock trying to boot to the virtual hard disk though. The kernel and ramdisk on the installer disc are different than the kernel and ramdisk that get installed and can't be used to boot to the virtual hard disk. The partition table on the virtual drive wasn't readable by fdisk on the host either so I couldn't determine the offsets of the partitions to try to loopback mount. What to do? What to do?...

There are probably other solutions, but I created a second disk image...

dd if=/dev/zero of=fakedisk.img bs=1024 count=10000

...and booted back into the installer without the DVD so the installer would fail and let me drop to a shell:

qemu-system-alpha -kernel vmlinux -append 'console=ttyS0' -initrd initrd.gz -drive file=debian_alpha.img,if=ide -drive file=fakedisk.img,if=ide

In the shell, I mounted the /boot partition (/dev/hda2) and dd'ed the kernel to the second virtual drive (/dev/hdb).

mount /dev/hda2 /cdrom
dd if=/cdrom/vmlinuz-2.6.26-2-alpha-generic of=/dev/hdb

Then, on the host, I pulled it off of the drive image.

dd if=fakedisk.img of=vmlinuz-2.6.26-2-alpha-generic bs=1587497 count=1

I then repeated this to get the ramdisk.

In the vm...

dd if=/cdrom/initrd.img-2.6.26-2-alpha-generic of=/dev/hdb

...and on the host:

dd if=fakedisk.img of=initrd.img-2.6.26-2-alpha-generic bs=9271534 count=1

Got em.

Now to restart qemu...

After some trial and error, I eventually discovered that with the VGA console disabled, gdm would crash qemu. The solution was to start linux in single-user mode...

qemu-system-alpha -kernel vmlinux-2.6.26-2-alpha-generic -append 'console=ttyS0 root=/dev/hda3 single' -initrd initrd.img-2.6.26-2-alpha-generic -drive file=debian_alpha.img,if=ide -drive file=debian-update-5.0.10-alpha-DVD-1.iso,if=ide,media=cdrom

...then disable gdm...

cd /etc/rc2.d
mv S30gdm K30gdm

...and then restart in multi-user mode.

qemu-system-alpha -kernel vmlinux-2.6.26-2-alpha-generic -append 'console=ttyS0 root=/dev/hda3' -initrd initrd.img-2.6.26-2-alpha-generic -drive file=debian_alpha.img,if=ide -drive file=debian-update-5.0.10-alpha-DVD-1.iso,if=ide,media=cdrom -net bridge -net nic,macaddr=aa:00:00:00:00:16 -nographic debian 5.0.10 alpha - 2. Login

Actually while I was disabling gdm, I also disabled other services I didn't plan on using like smartmontools, dhcdbd, winbind, spamassassin, and so on.

At that point, it was running, rather quickly actually, and felt like any other older Debian system.

I configured it with a static IP, added the Updates DVD to apt and installed openssh-server and various bits of development software. This required a bit of switching DVD's back and forth and I had to look up how to use the qemu monitor again.

Everything ran pretty well at that point. Networking worked. I could ssh into the machine. Apache worked. I could check out and build my software. I did run into a quirk with ODBC but that's why I like to build my stuff on these odd platforms. You never know what you'll find.

Gnome worked after rebooting with 256mb of emulated ram and aiming X at a nested X server on my PC.

debian 5.0.10 alpha - 3. Gnome

I could browse the web, albeit a little slowly.

debian 5.0.10 alpha - 4. Web

And finally, I was able to run the SQL Relay server against SQLite, PostgreSQL and MySQL and the client against a remote SQL Relay server to access Oracle.

debian 5.0.10 alpha - 4. sqlrsh

Yay.

So, finally I got linux running in an Alpha emulator. The only remaining problem is that it kind-of slams the host CPU. I guess qemu doesn't do idle-loop detection for Alpha, or if it does, it doesn't work with Debian. Either way, it's rough.

Still, it's a big step. I'll have to try some of the BSD and old Redhat alpha distros too.