Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[re-solved] Building 64 bit kernel on 32 bit Gentoo
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
TheLexx
Tux's lil' helper
Tux's lil' helper


Joined: 04 Dec 2005
Posts: 118
Location: Austin Tx

PostPosted: Sat Apr 27, 2019 9:01 pm    Post subject: [re-solved] Building 64 bit kernel on 32 bit Gentoo Reply with quote

MAIN QUESTION: Can I compile a 32 bit kernel inside of a 32 bit Gentoo system, yes or no?

Correct me if I am wrong! If I have Gentoo CHOST="i686-pc-linux-gnu" system running on a machine with a 64bit Intel processor. I can use either a 32 bit or 64 bit kernel? That is to say that the system can run "as is" with a 64 bit kernel as long as the kernel is configured correctly? Once said kernel is built, I will have the ability to boot up a system compiled as 32 bits under Gentoo. In addition I could use that same Kernel to boot a Gentoo system compiled to 64bits? I have a 64bit AMD and a 64bit Intel box, I would like to compile once for both systems, it works on my 32bit Gentoo. I do seem to remember a version of Finnix that was compiled at 32 bits but gave you the option of booting with a 64 bit kernel.

Ok with all that said, I would like to compile a 64 bit kernel on the 32 bit Gentoo system. I understand that it super difficult to compile regular 64 bit user programs from within a 32 bit system. This is because you will need access to a 64bit tool chain, practically you would build a cross compiler. But I thought (maybe unwarranted) that because the kernel uses it's own libraries and not the user space ones that it was self contained enough that I could compile a 64 bit kernel using a 32 bit Gentoo system.

Is this sort of compiling a fools errand? Is my situation worth trying to debug? If there are a few simple things I missed in configuration It would be easier compiling the 64bit kernel on the 32bit system. Otherwise I will need to repartition to make a bootable 64 bit system just to compile a kernel.

I did give a half-ass attempt at compiling a 64 bit kernel on a 32 bit Gentoo. I am able to compile the same long term stable kernel as a 32 bit kernel in the same /usr/src/linux directory. I first did a "make clean" then I uses "make menuconfig" for a generic 64 bit CPU. I got the following error.

Code:
cc1: error: CPU you selected does not support x86-64 instruction set


my new ".config" continues the following lines

Code:
CONFIG_GENERIC_CPU=y
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
CONFIG_X86_64_SMP=y
CONFIG_GENERIC_CPU=y


I was thinking that something of the old 32bit config leaked over to the new configuration. But, greping .config for m486 m586 and m686 returns zero lines.


Last edited by TheLexx on Tue May 14, 2019 7:38 pm; edited 3 times in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43559
Location: 56N 3W

PostPosted: Sat Apr 27, 2019 9:24 pm    Post subject: Reply with quote

TheLexx,

The simple answer is no. Your 32 bit toolchain cannot emit 64 bit code.

The more complex answer is yes, but you need a cross compiler.
If that makes your hair stand on end, the kernel is one of the easiest packages to cross compile.

If you don't want to go there, I have it at the back of my mind that VirtualBox can run a 64 bit guest on a 32 bit install on a 64 bit host.
That is, your hardware needs to be 64 bit capable.
You do a 64 bit install as a VirtualBox guest and build your kernel there.

Once you get a 64 bit kernel under your 32 bit userland, it just works.
The Gentoo based System Rescue CD did this, the Gentoo LiveDVDs do this.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
TheLexx
Tux's lil' helper
Tux's lil' helper


Joined: 04 Dec 2005
Posts: 118
Location: Austin Tx

PostPosted: Sat May 04, 2019 7:21 pm    Post subject: Reply with quote

Thank you for the information. It was not exactly what I wanted to hear, but I now have a plan of action that should lead me to success.
Back to top
View user's profile Send private message
TheLexx
Tux's lil' helper
Tux's lil' helper


Joined: 04 Dec 2005
Posts: 118
Location: Austin Tx

PostPosted: Mon May 13, 2019 6:37 pm    Post subject: Reply with quote

Main Question: Are there settings in "make menuconfig" that dictate whether a 64bit kernel can run both "ELF 32-bit LSB executable" and the 64 bit ones? Is there a setting that effectively makes it 64 bit only?

I unpacked a 64bit stage 3 archive for Gentoo into a fresh directory called "64bit-gentoo-root" that was on my "downloads" partition. I then booted up from a Finnix ISO image (also on my hard drive) using it's 64bit kernel. After booting into Finnix, I was able to chroot using "64bit-gentoo-root" as the root directory. This environment worked fine. I was able to compile a linux kernel in this environment.

My problem was when I tried to start up Gentoo using this kernel, I would get a panic on startup. The startup messages indicated that the kernel was doing booting and doing it's job, even mounting the root partition. However, it would panic, the operative line seamed to be, "/sbin/init exists but couldn't execute it". I'm not sure exactly what is happening. My guess is the kernel can only run 64bit ELF files and not 32bit ones. When trying to go from 32bit to 64bit I must have accidentally switched of the ability to run 32bit executable. Is this possible?

I thought about just booting up a 64bit system, but I don't have anything ready to run, remember my stage 3 is not at the root of the partition. I suppose I can compile a self-contained 64bit busy box then switch-root/chroot to a directory that is not at the root of a partition.

PS. I also just remembered, my Gentoo relies on an initrc. The initrc relies on a self contained 32bit busybox. During the boot the script inside initrc is never executed.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43559
Location: 56N 3W

PostPosted: Mon May 13, 2019 7:07 pm    Post subject: Reply with quote

TheLexx,

Code:
$ grep IA32 /usr/src/linux/.config
# CONFIG_IA32_EMULATION is not set


That's the menuconfig option that allows a 64 bit kernel to execute 32 bit code. In my kernels its off, as I use the no-multilib profile, which is 64 bit only.
It would be the wrong answer for you.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
TheLexx
Tux's lil' helper
Tux's lil' helper


Joined: 04 Dec 2005
Posts: 118
Location: Austin Tx

PostPosted: Tue May 14, 2019 7:40 pm    Post subject: Reply with quote

THAT was IT. Thanks again NeddySeagoon, you are a LIFE SAVER!!

You saved me again from spending hours trying different things just to see what the problem was.

I now have a kernel that works on both 32bit and 64bit Gentoo installs. I am still having some issues, but if needed I'll use a different thread. The base question here was, how can a get a kernel that will work on both. And I believe that is permanently solved.

PS. It's not that I don't like figuring out things by delving into the inner workings of Linux systems. But every now and then I, just want to get things working.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum