Showing posts with label 64-bit. Show all posts
Showing posts with label 64-bit. Show all posts

Sunday, February 1, 2009

Steps to a successful 64-bit Ubuntu

Completely on a whim I decided to try Arch Linux on my laptop, which had some hardware issues, and then later on my desktop. While I liked it, it was way too much work for me, given the fact that I use Linux almost exclusively and need something functional. When it came time to reinstall with an easier distro, I decided to go back to Ubuntu if only because I spent a decent amount of time trying to tweak Debian that is unneeded in Ubuntu. However, I decided to go with the 64-bit version, which comes with its own set of problems that can be overcome with a little knowhow.

Previously, I wrote on how to set up a chroot environment to run 32-bit programs in their own 32-bit environment, all within the 64-bit operating system. (I wrote it for Debian Lenny, but the same process can be used for Ubuntu if tweaked slightly.) It works, but it is not without limitations. The biggest of which was running a 32-bit web browser caused problems with other web browsers arguing for the title of "default browser," and being unable to run downloaded files from within the browser. I decided this time I was going to try to do it all without using a chroot.

Web Browsing:
Adobe Flash has always been tricky to get working on a 64-bit browser. This will soon change, as Adobe currently has an alpha version of flash, but I have tried it and it is (as one would expect for alpha software) quite buggy and unstable. The other common alternative is to run the nspluginwrapper package to use a 32-bit flash in a 64-bit browser, but this can also be quite buggy for some. My solution is simply to run a 32-bit browser. I don't know how well all 32-bit browsers run, but I would recommend Swiftfox, which is basically an optimized Firefox, and I recommend it because it comes in a very easy-to-install .deb file. The one thing you have to do is figure out what sort of processor your computer uses, because different packages are optimized for different processors. After you find your processor, you can download the appropriate version of swiftfox here. (My computer uses the Prescott version, so I am going to use it in the examples) Then install it in the terminal:
sudo dpkg -i swiftfox_3.0.4pre-1_prescott.deb
Even though it is a 32-bit browser, it *should* install just fine. Open it up and make sure it works. One thing to watch out for is that on Debian, it did not find the printer I had installed, though I have never had problems with it in Ubuntu. If everything works in Swiftfox, you are ready to install Flash. Download the latest version from Adobe. Download the .tar.gz file (NOT the .deb file), navigate to the downloaded file and extract the contents. Copy libflashplayer.so to the plugins directory in your home directory:
tar -zxvf install_flash_player_10_linux.tar.gz
cd install_flash_player_10_linux
cp libflashplayer.so ~/.mozilla/plugins/
When you start up Swiftfox again, you should have working Flash support.

Adobe AIR:
I like the Adobe AIR runtime to use TweetDeck, but it is still not supported in 64 bit. The latest version will run on 64-bit versions with a few tweaks, and Adobe is kind enough to supply the information on their website. Rather than rehash what they have, I would recommend just checking out their website. If you follow their guide exactly, Adoebe AIR should run beautifully.

The getlibs Package:
For many other programs that have no 64-bit version, installing the 32-bit libraries will often be enough to get them up and running. The easiest way I have found to do this is with a package called getlibs, which can be found at http://www.boundlesssupremacy.com/Cappy/getlibs/getlibs-all.deb. This program will assess 32-bit packages/binaries and figure out which 32-bit libraries it needs to run successfully. For this example, I am going to use the Amazon.com mp3 downloader. After downloading it, if you try to install it with dpkg, it will fail, claiming that you are attempting to install something for the wrong architecture. This is an easy enough fix using the --force-architecture option when installing:
sudo dpkg -i --force-architecture amazonmp3.deb
The package will install but will still give you errors if you try to run it. To fix this, install getlibs if you have not already, and then run it on the binary file (not the .deb file) and it will, after a few moments, download and install the required libraries:
sudo dpkg -i getlibs-all.deb
sudo getlibs /usr/bin/amazonmp3
My one complaint with getlibs is that it does not provide any detailed output, so it may seem like it is not doing anything, but be patient. Once it completes, try running your program again and it should run. If the installer for a program is in .bin format, try running getlibs on the .bin file first because that might work as well (like in the directions for installing Adobe AIR), but so far it doesn't seem to do anything for .deb files for me. If a program complains of a missing library file, getlibs can also be used to download that specific library with the -l (or -64l for 64 bit libraries) option. And if downloading the libraries doesn't seem to work, try updating your library links with "sudo ldconfig".

