Code Repo    |     RSS
MD's Technical Sharing



Sunday, January 4, 2015

Keyboard issues in GRUB bootloader on a Mac Mini booting Mac OS, Windows and Ubuntu Linux

The Mac Mini, my main machine for daily work, has the following partition configuration for triple-booting Windows, Mac and Ubuntu Linux: 
  • Partition 1: Mac OS X (HFS+)
  • Partition 2: Windows 8 (NTFS)
  • Partition 3: Ubuntu Linux (Ext4) 
  • Partition 4: DATA (NTFS)
rEFIt is used as the boot manager to allow me to select which partition to boot from at startup. GRUB2 is installed on partition #2 and configured to select between Windows 8 and Linux. This configuration has been working well for a few years.

However, recently after the old USB keyboard (a Microsoft Wired Keyboard 600) failed and had to be replaced with a Prolink PKCS-1002 keyboard, I could no longer select between Windows and Linux at the GRUB2 boot menu, and the system booted to Windows by default. The selection of the Mac OS X partition from the rEFIt menu still worked fine. Once booted to Mac OS, Windows or Linux (by changing the GRUB default entry), I could use the keyboard without hassle. The keyboard issue would still remain even when the Windows 7 BCD bootloader was used, suggesting that the issue was not specific to the GRUB bootloader.

You would probably tell me to go to BIOS and enable USB legacy support, but hey, this is a Mac that uses EFI and boots Windows via BIOS emulation, which most likely would already have legacy USB support, otherwise the old keyboard could not have worked.

Adding keyboard support to GRUB menu

After some research, I decided to follow the advice in this forum thread, which basically told me to add the following lines to /etc/default/grub:

GRUB_PRELOAD_MODULES="usb usb_keyboard ehci ohci uhci"
GRUB_TERMINAL_INPUT="usb_keyboard"


and run:

grub-mkconfig -o /boot/grub/grub.cfg
update-grub2

Well, I tried that, which turned out to be a big mistake. The USB keyboard now indeed worked fine in the GRUB menu but selecting any entry would only return error grub error: disk (hd0,msdos5) not found. A simple ls in the GRUB rescue console resulted in the same error. I guess the preloading of keyboard modules at the GRUB menu disrupted the initialization of other system driver packages and the system failed to recognize the hard disk partition to boot from.

I stupidly did not backup my grub.cfg file and the only recourse was to boot from a Ubuntu Live CD, revert the above change to /etc/default/grub and follow this guide to restore the GRUB default configuration. Fortunately this worked and I was back to square one, with a non-working keyboard at GRUB menu.

Keyboard compatibilities

At this point I decided to buy another keyboard, a Logitech K120, and see if the same issues still persist. Surprisingly everything worked and I was able to use the new keyboard to select either Windows or Linux to boot to.

So what is the issue causing only the Prolink keyboard not to work? I checked the hardware ID of all three keyboards from Windows Device Manager:

Logitech K120: VID_046D&PID_C31C [working at GRUB menu]
Microsoft Wire Keyboard 600: VID_045E&PID_0750  [working at GRUB menu]
Prolink PKCS-1002: VID_1A2C&PID_0027 [not working at GRUB menu]

All 3 keyboards are recognized as HID Keyboard Device by Windows:


Despite much effort, I could not find anything from the Device Properties page of the Prolink keyboard that could provide any hint why it could not work. I can only hazard a guess that its implementation of USB Human Interface Device is flawed causing it to fail to work with the emulated BIOS at the GRUB menu while Windows, which presumably has more sophisticated error handling, is able to detect the keyboard without issues.
Read More »

Friday, August 12, 2011

HTC HD2 Android: Working with ext2 images under Windows

My HTC HD2 running on Android from SD card had been working well for some time until it could not boot to Android one day (booting to Windows Mobile was still fine). Obviously I could redownload the same Android build, but this would mean loss of text messages, applications, call history and any other data not backed up or synchronized with Google server. In an attempt to salvage these data, I looked at the Android folder on the SD card and notice the following files:

