Bitcoin Forum
May 06, 2024, 08:12:18 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Linux packages should have an autodetect 32/64 bit using bash  (Read 2938 times)
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
February 26, 2011, 05:30:59 PM
 #1

bitcoin.linux
Code:
#!/bin/bash
MACHINE_TYPE=`uname -m`
WORKING_DIR=`basename $0`
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  # run 64-bit bitcoin here
  $WORKING_DIR/bin/64/bitcoin
else
  # run 32-bit bitcoin here
  $WORKING_DIR/bin/32/bitcoin
fi

Idea came to me after a user on IRC was having trouble running bitcoin (didn't know their arch nor how to navigate in console nor about bitcoin/bitcoind distinction).

My sister has been using bitcoin, and because of the long startup/multiple executables she was just going into every directory under bin and opening all the binaries repeatedly until it bitcoin opens. She assumed it was because bitcoin is broken. This script would also alleviate that problem.
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
The Bitcoin software, network, and concept is called "Bitcoin" with a capitalized "B". Bitcoin currency units are called "bitcoins" with a lowercase "b" -- this is often abbreviated BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
1715026338
Hero Member
*
Offline Offline

Posts: 1715026338

View Profile Personal Message (Offline)

Ignore
1715026338
Reply with quote  #2

1715026338
Report to moderator
ribuck
Donator
Hero Member
*
Offline Offline

Activity: 826
Merit: 1039


View Profile
February 26, 2011, 08:17:53 PM
 #2

Doesn't "uname -m" only give you the hardware type? Until recently, I was running 32-bit Fedora on 64-bit hardware.
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 26, 2011, 09:35:09 PM
Last edit: February 27, 2011, 10:34:32 AM by kseistrup
 #3

If gcc is installed, perhaps you could look for the _LP64 preprocessor symbol (a.k.a. “longs and pointers are 64 bits”) and act accordingly, e.g.:

Code:
#!/bin/sh

WORKING_DIR=$(basename "${0}")

gcc -dM -E - </dev/null | grep -q '_LP64 1' && {
  exec "${WORKING_DIR}"/bin/64/bitcoin "${@}"
}
exec "${WORKING_DIR}"/bin/32/bitcoin "${@}"

# eof

Cheers,

Klaus Alexander Seistrup
dbitcoin
Hero Member
*****
Offline Offline

Activity: 742
Merit: 500

BTCDig - mining pool


View Profile WWW
February 27, 2011, 02:43:16 AM
 #4

1) check hardware
Code:
# cat /proc/cpuinfo
2) check used kernel
Code:
# file /sbin/init

BTCDig - mining pool (Stratum, VarDiff, DGM, SSL, JSON API)
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
February 27, 2011, 10:29:21 AM
 #5

1) check hardware
Code:
# cat /proc/cpuinfo
2) check used kernel
Code:
# file /sbin/init


Is that platform agnostic? AFAIK aren't some distros replacing the classic init runlevel?

I'm on a computer with a 64bit processor but 32bit Ubuntu. uname -m shows i686
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 27, 2011, 10:35:34 AM
 #6

I'm on a computer with a 64bit processor but 32bit Ubuntu. uname -m shows i686
That answers ribuck's question, doesn't it?

Cheers,

Klaus Alexander Seistrup
khal
Hero Member
*****
Offline Offline

Activity: 540
Merit: 500



View Profile WWW
February 27, 2011, 11:08:31 AM
Last edit: February 27, 2011, 11:34:56 AM by khal
 #7

To know the default used architecture on debian based distrib :
Code:
dpkg --print-architecture
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
February 27, 2011, 11:32:21 AM
 #8

I'm on a computer with a 64bit processor but 32bit Ubuntu. uname -m shows i686
That answers ribuck's question, doesn't it?

Cheers,

No, because if it was the other way around then uname -m would show 64 bit on the 32bit version of Ubuntu.
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 27, 2011, 01:25:03 PM
 #9

No, because if it was the other way around then uname -m would show 64 bit on the 32bit version of Ubuntu.
I don't think you'll be able to run a 64bit version of Linux on a 32bit machine, whereas you can run a 32bit version of Linux on a 64bit machine without any problems whatsoever.

Cheers,

Klaus Alexander Seistrup
lumos
Full Member
***
Offline Offline

Activity: 157
Merit: 104



View Profile
February 27, 2011, 01:29:34 PM
 #10


My sister has been using bitcoin, and because of the long startup/multiple executables she was just going into every directory under bin and opening all the binaries repeatedly until it bitcoin opens. She assumed it was because bitcoin is broken. This script would also alleviate that problem.
she sounds like a retard
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
February 27, 2011, 02:09:20 PM
 #11

No, because if it was the other way around then uname -m would show 64 bit on the 32bit version of Ubuntu.
I don't think you'll be able to run a 64bit version of Linux on a 32bit machine, whereas you can run a 32bit version of Linux on a 64bit machine without any problems whatsoever.

Cheers,

You must have misunderstood & I wasn't clear enough:
The CPU is 64 bit.
The kernel is compiled for 32 bit.

