Installing Qemu on Gentoo x86 with GCC 3

From OLPC
Revision as of 15:37, 30 November 2008 by 87.218.138.217 (talk) (→‎Changing ownership)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Foreword

One of the methods for emulating the XO Laptop involves using the Qemu emulator. However due to known bugs, it may be difficult to install it on systems running Gentoo on the x86 platform. Therefore the steps shown on this page describe how to install Qemu and run the XO simulation successfully on such systems.

Preparation

Use flags

sdl : is needed for graphical output.

alsa : sound related, not sure how this affects sound in Qemu.

kqemu : improves performance on x86 architecture.

Add the above flags according to needs. At the least "sdl" flag is needed for XO emulation. Since app-emulation/qemu is a meta package it is better to specify flags for each component separately in /etc/portage/package.use:
Note: Don't forget to make a backup of /etc/portage/package.use first!

 # echo "app-emulation/qemu-softmmu alsa sdl kqemu" >> /etc/portage/package.use


Portage tools

app-portage/gentoolkit
app-portage/portage-utils


Install

Try installing qemu:

 # emerge -av app-emulation/qemu

The install may fail with error indicating a need for GCC 3.x or fails to compile with some unknown reason then it might be worth reading further on.


Compiling with GCC 3.x.x

If the portage complained about GCC 3 version then the following will show how to install and set up GCC 3. In Gentoo there is a choice between using GCC 3.4 and GCC 3.3. Installing GCC 3.4 went smoothly without any problems, however it failed to build Qemu. For Gentoo x86 athlon-xp at least, only GCC 3.3.x was able to compile Qemu successfully.

Use the following command to see which GCC versions are available for Gentoo:

 # equery list -p -o -e gcc


GCC 3.4.x

Note that on x86 athlon-xp the compiler successfully installed but Qemu compilation failed using this version of GCC.


Checking for installed versions

Check to see if gcc-3.4.x is installed:

 # equery list --installed --exact-name 'sys-devel/gcc'
 [I--] [ -] sys-devel/gcc-4.1.2 (4.1)
 [I--] [M~] sys-devel/gcc-4.2.2 (4.2)


Emerging gcc-3.4

Just emerge it in a normal way:

 # emerge -av sys-devel/gcc:3.4


Switching compiler

The compiler needs to be switched to version gcc-3.4.

Check the current compiler version:

 # gcc-config -l
 [1] i686-pc-linux-gnu-3.4.6
 [2] i686-pc-linux-gnu-4.1.2 *
 [3] i686-pc-linux-gnu-4.2.2

Change the compiler to 3.4.6:

 # gcc-config i686-pc-linux-gnu-3.4.6
 # source /etc/profile
 #

Verify the change:

 # gcc-config -l
 [1] i686-pc-linux-gnu-3.4.6 *
 [2] i686-pc-linux-gnu-4.1.2 
 [3] i686-pc-linux-gnu-4.2.2

Then emerge Qemu. See Emerging Qemu. If it fails to compile then try GCC 3.3.x instead.


GCC 3.3.x

Installing this version is tricky on Gentoo. However once it has been set up, Qemu compiled smoothly time and time again.

Note: As at 2008-02-19 this version of GCC (3.3.x) successfully installed by selecting gcc-3.4.x as compiler.

Install gcc-3.4.x first if not in the system already.

 emerge -av sys-devel/gcc:3.4

Then select gcc-3.4.x

 gcc-config -l
 [1] i686-pc-linux-gnu-3.4.6 
 .
 .
 [7] i686-pc-linux-gnu-4.1.2 *

In this example it is i686-pc-linux-gnu-3.4.6

 gcc-config i686-pc-linux-gnu-3.4.6

Emerge GCC 3.3.x as normal.

 emerge -av sys-devel/gcc:3.3


Checking for installed versions

(Note: Using this method may now be deprecated.)