Monday, December 8, 2008

Using 32-bit applications in 64-bit Debian with chroot

Some time ago I switched to 64-bit Debian on my desktop. I used to be scared off by the fact that certain, important applications were not yet available in 32 bit, such as Adobe's flash player. With some workarounds some of these programs are workable in 64 bit, for example nspluginwrapper uses the 32 bit version of flash and forces it to play nice with your 64 bit browser, with moderate to good success. (Adobe also just released their alpha version of 64 bit flash for Linux, but it kept causing my browser to crash.) For other programs, though, there is no way to run them effectively (or at all) in 64 bit. Until recently there were very few programs I wanted in this category (really, only TweetDeck, a twitter application on the Adobe AIR interface), but suddenly there have been a few more programs that I wanted/needed that are only available in 32 bit versions. The solution? Run them in 32 bit using a chroot! A chroot is sort of like a disk within a disk. It is often used for testing so that developers can test a program without it destroying the filesystem on their machine. Here, we are using it to install a 32 bit Debian inside a 64 bit Debian. This process is also possible to do on Ubuntu, with slightly modified commands. *Note, most of this comes from this page, but I have cleaned it up, fixed some typos and, in my opinion, made it easier to understand.

Step 1: Set up the base file system
First you need to set up the base file system. This is going to install a very minimal version of 32-bit Debian Sid inside your 64-bit Debian install. So first, make a directory for this second install and then use debootstrap to install (as root or with sudo):
mkdir /var/sid-386-chroot
debootstrap --arch i386 sid /var/sid-386-chroot http://ftp.debian.org/debian/

This will download a number of packages for the chroot and install them. Depending on your internet connection this may take a little while. When it is all done you should see that you have a whole file system inside /var/sid-386-chroot, similar to your main file system.

I am not entirely sure what the next steps do, but the howto I followed states that you have to add the library path of your chroot to your ld.so.conf, and you need a link to your 32 bit linker in the /lib path. In any case, what you need to do is add the following lines to /etc/ld.so.conf:
# chroot i386 system libs
/var/sid-386-chroot/lib
/var/sid-386-chroot/usr/lib
/var/sid-386-chroot/usr/X11R6/lib
/var/sid-386-chroot/usr/local/lib

Then you need to run these commands in the terminal:
cd /lib
ln -s /var/sid-386-chroot/lib/ld-linux.so.2 ld-linux.so.2
ldconfig


Step 2: Set up the chroot to run alongside your 64 bit install
For your 32-bit applications to work just like they were on your 64 bit install, certain parts of your 64 bit install have to be accessible to your chroot (normally, a chroot can't access anything outside of the chroot. It's called a chroot jail and it is why developers use chroots to test programs.) For this, we use what is called a bind mount, which is used to mount a directory, such as /home, to the home folder inside the chroot. There are a few folders which should be mounted in the chroot, and this can be done by modifying the /etc/fstab file and adding the following lines at the bottom:
/home /var/sid-386-chroot/home none bind 0 0
/tmp /var/sid-386-chroot/tmp none bind 0 0
/proc /var/sid-386-chroot/proc proc defaults 0 0
/dev /var/sid-386-chroot/dev none bind 0 0
/usr/share/fonts /var-sid-386-chroot/usr/share/fonts none bind 0 0

It is VERY IMPORTANT to note that now that these folders are bound to their locations on your main file system, if you ever decide to delete your chroot, make sure that you unmount these bind mounts or else you can end up erasing these folders on your main file system. Also make sure that there are directories for each of these mounts. The only one you should end up having to make is /media/cdrom0. Then mount them:
sudo mkdir /var/sid-386-chroot/media/cdrom0
sudo mount -a

If all went well you should get no error messages and these locations will be bound to their counterparts in the chroot.

Lastly, you need to make sure that all of the users on your machine also exist in the chroot. This can be done by copying certain files to the chroot:
# sudo cp /etc/passwd /var/sid-386-chroot/etc/
sudo cp /etc/shadow /var/sid-386-chroot/etc/
sudo cp /etc/group /var/sid-386-chroot/etc/
sudo cp /etc/sudoers /var/sid-386-chroot/etc/
sudo cp /etc/hosts /var/sid-386-chroot/etc/


