Showing posts with label gentoo. Show all posts
Showing posts with label gentoo. Show all posts

Resuming an Interrupted SSH Session

If you ssh into remote *nix boxes with any sort of regularity, it's almost inevitble that at some point your connection is going to drop. If it happens while you are editing a file it can be a real pain to start from where you left off. In my case, I had an account on my school's Unix server but it would kick me off after about 5-10 minutes of inactivity. Talk about frustrating. 

Fortunately, the "screen" command let's you easily restart your session. 

Get Screen

Your distro probably already has screen built in. If you're using ubuntu and it's not there just type:
sudo apt-get install screen
For gentoo the command would be:
emerge -av app-misc/screen
Using Screen

Once it's installed usage is trivial. If you're only going to be using a single session, connect via ssh and type:
screen
If you get dissconnected, reconnect your ssh session and type:
screen -R
You will then enter the session where you left off.
You can check if there is an existing screen session by typing:
screen -ls
 If you want to use multiple sessions, you will need to name the sessions with a unique name.
screen -S session1
Then connect in the same way, but including the session name:
screen -R session1
 Those are the basics! Screen has more advanced features you can check out in the man page.

Installing Gentoo on an Apple G5

I was lucky enough to recently acquire an old dual 2.5Ghz G5 from my brother because he was no longer using it. Sweet! This is the first Mac I've used since the late 90's, and I have to say I'm really impressed with the quality of the case, components, and construction. The only drawback is that it's the last Apple to use the PowerPC processor architecture, meaning consumer software isn't really being developed for it anymore. :(

Since updated software for OS X on PPC is getting hard to find, I decided that a source based Linux distro could extend the life of the machine a little longer (debateable, some feel an OS like Debian has more support). Although to be honest, a more practical option would be to keep OS X and compile any Linux software I wanted for OS X. But what's the fun in that? I haven't really used OS X but I would definitely like to experiment with it, so my goal is to have a dual boot system with OS X and Gentoo Linux.

I don't have any experience with Linux on PPC (especially the bootloader), so I decided to take no chances and removed the hard drive with OS X on it and put in a spare 160GB sata drive I had, just to make sure I didn't ruin some data. (fdisk /dev/sda instead of /dev/sdb has been known to happen...)

This walkthrough is heavily inspired from the PPC Gentoo Handbook. I had to make a few modifications since I didn't want a fully 64 bit system and the regular PPC handbook won't work for a G5 if you follow it exactly.

Getting Gentoo

The Gentoo minimal install CD can be downloaded here: http://distfiles.gentoo.org/releases/ppc/current-iso/
This walkthrough was made using "install-powerpc-minimal-20091018.iso"
Burn the iso to a CD-R with a program like Iso Recorder, Nero, or K3B.

Booting from the Install CD

Insert the CD (you may have to boot into OS X to eject the drive without forcing it manually). Reboot and hold down the "c" key after the startup tone sounds.
If you did it right, some information and boot options will be displayed by yaboot. Type "G5" and hit enter to boot from the livecd. If the display is corrupted (I had some problems with the pcie Radeon) try rebooting and typing "G5 video=ofonly" at the prompt.
The livecd should detect the network interface and start dhcp automatically.
When it's finished booting, start ssh so we can install from a different computer.

passwd password (use your desired password)

/etc/init.d/sshd start

ifconfig

Take note of the ipaddress and open an ssh connection from another computer. From Linux:

ssh root@$IP_ADDRESS

Prepare the Hard Drive

This part can get a little tricky. The drive needs a minimum of 4 partitions (counting swap), 2 of which are not used by linux. We will use mac-fdisk to partition the drive. Since, I am installing to a separate drive I'm not going to worry about mac partitions.

mac-fdisk /dev/sda

Press "i" to wipe the drive and initialize it. Warning: All data will be lost!
After the drive has been initialized, press "b" and enter "2p" when asked for the start block. This installs the Apple_Bootstrap partition.
Now we need a swap. Press "c" and enter "3p" for the block. Enter "512M" or greater when asked for the size. Most people generally use twice the installed memory. Type "swap" when the name prompt appears.
Finally, the root partition. Press "c" and enter "4p" to select the starting root block. When the size prompt comes up, type "4p" again to use up all the remaining space. When asked for a name, enter "root."
Hit "w" to save the changes, and then "q" to exit.

