Bitcoin Forum
December 03, 2016, 04:43:51 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Linux packages should have an autodetect 32/64 bit using bash  (Read 2541 times)
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


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.
1480740231
Hero Member
*
Offline Offline

Posts: 1480740231

View Profile Personal Message (Offline)

Ignore
1480740231
Reply with quote  #2

1480740231
Report to moderator
1480740231
Hero Member
*
Offline Offline

Posts: 1480740231

View Profile Personal Message (Offline)

Ignore
1480740231
Reply with quote  #2

1480740231
Report to moderator
1480740231
Hero Member
*
Offline Offline

Posts: 1480740231

View Profile Personal Message (Offline)

Ignore
1480740231
Reply with quote  #2

1480740231
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480740231
Hero Member
*
Offline Offline

Posts: 1480740231

View Profile Personal Message (Offline)

Ignore
1480740231
Reply with quote  #2

1480740231
Report to moderator
ribuck
Donator
Legendary
*
Offline Offline

Activity: 826


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: 565


Unselfish actions pay back better


View Profile WWW
February 26, 2011, 09:35:09 PM
 #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
http://about.me/kseistrup
dbitcoin
Hero Member
*****
Offline Offline

Activity: 742

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
Legendary
*
expert
Offline Offline

Activity: 1232


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: 565


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
http://about.me/kseistrup
khal
Hero Member
*****
Offline Offline

Activity: 538


NamecoinID: id/khal


View Profile WWW
February 27, 2011, 11:08:31 AM
 #7

To know the default used architecture on debian based distrib :
Code:
dpkg --print-architecture

NMC: N1KHAL5C1CRzy58NdJwp1tbLze3XrkFxx9 | NamecoinID: id/khal | Register .bit domain
BTC: 1KHAL8bUjnkMRMg9yd2dNrYnJgZGH8Nj6T | My bitcoin Identity: send messages to bitcoin users
Free bitcoins: Surf4Bitcoin.com | Charity Ad: Make a good deed without paying a cent
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


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: 565


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
http://about.me/kseistrup
lumos
Full Member
***
Offline Offline

Activity: 160



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
Legendary
*
expert
Offline Offline

Activity: 1232


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
Legendary
*
Offline Offline

Activity: 826


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: 565


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
http://about.me/kseistrup
kseistrup
Hero Member
*****
Offline Offline

Activity: 565


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
http://about.me/kseistrup
grondilu
Legendary
*
Offline Offline

Activity: 1134


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: 565


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
http://about.me/kseistrup
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


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
Legendary
*
expert
Offline Offline

Activity: 1232


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: 2086



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

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

genjix
Legendary
*
expert
Offline Offline

Activity: 1232


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!