uname -m displays i686. If uname -m showed the hardware arch then it would display x86_64, no? Therefore I conclude that uname -m is displaying the machine hardware type as compiled into the kernel, not detected from proc.

Quote from: random forum on google
all methods above are wrong. If the system was installed with 32bit OS the result will always be 32 unless it has a 64bit Linux running.
The correct way to do is:
cat /proc/cpuinfo
and look for flag “lm” in the flags: column. If it’s there then it’s 64bit CPU no matter Intel or AMD.

I'm inclined to think that uname -m is simply reporting back the compiled flags inside the kernel.

Here is the terminal output on this dual processor system:
Quote
x@l:~$ cat /proc/cpuinfo | grep flags
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm tpr_shadow vnmi flexpriority
flags           : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm tpr_shadow vnmi flexpriority
x@l:~$ uname -m
i686

Note the presence of lm (64bit CPU) but reporting of i686 from uname.
ribuck
Donator
Hero Member
*
Offline Offline

Activity: 826
Merit: 1039


View Profile
February 27, 2011, 02:30:28 PM
 #12

I conclude that uname -m is displaying the machine hardware type as compiled into the kernel

The "man uname" command says that -m means "print the machine hardware name", but maybe uname -m is actually printing the last part of the kernel version string as displayed by uname -r.

I'm currently running 64-bit Fedora, and this is what I see:

uname -r
2.6.35.11-83.fc14.x86_64
uname -m
x86_64

Auto-detection would be a good thing if it is foolproof, but otherwise it adds more problems than it solves.
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 27, 2011, 02:43:44 PM
 #13

You must have misunderstood & I wasn't clear enough:
The CPU is 64 bit.
The kernel is compiled for 32 bit.

uname -m displays i686. If uname -m showed the hardware arch then it would display x86_64, no? Therefore I conclude that uname -m is displaying the machine hardware type as compiled into the kernel, not detected from proc.

I think I understood you correctly.  When I referred to ribuck I just meant to say that the above answered his question, not that his assumption was correct.  Wink

Quote
I'm inclined to think that uname -m is simply reporting back the compiled flags inside the kernel.

Me too.  So can't we conclude that if we wish to run a version of bitcoin that has the same ‘bitlength’ as the running Linux kernel, then ‘uname -m’ is a valid way of getting the required information?

(I'm not sure ‘we’ always want that, though:  On a Core 2 Duo machine I get appr. 1000 khash/sec with a 64bit 1-threaded jgarzik miner using the cryptopp algorithm (the fastest algorithm available in the 64bit version), whereas I get an extra 50+ khash/sec using the cryoptopp_asm32 algorithm with the 32bit version of the same miner, so surely I want to run the 32bit version in order to get a few extra millicents.)

Cheers,

Klaus Alexander Seistrup
kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 27, 2011, 02:49:11 PM
 #14

Auto-detection would be a good thing if it is foolproof, but otherwise it adds more problems than it solves.
You're right.

A 64bit kernel can run the 64bit bitcoin excutable as well as the 32bit one, whereas a 32bit kernel can only run the 32bit binary.  So I gather it would be safe to run the 64bit version if ‘uname -m’ explicitly says ‘x86_64’, and run the 32bit version in all other cases.  Am I correct?

Cheers,

Klaus Alexander Seistrup
grondilu
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
February 27, 2011, 02:49:57 PM
 #15

/proc/cpuinfo  is probably your best source of information about your processor.

kseistrup
Hero Member
*****
Offline Offline

Activity: 566
Merit: 500


Unselfish actions pay back better


View Profile WWW
February 27, 2011, 02:58:43 PM
 #16

/proc/cpuinfo  is probably your best source of information about your processor.
Which part of the information are you specifically referring to?  And aren't we more interested in the kernel than in the hardware?

Cheers,

Klaus Alexander Seistrup
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
February 27, 2011, 03:36:55 PM
 #17

Auto-detection would be a good thing if it is foolproof, but otherwise it adds more problems than it solves.
You're right.

A 64bit kernel can run the 64bit bitcoin excutable as well as the 32bit one, whereas a 32bit kernel can only run the 32bit binary.  So I gather it would be safe to run the 64bit version if ‘uname -m’ explicitly says ‘x86_64’, and run the 32bit version in all other cases.  Am I correct?

Cheers,

Yes. Agreed.
genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
March 07, 2011, 09:21:58 AM
 #18

Pull request is here, https://github.com/bitcoin/bitcoin/pull/104
Luke-Jr
Legendary
*
expert
Offline Offline

Activity: 2576
Merit: 1186



View Profile
March 07, 2011, 03:00:24 PM
 #19

What if it's PowerPC, ARM, SPARC, etc?

genjix (OP)
Legendary
*
expert
Offline Offline

Activity: 1232
Merit: 1072


View Profile
March 09, 2011, 01:16:08 AM
 #20

What if it's PowerPC, ARM, SPARC, etc?

It will run the 32 bit version.

There aren't any bitcoin builds for those platforms anyway so the point is moot.

BTW, this is the new request https://github.com/bitcoin/bitcoin/pull/107
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!