Set the Time

Maybe it's already correct? Type "date" and verify. If not set the correct time and date:

date 051018002010 (mmddhhmmyyyy - Month Day Hour Minute Year)

Create the Filesystems

I used ext3, a nice solid file system with plenty of support. Yaboot will not boot from ext4, so if you want to use it you will need a separate boot partition.

mke2fs -j /dev/sda4

Create and activate the swap partition:
mkswap /dev/sda3

swapon /dev/sda3
Mount the root partition so we can install Gentoo on it:

mount /dev/sda4 /mnt/gentoo

Download and Install the Latest System Files

Move to /mnt/gentoo to make things easier.

cd /mnt/gentoo

Now navigate to the Gentoo mirrors to download the latest stage 3 file:

links distfiles.gentoo.org

Navigate to releases/ppc/current-stage3 and download:

stage3-ppc64-32ul-*.tar.bz2

Unpack it:
tar xvpjf stage3-ppc64-32ul*.tar.bz2

Now portage needs to be downloaded and installed/updated.

links distfiles.gentoo.org

Navigate to releases/snapshots/current and download:

portage-latest.tar.bz2

Now install it:

tar xvjf portage-latest.tar.bz2 -C /mnt/gentoo/usr

It might take a while to finish decompressing.

Compile Options

We need to optimize compiling for the G5 processor.

nano /mnt/gentoo/etc/make.conf

Here's what I have in my make.conf:

CHOST="powerpc-unknown-linux-gnu"
CFLAGS="-O2 -pipe -mcpu=970"
MAKEOPTS="-j3"
VIDEO_CARDS="radeon"

Note since the 32bit User Land is being used, there is no 64 after the powerpc above.

Chroot to the New Installation

Copy over the DNS info so that the internet is accessible:

cp -L /etc/resolv.conf /mnt/gentoo/etc
Now /proc and /dev needs to be mounted:

mount -t proc none /mnt/gentoo/proc

mount -o bind /dev/ /mnt/gentoo/dev/

chroot /mnt/gentoo /bin/bash

env-update

source /etc/profile

You should now be inside the new Gentoo installation. Portage should already be up to date, but you can run "emerge --sync" to make sure.
List a profile:

eselect profile list

Select your desired profile:

eselect profile set 9 (9 is the 64/32 gnome desktop that I used)
Set the Timezone

Find your timezone with "ls /usr/share/zoneinfo"
Select it by "cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime"
You can see that I'm using PST time. Adjust to your needs.
While we are messing the time, might as well configure the clock.

nano /etc/conf.d/clock

Uncomment the line with "Factory" in it and replace "Factory with your zone/city. For me, that's "America/Los_Angeles"

Install and Compile the Kernel

For simplicity, I'm sticking with gentoo-sources.

emerge gentoo-sources

Now change directories:

cd /usr/src/linux

Configure the default settings for the G5:

make g5_defconfig

I've found the above command is all you need for a bootable system. Of course you should probably configure to your liking with "make menuconfig"
Now the tricky part! The G5 needs a 64bit kernel to boot, but we are using a 32bit User Land! This means we have to cross-compile the kernel. Just typing "make" will not work! Use the following:

CROSS_COMPILE="powerpc64-unknown-linux-gnu-" make && make modules_install

Wait until it's finished compiling (probably about 30 minutes) and then copy the kernel to /boot:

cp vmlinux /boot/kernel-2.6.32

Getting close! Bet you thought I forgot about fstab. Think again!
Edit fstab:

nano /etc/fstab

Make sure to comment out the line for the /boot partition
Change "ROOT" to "sda4"
Change "SWAP" to "sda3"
The default settings are configured for an ext3 /root and swap on sda3.

Set Hostname and Network

nano /etc/conf.d/hostname

HOSTNAME="yourcomputer"
Now emerge dhcp:

emerge dhcpcd

If you are using DHCP on your network, you most likely don't need to configure anything else. Gentoo will automatically get an address on boot.

Set the Root Password

This one is kinda important ;)

passwd

System Tools

To speed things up, I'm only installing a System Logger.

emerge syslog-ng

Now make sure it starts on boot:

rc-update add syslog-ng default

Bootloader!

The bootloader was one of the most confusing steps to me as I was used to grub.
Since we are using 32bit UL, we need regular yaboot (NOT yaboot-static)
emerge yaboot
Now, either exit out of the chroot, or just start a seperate ssh session to the live cd and run:
yabootconfig --chroot /mnt/gentoo