data.img: contains user data such as text messages, applications, etc.
system.ext2 and rootfs.img: Android system files

Although most guides suggest using a Linux live CD such as Ubuntu and use the mount command to mount them as drives, which actually works, I wanted to do the same in Windows. My first try is to use Daemon Tools. This obviously has no chance of success, as the tool is meant to mount CD/DVD images, and not disk images, not to mention the Ext2 filesystem used by Android. I then tried various Windows tools to open/mount Linux images, and summarized the results in the following table. Take note that the image may be easily damaged if mounted by a tool not supporting it, or if not unmounted properly. If you want to try this, remember to back up first!



data.img
rootfs.img
system.ext2
R
R
R
X
R
R
X
RW
RW
X
RW
RW
R
X
X
X
R
R

Legend
X=failed
R=read-only access
RW=read/write access

You may need the Ext2 driver for Windows for some of the tools to work. Also read this tutorial on using IMDisk.

Looking at the table, Ext2Explore does the best by supporting all 3 images, albeit with read-only access. GizMo and ImDisk support  read/write access for rootfs.img and system.ext2 (with IMDisk being more stable), but not for data.img, where most of the user data stays. DiskInternal Linux Reader supports data.img in read-only mode, but not the other two images.

So what is so special about data.img? Some websites say it is using YAFFS2 filesystem, which only applies for phones with Android on ROM. Since my Android is on SD card, I believe data.img still uses ext2, perhaps with some special format causing most Windows tools to fail mounting it.

Extending system.ext2

My next challenge is to use Windows to extend my system.ext2 as I want to add some fonts and background images and my system.ext2 does not have enough space. This time, despite finding no Windows tools that provide read/write access to data.img, I find a set of tools from xda-developers that does the job. The author compiled the source code of dd, dumpe2fs, e2fsck, mke2fs and resize2fs to run under Windows and built a user interface for it using Tclkit:

However, the TopoResize app is poorly written and crashes all the time. I resorted to resizing the image using the command line tools mentioned above:

dd if=/dev/zero bs=1M count=XXX >> system.ext2
XXX = Amount of space in MB to be added to the image

resize2fs -f system.ext2
Resize the filesystem in the image

e2fsck -f system.ext2
Perform a check on the new filesystem. Without this, Android may hang while booting up.

The set of command line tools I used can be downloaded here. Next thing on my wishlist is to open data.img read/write on Windows; if anyone knows of a way, do leave a comment here. :)
Read More »

Tuesday, November 4, 2008

Ubuntu on a USB thumb drive

1. Download Ubuntu live CD from http://www.ubuntu.com/getubuntu/download. We are using Ubuntu 7.10
2. Extract all files in the ISO files to a USB thumb drive (size at least 1GB)
3. We'll need a bootloader which makes the thumb drive bootable and will load the ubuntu kernel image into memory. Download syslinux from http://www.kernel.org/pub/linux/utils/boot/syslinux/.
4. Make sure that the thumb drive is FAT/FAT32 formatted, and not NTFS.
5. Assuming the thumb drive is F:, run the following command:Syslinux -ma F:
6. This will copy the bootloader to F: and create a file name ldlinux.sys having System & Hidden attribute

7. Create the boot loader configuration file, named syslinux.cfg, located in the root drive of F:\, containing the following:

    default ubuntu

    prompt 1

    timeout 40

    label ubuntu

    kernel vmlinuz

    append file=/cdrom/preseed/ubuntu.seed boot=casper initrd=initrd.gz --

    For more information on the syntax of the file, see http://members.chello.at/bobby100/ILpart1.htm


8. Move the kernel and the ram disk image (vmlinuz & initrd.gz) from the casper folder to the root directory.
9. Setup BIOS to boot from the thumb drive
10. Reboot and Ubuntu will start from the thumb drive.

An alternative is to use Slax (http://www.slax.org/), a portable Linux solution.

Reference:
http://www.sandaru1.com/2007/07/02/how-to-convert-your-live-cd-iso-into-a-live-usb/
Read More »