Check to see if gcc-3.3.x already is installed:

 # equery list --installed --exact-name 'sys-devel/gcc'
 [I--] [ -] sys-devel/gcc-4.1.2 (4.1)
 [I--] [M~] sys-devel/gcc-4.2.2 (4.2)

If the result does not show gcc-3.3.x, then it needs to be installed using custom ebuild.

Creating custom ebuild

(Note: Using this method may now be deprecated.)

Due to known and documented bugs the installation process will not be straightforward. Two patches must be applied before GCC 3.3 can successfully compile. These patches are applied to a custom ebuild that can be downloaded from bugs.gentoo.org,

Setting up local portage overlay

This will be the directory where the custom ebuild will be kept. Its value is controlled through "PORTDIR_OVERLAY" variable in /etc/make.conf.
Note: Don't forget to make a backup of /etc/make.conf first!

 # nano -w /etc/make.conf

Then add the line specifying the local overlay directory:

 PORTDIR_OVERLAY="/usr/local/portage"

Exit the editor and create the directory to place the ebuild if it does not exist already:

 # mkdir -p /usr/local/portage/sys-devel/gcc/files
Downloading the patches and ebuild

Download the ebuild called "gcc-3.3.6-r3.ebuild" from bugs.gentoo.org and place it in the following directory:

 /usr/local/portage/sys-devel/gcc

The ebuild can be downloaded from the following location:

File name: gcc-3.3.6-r3.ebuild
http://bugs.gentoo.org/show_bug.cgi?id=201035

Afterwards download the two patches and place them in the following directory:

 /usr/local/portage/sys-devel/gcc/files

Patches:
138321 gcc-3.3-makelang.patch
http://bugs.gentoo.org/show_bug.cgi?id=201035

138322 gcc3.3-stpcpy.patch
http://bugs.gentoo.org/show_bug.cgi?id=201035

Populating the local build directory

In this step copy the contens of the main ebuild directory ~/portage/sys-devel/gcc/files/ to the same place on the local ebuild directory.

 # cp -r /usr/portage/sys-devel/gcc/files/* /usr/local/portage/sys-devel/gcc/files/
Updating the manifest

Without updating the manifest the build will fail at the checksum checking stage. Use the "digest" option in ebuild to update the manifest with the new ebuild file and patches.

 # cd /usr/portage/sys-devel/gcc/files
 # ebuild gcc-3.3.6-r3.ebuild digest


Taking precautionary safety measures

Since it is not an ebuild from the main branch its wise to put in some safety measures to protect the system should unforseen events happen.

To protect the system from custom ebuild writing over existing system files use the "collision-protect" Feature in /etc/make.conf.
Note: Don't forget to make a backup up /etc/make.conf first!

 # nano -w /etc/make.conf

Add "collision-protect" to the FEATURES line:

 FEATURES="strict notitles ccache sfperms splitdebug sandbox collision-protect"

Also verify that feature "sandbox" is enabled.

 # emerge --info | grep FEATURES


Finally gcc-3.3.6 is ready to be built.

Emerging and compiling gcc-3.3.6

Unmask the gcc-3.3.x package:
Note: Don't forget to make a backup up /etc/portage/package.keywords first!

 # echo "sys-devel/gcc:3.3 ~x86" >> /etc/portage/package.keywords

Then emerge the package:

 # emerge -av sys-devel/gcc:3.3

Switching compiler

After the compiler builds successfully check the current compiler version:

 # gcc-config -l
 [1] i686-pc-linux-gnu-3.3.6
 [2] i686-pc-linux-gnu-4.1.2 *
 [3] i686-pc-linux-gnu-4.2.2

Change the compiler to 3.3.6 for compiling Qemu:

 # gcc-config i686-pc-linux-gnu-3.3.6
 # source /etc/profile
 #

Verify the change:

 # gcc-config -l
 [1] i686-pc-linux-gnu-3.3.6 *
 [2] i686-pc-linux-gnu-4.1.2 
 [3] i686-pc-linux-gnu-4.2.2