It's important you run the above command out of the chroot environment or it will error out.
If the fstab is configured correctly there should be no problems.The bootstrap should be /dev/sda2.
When it asks for a kernel type: "/boot/kernel-2.6.32" (or whatever you named your kernel)
Leave initfs blank.

When it's done, we are ready to reboot! Unmount /mnt/gentoo/proc /mnt/gentoo/dev/ and /mnt/gentoo
then reboot.
If all goes well, gentoo will boot to the command prompt!
From here on out, software can be instaled using standard emerge commands. After emerging gnome, a few other apps, and fiddeling with the appearence (thanks gnome-look.org), I ended up with this:


Conclusion
I actually had some fun working through this project, but I have to say I probably won't be using it as my main desktop. The system is noticeably snappier than OS X, but that may be because I have no 3D effects turned on. The main drawback is closed source software that isn't precompiled for PPC (Adobe Flash, Skype) won't work, which greatly reduces the usability of the system. (Maybe HTML5 will change that?)The OS X drive will be going back in soon and I'll experiment with compiling linux software in OS X. Oh well, it was a fun, project.

Installing Masked Packages in Gentoo

I've been avoiding installing masked packages for quite some time because I didn't know how to do it properly. I finally broke down and looked up the correct procedure.
Here is the improper way, which will either break your system or make it unstable if used sytemwide:

/etc/make.conf
ACCEPT_KEYWORDS="~x86"
-The x86 variable should be changed depending on your achitecture (x64, ppc, ppc64, etc)

Now, here is the "correct" way to unmask packages.
  • Edit or create the file "/etc/portage/package.keywords" -The file needs to be created if you have never accessed it before. 
  • Input the following, depending on the package. I'll use gnome-do as an example: "gnome-extra/gnome-do **"
In the future, use the command line without a text editor:
echo "gnome-extra/gnome-do **" >> /etc/portage/package.keywords
That's it!

Upgrading Gentoo using Emerge

A few days ago, for whatever reason, I had the insane urge to upgrade all the software on my Gentoo system to the latest version. I still havent gotten around to compiling the latest kernel that came with the update (2.6.33), mostly because I've forgotton what what hardware I have and I haven't been having any problems with my current kernel (2.6.31).
Things actually went smoothly for the most part, the process only got hung up on compiling and installing Virtual Box. I figured I wouldn't mess around with it because I'm running a Windows XP virtual machine for work and I don't want to screw that up.

I started with syncing emerge:
sudo emerge --sync
and then started the update:
sudo emerge -av --update world --deep
After confirming the upgrade, I let it compile overnight. Unfortunately, I didn't use the "--keep-going" option so the job stopped when it had problems with Virtual Box. I used the "--skip-first" option to successfully complete the rest.

So once that was all finished, I ran etc-update, and crap! 31 config files need to be updated! Mind numbing...
I got to work merging the files that I knew had custom changes in them. After a while, the -3 option was looking really tempting (auto-merge files with new copy). I finally gave in and used it with about 15 files left, and woohoo! Mundane file editing over!

Everything seemed great until I rebooted and I had no internet. Some quick troubleshooting revealed that I was receiving a dhcp address, but no DNS servers, meaning I was able to ping internet IP addresses, but not their names.

A nice little side effect of not being able to resolve names is my time was off, because my ntp client couldn't resolve pool.ntp.org. A temporary fix is really easy, just open up /etc/resolv.conf and add some name servers.

sudo nano /etc/resolv.conf
Then add:
nameserver 208.67.220.220
(OpenDNS)

Once done, I was immediately able to browse the web and sync my time, but why did it happen in the first place? To add to the confusion, every time I reboot the computer, dhcp overwrites the resolv.conf file with a blank file, meaning I have to add the DNS again!
Well, it turns out to be my mistake. I took a look at /etc/conf.d/net and noticed that I had set up the machine for a static IP, but dhcp was also starting at boot, overwriting the file. I'm actually not too sure how it was working before the update, but to fix it I just ended up setting it to full dhcp. After setting that, I rebooted and presto! Internet with no tweaks!

Setting up Amarok Media Player