Now you should be able to enter the chroot and run programs from within. To get into the chroot (which you must be root to do) you can type:
sudo chroot /var/sid-386-chroot

Now you can run commands. Try out a command or two. Keep in mind that the chroot is a brand new Debian install, so most of the programs you use will not be installed yet. For example, if you try running gedit, it won't run because gedit is not yet installed in the chroot. You can install it and other programs with apt-get or aptitude just like in your 64 bit install. Should you ever want to exit the chroot, simply type "exit"

Step 3: Installing your 32-bit applications
Anything in the Debian repositories is as easy as entering the chroot and installing it via the apt-get or aptitude command line. Keep in mind that since it is a different install you will have to add contrib and non-free to your sources.list file if you want to use those repositories. Downloaded .deb files are a bit tougher. Download them to your home directory and install them with dpkg -i (from within the chroot), for example, if you wanted to install skype (a 32-bit only app), download it, navigate to the directory where you downloaded it in the terminal, and type:
dpkg -i skype-debian_2.0.0.72-1_i386.deb
. This method is a bit more tedious because, since the chroot is a brand-new, minimal install, there are most likely a host of dependencies that are not installed yet. This means that it will come up with all sorts of errors about dependencies. For each dependency that it is lacking, use apt-get or aptitude to install them.

You may also get a lot of errors about locale settings. To fix this, I had to install locales and reconfigure it:
sudo apt-get install locales
sudo dpkg-reconfigure locales


You should now be able to run your 32 bit application from within the chroot. (Note: TweetDeck did not function properly until after the next step, but other applications ran okay.) In this example, while in the chroot simply type "skype" into the terminal and skype will launch.

Step 4: Make it work seamlessly from your 64-bit install.
So you got your application up and running, but as you are probably already thinking, entering the chroot and running the application is rather tedious. So the next step is to work up a script that will load it in one fell swoop. First, make sure you exit the chroot and install dchroot, which will allow you to run programs installed in the chroot from your 64-bit Debian.
sudo apt-get install dchroot

Now you need to edit (or create) /etc/dchroot.conf and add:
# sid386 chroot
sid386 /var/sid-386-chroot

This essentially names the chroot and defines where it is located, so that dchroot knows where to look when it is run. Now you should be able to launch skype using dchroot without having to enter the chroot itself by running the command:
dchroot -c sid386 -d skype

To make life even easier, we can write a simple script to call that command whenever we want to launch Skype. While you could certainly write a script to specifically launch Skype, it would mean that you would have to make a new script for every 32-bit application you install. Instead, we are going to create one universal wrapper script. Make the following script called /usr/local/bin/do_chroot:
#!/bin/sh
ARGS=""
for i in "$@" ; do
ARGS="$ARGS '$i'"
done

exec dchroot -c sid386 -d -q "`basename $0`" "$ARGS"

I am no scripting expert, but basically what this script does is it uses the name of the script to determine what program to run from the chroot, and will also take any arguments given and append them to the end of the dchroot command. Make sure it is executable ("sudo chmod 755 /usr/local/bin/do_chroot"). Now, make a link to the script called "skype" in /usr/bin:
sudo ln -s /usr/local/bin/do_chroot /usr/bin/skype

This script is slick in the fact that it will use the name of the link in the script to run the whatever program the link is named after. This means that when you make your link, make sure it is typed exactly as it needs to be to launch it in the chroot (So, in this example, make sure it is "skype" and not "Skype" or "launch_skype" or anything else. Just "skype".) If all has worked correctly, all you have to do now is type "skype" into the terminal to launch the 32-bit only Skype!

Conclusion
It is a little bit of effort to set up, but after the chroot is set up, new 32-bit applications can be installed by entering the chroot, installing the application, exiting the chroot, and linking to the do_chroot script. Using this method, I have installed and use the following 32-bit only applications:
  • Skype
  • TweetDeck (which uses the Adobe AIR environment, currently only for 32-bit)
  • SwiftFox (The 64-bit Flash Player alpha kept crashing IceWeasel so I switched to SwiftFox and a 32-bit Flash Player)
  • Amazon.com MP3 downloader