Emerging Qemu

Emerging

With GCC 3.3.6 it should compile smoothly. For GCC 3.4.6 there is a known bug #194681 so the compile may fail.

 # emerge -av app-emulation/qemu

Setup

Group permission

When installing kqemu it adds the group "qemu" to /etc/group. Then instructs to add users to "qemu" group.

Adding user to the "qemu" group in /etc/group.

 # gpasswd -a <USER_NAME> qemu

Then re-login the <USER_NAME>.


Kernel module loading

Kernel module needs to be loaded for kqemu.

 # modprobe kqemu major=0

If the kqemu module does not automatically load at bootup, edit /etc/modules.autoload.d/kernel-2.6.
Note: Don't forget to make a backup of this file first!

# echo "kqemu major=0" >> /etc/modules.autoload.d/kernel-2.6


Changing ownership

When starting qemu with kqemu enabled it might throw out an error saying /dev/kqemu cannot be accessed and kqemu will not be starting. If this is the case then modification to the ownership of file /dev/kqemu is required.

 # chown root:qemu /dev/kqemu

Cleanup

After the install, it is useful to add Qemu to an exclusion list to prevent it from failing the whole process when doing emerge in bulk.
Note: Don't forget to create a backup of /etc/portage/package.mask first!

 # echo ">app-emulation/qemu-0.9.0" >> /etc/portage/package.mask
 # echo ">gcc-3.3.6-r3.ebuild" >> /etc/portage/package.mask
 # echo ">app-emulation/qemu-user-0.9.0" >> /etc/portage/package.mask

Also don't forget to switch the compiler back to the default version.

 # gcc-config -l
 [1] i686-pc-linux-gnu-3.3.6 *
 [2] i686-pc-linux-gnu-4.1.2 
 [3] i686-pc-linux-gnu-4.2.2
 # gcc-config i686-pc-linux-gnu-4.1.2
 # source /etc/profile
 # gcc-config -l 
 [1] i686-pc-linux-gnu-3.3.6 
 [2] i686-pc-linux-gnu-4.1.2 *
 [3] i686-pc-linux-gnu-4.2.2


What to do when the patches for gcc-3.3.4 get tagged as official

If the patches get incorporated into the official build tree, then it may be necessary to remove the local ebuild.

If the custom ebuild was created in the local portage overlay as shown in the above steps, then all that needs to happen is to remove the directory that contained the custom ebuild.


Quick guide to using Qemu

(Being written)


Reference

Internal links

(Being written)


External links

Bug related

Qemu compile bug:
194681 app-emulation/qemu-softmmu-0.9.0 fails to compile with gcc-3.4.6
http://bugs.gentoo.org/show_bug.cgi?id=194681

gcc-3.3.6 does not compile bug:
201035 fix building of sys-devel/gcc-3.3.6 on recent systems
http://bugs.gentoo.org/show_bug.cgi?id=201035

gcc-3.3.6-r3.ebuild:
http://bugs.gentoo.org/attachment.cgi?id=137589

gcc3.3.6 patches:
138321 gcc-3.3-makelang.patch
http://bugs.gentoo.org/attachment.cgi?id=138321

138322 gcc3.3-stpcpy.patch
http://bugs.gentoo.org/attachment.cgi?id=138322

Gentoo related

"Howto: Qemu"
http://gentoo-wiki.com/HOWTO:_Qemu

"Gentoolkit"
http://www.gentoo.org/doc/en/gentoolkit.xml

"Portage-utils"
http://www.gentoo.org/doc/en/portage-utils.xml

"Howto Installing 3rd Party Ebuilds"
http://gentoo-wiki.com/HOWTO_Installing_3rd_Party_Ebuilds

"Ebuild Howto"
http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=1

"Forum discussion about installing gcc-3.x.x on Gentoo"
http://forums.gentoo.org/viewtopic-p-4573658.html?sid=15476000f07f0c109096a2633721c38e