Now that I have a bunch of new audio files, I wanted to be able to organize and play them in an efficient way. I've heard that Amarok is a really nice audio player, similar to iTunes but a little more powerful. Also, a nice feature is that you can store your music library information in MySQL database, making it quicker than other audio players, particularly if you have a very large music library.

Since I know amarok uses mysql, and it isn't installed on my system, I ran
sudo emerge -av mysql

When it completed installing, I ran
sudo emerge --config dev-db/mysql

(Found on the Gentoo MySQL Guide)
This allowed me to set up the root password.



Checked to make sure it starts normally with
sudo /etc/init.d/mysql start

When it started normally, I added it to the boot sequence with
sudo rc-update add mysql default

Now that MySQL is installed and running, it's time to install Amarok:
sudo emerge -av amarok

Once Amarok was done compiling and installing, I opened it up from the application menu, but nothing happened... When opening from a terminal window I got the following error:

"amarok: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory"
I went ahead and ran revdep-rebuild:
sudo revdep-rebuild

to see if that would fix the problem. It's generally one of the first things to try when running into a missing dependency on Gentoo. It scans for missing dependencies and re-compiles files as needed. Missing or broken dependencies are an unfortunate scenario that occasionally comes up with Gentoo. You wouldn't normally see such issues on a binary based distro like Ubuntu or Fedora.

Once the rebuild finished, I ran
sudo etc-update

and replaced the old sql conf file.
After that, I started up Amarok from the application menu, and success! It opened up normally!
Actually it opened with the following dialog showing:


Pressing OK brings the following screen:

This was expected, now we just need to create the SQL database, username, and password as defined in the configuration window. Start with:
mysql -uroot -p mysql

Then type in the password that was set up for root earlier.
Now that we are connected to mysql, we can create a new database with the following:
CREATE database amarokdb;

A "Query OK ..." will display if the command was successful.

We can add a new user with the following:
CREATE USER 'amarokuser'@'localhost' IDENTIFIED BY 'your_password';

You should use something other than "your_password" in the above command.
Again, we are looking for a "Query OK" to verify success.
Finally, we need to set permissions as indicated in the Amarok configuration window:
GRANT ALL ON amarokdb.* TO 'amarokuser'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;

Use the password created earlier for "your_password"
The "Query OK" message should display after each command.
At this point, the MySQL database, user, and permission should be successfully created.

Now, back in the Amarok Configure window, replace the password with the one that was created earlier and hit "Apply" or "OK." Then Amarok needs to be completely exited and then reopened for the new database settings to be used. When Amarok is reopened, the following window shows up looking for all the music files.

Find wherever the music files are stored, hit OK and Amarok scans the directory. The files are now shown in the Local Collection on the main Amarok Screen. From here on out it should be somewhat simple to figure out how to add playlists and so on. Check out the User Manual for more info on operating Amarok.

Ripping CDs using K3B

If you read my last post, you know I was on a quest to rip some CDs but was delayed by some hardware problems. Now that those are resolved, I thought I would document the process I used to actually rip the music, using my Gentoo desktop.

I had never ripped CDs using Linux (Who still uses CDs anyway?) so I started searching for an easy to use open source ripper. I have both gtk and kde libraries installed on my system, so it doesn't really matter what desktop the app is built for. One of the most popular Linux applications is Grip. I installed it on my system using "emerge -av grip" I did a test run with it but the interface wasn't very intuitive and I'm very impatient. (Who has time to RTFM?!)
Grip GUI

It seemed easy enough to use with the default settings, but one of my requirements is to rip the tracks using the lossless FLAC audio codec, and I couldn't easily figure out how to do that with Grip.

With Grip out, due to impatience, I kept searching and found K3B. I have used K3B in the past for burning CDs and DVDs but I was unaware that it ripped CDs. I installed K3B using "emerge -av k3b". The install took a while because there were quite a few dependencies my system needed to compile and install. When the installation was complete, I fired it up, and after the fancy splash screen disappeared, I easily found the ripping section of the program using the "More Actions" button on the main screen. I popped in the first CD, a Beethoven compilation, and was delighted to see that it automatically recognized it and downloaded the album and track info from CDDB.

Track info auto populated from CDDB

Selected the "Flac" filetype and custom target folder

Once I had the above settings configured, I hit "Start Ripping" and BAM! Music encoded with FLAC after a few minutes. Using the badass program Amarok (covered in next post) I was able to listen to the ripped music.