About Me

A Computer Enthusiast who's learning as much as I can, while attempting to share and re-distribute the knowledge! Enjoy! :D

Wednesday, August 22, 2012

Gentoo 2012 Install on a MacBook Pro via VB

This is quick tutorial and/or notes for myself on installing Gentoo as VM on MacBook Pro using Virtual Box.

Notes
------
* Followed on-line documentation at: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml
* Notes for a quick installation. In depth information ... read/follow the on-line documentation.
* To get a listing of available drives ... `ls /dev`

Installation
-----------
* I started on step 4: Preparing the Disks (from the on-line documentation)
After creating the extended partition, you then create the logical partition; make sure the /boot partition is bootable by using the 'a' option of fdisk;
* m: help
* p: print
* n: new partition
* w: write partition table
* a: make partition bootable
* d: delete partition
----------------------------
fdisk /dev/sda
----------------------------

This is the table I used for creating the partition table
----------------------------
/dev/sda1     /boot           +32M
/dev/sda2     swap           +512M
/dev/sda3     /                  +4G
/dev/sda4     Extended     default (remaining free space)
----------------------------

Logical Partition
----------------------------
/dev/sda5     /home          default (remaining free space)
----------------------------

* Make filesystems
I use ext4 types for the filesystem
----------------------------
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda5
----------------------------

* Create and enable swap space
----------------------------
mkswap /dev/sda2
swapon /dev/sda2
----------------------------

* Mount newly created filesystems
This assumes you're following my partition scheme; adjust to your needs
----------------------------
mount /dev/sda3 /mnt/gentoo
mkdir /mnt/gentoo/boot
mkdir /mnt/gentoo/home
mount /dev/sda1 /dev/gentoo/boot
mount /dev/sda5 /mnt/gentoo/home
----------------------------

* Enter into /mnt/gentoo directory
----------------------------
cd /mnt/gentoo
----------------------------

* Configure your network card
Since I'm in a VM, I had to manually set-up my network card; verify network connectivity with ping
----------------------------
net-setup eth0
ping www.google.com
----------------------------

* Download and untar stage3 tarball
Use links; verify you're in /mnt/gentoo (or the mountpoint at which you mounted your root fs; looks like i686 is used for newer processes (64-bit), i486 and lower are used for older/lower processors (32-bit)
* q: quit links
* d: download file
----------------------------
links http://www.gentoo.org/main/en/mirrors.xml
select a mirror
navigate to: releases --> --> current-stage3 --> stage3...bz2
----------------------------

* Download and untar latest portage snapshot
Use links; verify you're in /mnt/gentoo (or the mountpoint at which you mounted your root fs
----------------------------
links http://www.gentoo.org/main/en/mirrors.xml
navigate to: snapshots --> portage-latest.tar.bz2
tar xvjf /mnt/gentoo/port... -C /mnt/gentoo/usr - (port... is the portage name)
----------------------------

* Configure compile options
View /mnt/gentoo/usr/share/portage/config/make.conf.example for make.conf examples; I kept mine standard. If you have multiple processors for the VM, you could add -j2 for parallel compiling
----------------------------
nano /mnt/gentoo/portage/make.conf <-- this file is not created by default
* Optional * MAKEOPTS="-j2" into make.conf for parallel compiling
----------------------------

* Optional: Select a mirror relatively close to your location (speeds DL times)
----------------------------
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -r -o >> /mnt/gentoo/etc/portage/make.conf
----------------------------

* Copy DNS servers
----------------------------
cp -L /etc/resolv.conf /mnt/gentoo/etc

* Mount necessary filesystems
----------------------------
mount -t proc none /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys
----------------------------

* Chrooting into new environment
----------------------------
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1="(chroot) $PS1"
----------------------------

* Configure Portage
----------------------------
emerge --sync
----------------------------

* Choose profile
I kept the default profile: option 1 default/linux/x86/10.0 *
----------------------------
eselect profile list
----------------------------

* Configure USE variable
I kept the default USE variable (will research more on this)

* Optional: Select your timezone
After select your timezone region
----------------------------
ls /usr/share/zoneinfo
cp /usr/share/zoneinfo/US/Pacific /etc/localtime
echo "US/Pacific" > /etc/timezone
----------------------------

* Configure your kernel
2 possibilities: Manual or Genkernel

* Manual Configuration Version *
----------------------------
emerge gentoo-sources
ls -l /usr/src/linux
emerge pciutils <-- for lspci: hardware detection
cd /usr/src/linux
make menuconfig

* Configure your kernel; assistance found on Gentoo's website

* Compile your manual config kernel
After completion, write down your kernel name (for bootloader)
----------------------------
make && make modules_install
----------------------------

* Install the manual config kernel
----------------------------
cp arch/x86/bzImage /boot/kernel-3.3.8-gentoo <-- insert your kernel name

----------------------------

* Genkernel Version *
----------------------------
emerge gentoo-sources
emerge genkernel
genkernel all
ls /boot/kernel* /boot/initramfs* (for bootloader)
----------------------------

* Create fstab
defaults: rw, suid, dev, exec, auto, nouser, async
----------------------------
nano /etc/fstab
----------------------------

Based upon my partitioning scheme, here's my fstab
                                           FS
device        mount point       type       mount options       dump | fsck
--------------------------------------------------------------------
/dev/sda1     /boot                 ext4       defaults,noatime              1 2
/dev/sda2     none                  swap     sw                                  0 0
/dev/sda3     /                        ext4      defaults,noatime               0 1
/dev/sda5     /home                ext4      defaults,noatime               0 2
/dev/cdrom   /mnt/cdrom       auto       noauto,ro,user                 0 0 
--------------------------------------------------------------------

* Configure hostname
----------------------------
nano /etc/conf.d/hostname
hostname="gentoo-node"
----------------------------

* Configure network
----------------------------
nano /etc/conf.d/net
config_eth0="dhcp" <-- add into net
----------------------------

For automatically starting at boot
----------------------------
cd /etc/init.d
ln -s net.lo net.eth0
rc-update add net.eth0 default
----------------------------

* Change root password
----------------------------
passwd
----------------------------

* Optional: Add users; make sure wheel group is added for su access
* m: create home directory
* G: group listing
----------------------------
useradd -m -G users,wheel
----------------------------

* Confirm clock/date; Install optional system logger, etc ...

* Install bootloader (GRUB)
Skip if not in a VM and have another bootloader installed (Fedora, Ubuntu, etc)
----------------------------
emerge grub
nano /boot/grub/grub.conf
----------------------------

My grub.conf - manual config kernel
(hd0,0): (hard drive letter, device number)
Example: (hd0,0) translates to hard drive 1, /dev/sda1
----------------------------
default 0
timeout 30
splashimage=(hd0,0)/grub/splash.xpm.gz

# My Gentoo
title Gentoo 3.3.8
root (hd0,0)
kernel /boot/kernel-3.3.8-gentoo root=/dev/sda3
----------------------------

My grub.conf (based upon genkernel
----------------------------
default 0
timeout 30
splashimage=(hd0,0)/grub/splash.xpm.gz

# My Gentoo
title Gentoo 3.3.8
root (hd0,0)
kernel /boot/kernel-genkernel-x86-3.3.8-gentoo real_root=/dev/sda3
initrd /boot/initramfs-genkernel-x86-3.3.8-gentoo
----------------------------

* Install GRUB
----------------------------
grep -v rootfs /proc/mounts > /etc/mtab
grub-install --no-floppy /dev/sda (if no other Linux/UNIX distribution is installed yet)
----------------------------

* Exit, unmount FS's, and SHUTDOWN (or REBOOT)
Exit out of chroot environment, umount fs's, and shutdown the system.
** I'm installing inside a VM, with the ISO image mounted. To avoid errors, shut system down, and unmount the ISO image.**
----------------------------
exit
cd
/sbin/shutdown -h now ( or reboot)
----------------------------

Sunday, October 30, 2011

CUDA on Linux and OS X Lion - Updated

I wrote a quickstart sometime last year for CUDA on Linux and OS X. Here's an updated version covering CUDA 4.0 for Linux and OS X Lion. I will be installing the Toolkit and Example in my home directory. However, feel free to deviate and install in the normal system directories. Additionally, I'm using 64-bit version rather than 32-bit.

Please refer to NVIDIA's CUDA website to confirm your video card is CUDA ready. You can also check it here.

1.  Unless you have the proprietary NVIDIA Drivers already installed, download the appropriate Developer Drivers from here. Click on "Get Latest CUDA Toolkit".

2. Install the drivers as root. If you've installed Proprietary NVIDIA drivers before, the process is the same (for Linux).

Linux:
//**********
  • Ctrl-Alt-F2
  • Log in as root (as yourself on Ubuntu)
  • Stop your window manager: telinit 3 usually does it. For Ubuntu, try sudo service gdm stop (this assumes your running GNOME).
  • Become root (if not already) or utilize sudo for Ubuntu
  • Navigate to the directory where you've downloaded the NVIDIA graphic drivers
  • Run sh dev_driver_name.run. Try sudo sh dev_driver_name.run
//**********
 OS X:
//**********
  • Run devdriver.dmg
//**********

3. Download and install CUDA Toolkit.

Linux:
//**********

shell$ cd Downloads
shell$ sh cudatoolkit.run

For "enter install path", I used my home directory: /home/myname. You may utilize default path if needed.

//**********

OS X:
//**********
  • Run cudatoolkit.pkg
//**********

4. Update your PATH and LD_LIBRARY_PATH:

Linux:
//**********

PATH - /Path/To/Your/CUDA/Install/bin (my version --> /home/myname/cuda/bin)
LD - /Path/To/Your/CUDA/Install/lib (my version --> /home/myname/cuda/lib64:/home/myname/cuda/lib)

//**********

OS X:
//**********

PATH - /usr/local/cuda/bin
DYLD - /usr/local/cuda/lib

//**********

5. Download and install GPU Computing SDK

Linux:
//**********

shell$ cd Downloads
shell$ sh gpucomputingsdk.run

For "enter install path", I accepted the default. This is dependent upon where your CUDA Toolkit is installed. Additionally, you will be asked to confirm your CUDA installation directory.

//**********

OS X:
//**********
  • Run  gpucomputingsdk.pkg
//**********

6. Make the example programs.

Linux:
//**********

shell$ cd NVIDIA_GPU_Computing_SDK
shell$ cd C
shell$ make

//**********

OS X:
//**********

shell$ cd /Developer/GPU\ Computing/C
shell$ make

//**********

You have a fully functional CUDA environment. Run a few of the example programs to test your environment. Good luck!

Thursday, October 27, 2011

OpenMPI Quickstart - Updated

I wrote a quickstart sometime last year for OpenMPI on Linux. Here's an update for OpenMPI for Linux and OS X Lion.

1. Download the latest openmpi source files:
 2. Find out how many processors are available to utilize (optional).

Linux:
//**********

shell$ grep 'processor.*:' /proc/cpuinfo | wc -l

//**********

OS X:
//**********

shell$ system_profiler | egrep "Processors|Cores"
      Number of Processors: 1
      Total Number of Cores: 2

//**********

3. Move the downloaded file to your home directory, and untar the file.

Linux and OS X:
//**********

shell$ cp openmpi-1.4.4.tar.bz2 ~
shell$ cd
shell$ tar -xvjf  openmpi-1.4.4.tar.bz2

//**********

4. cd into the newly created openmpi directory and view the INSTALL file. Here you will find more information on how to install OpenMPI.

Linux and OS X:
//**********

shell$ cd openmpi-1.4.4
shell$ less INSTALL

//**********

5. Run configure and append the prefix option with your preference for the binary installation location.

Linux and OS X:
//**********

shell$ ./configure --prefix=$HOME/openmpi

//**********

6. Run 'make all install'

Linux and OS X:
//**********

shell$ make all install

//**********

7. cd into your home directory and edit your .bash_profile or .bashrc (.cshrc for c shell) to include the bin install location within your PATH. Don't forget to source it.

Linux and OS X:
//**********
shell$ cd
shell$ vi .bashrc

export PATH=$PATH:$HOME/openmpi/bin

shell$ source .bashrc
shell$ which mpic++
/home/username/openmpi/mpic++

//**********

You now have a fully functionally parallel processing environment! Good luck!

Sunday, December 26, 2010

Eclipse + ShellEd plugin = Shell Scripting within Eclipse

Quick How-To for Eclipse + ShellEd plugin:

Tutorial on installing Eclipse Plugin ShellEd using the following:
  • MAC OS X (Version: 10.6.5)
  • Eclipse (Version: Helios Service Release 1)
1. Install Linux Tools Plugin
  • Within Eclipse: click Help --> Install New Software
  • Click "Available Software Sites" (link slightly below Add button)
  • Enable (check box): http://download.eclipse.org/technology/linuxtools/update
  • Click OK
  • Under "Work with:" --> Select the recently enabled linuxtools
  • Under "Linux Tools" (1st group) --> Enable: Man Page Viewer (Incubation)
  • Click Next --> Next --> Accept license agreement --> Finish
  • Restart Eclipse
2. Download and Install the latest ShellEd Plugin Build
  • Download the latest ShellEd Eclipse Plugin (.zip file) from: http://sourceforge.net/projects/shelled/files/shelled/
  • Within Eclipse: Click on Help --> Install New Software
  • Click Add --> Archive ...
  • Navigate to the downloaded location of the .zip file --> Click Open
  • Input a name for future reference --> Add Repository (Click Ok)
  • Check Box --> Next --> Next --> Accept license agreement --> Finish
  • Confirm Security Warning (Installing Unsigned Content) by Clicking OK
  • Restart Eclipse
3. Test the installation by creating a new Shell Project, setting up the Shell Interpreter, entering some code, and run the script within Eclipse.

Creating A New Shell Project
  • Create a new project: New Project Wizard --> Select Shell Script Project Wizard --> Click Next
  • Input the Project Name --> Click Finish (default setting are fine for now
Setting Up The Shell Interpreter
  • Navigate to Eclipse Preferences (Eclipse Menu --> Preferences)
  • Navigate to ShellEd Options --> Select Interpreters
  • Click Search --> Select the interpreter you would like to use --> Click OK
Entering Code
  • Insert a new file into the project --> Right click on Shell Project Name --> Select New --> Select File
  • Input file name --> Click Finish
  • Enter a few commands (Bash Interpreter for this example) and Save
Run The Script Within Eclipse
  • Click Run Menu --> Run As --> Run shell script
--
Resources

1. SourceForge: Information on setting up Interpreter within Eclipse
  • http://sourceforge.net/projects/shelled/forums/forum/399718/topic/3863713
2. Linux Tools Project Plugin Install Help
  • http://wiki.eclipse.org/Linux_Tools_Project/PluginInstallHelp
3. SourceForge ShellEd Source and Zip Files
  • http://sourceforge.net/projects/shelled/files/shelled/
4. Eclipse Marketplace ShellEd
  • http://marketplace.eclipse.org/content/shelled

Monday, July 12, 2010

Boost Libraries and Eclipse

Installing Boost Libraries

1. Download the most recent version of Boost Libraries - http://sourceforge.net/projects/boost/files/boost/

2. Within the directory where you want to put the Boost Installation, execute the following:
  • tar --bzip2 -xf /path/to/boost_1_45_0.tar.bz2
Lagatuz-MacBookPro:Downloads marklagatuz$ pwd
/Users/marklagatuz/Downloads
Lagatuz-MacBookPro:Downloads marklagatuz$ tar --bzip2 -xf boost_1_45_0.tar.bz2

You now have a working Boost Library consisting of Header files. If you would like to make sure of the compiled libraries ... continue on!

3. Set up the Boost Compiled Library
  • Run the bootstrap strict with the --help option to receive options
./bootstrap.sh --help
  • Create the directory where you would like the Boost Library Binaries to reside
Lagatuz-MacBookPro:Downloads marklagatuz$ pwd
/Users/marklagatuz/Downloads
Lagatuz-MacBookPro:Downloads marklagatuz$ mkdir boost_1_45_0_Compiled
  • Change directory into the boost installation directory (header files only)
Lagatuz-MacBookPro:Downloads marklagatuz$ cd boost_1_45_0
Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ pwd
/Users/marklagatuz/Downloads/boost_1_45_0
  • Run the bootstrap script. I've added the following options:
  • --prefix: is for my own installation directory choosing.
  • --with-libraries. is for choosing which library binaries I want installed

Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ ./bootstrap.sh --prefix=/Users/marklagatuz/Downloads/boost_1_45_0_Compiled --with-libraries=all
  • Finally, install the binaries (a /lib will be created inside the prefix directory)
Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ ./bjam install

Congratulations ... you have the Boost Libraries installed!

Integrating Boost with Eclipse

After a successful installation of Boost Libraries on your system, here are some steps to integrate the Library with Eclipse. I've installed on OS X, so a Linux flavor should be similar.

If you want to utilize the Library which are only inline and templates (non-compiled):

1. Within Eclipse: Go to Properties menu
  • Project --> Properties
2. Add the headers into your Include path during compilation
  • C/C++ Build --> Settings --> GCC C++ Compiler --> Directories
  • Add the location of your installed Boost Library Include Path (/Users/marklagatuz/Downloads/boost_1_43_0 for me)
3. Finally save the configuration

If you want to utilize the Library which are compiled:

1. Within Eclipse: Go to Properties menu
  • Project --> Properties
2. Add the headers into your Include path during compilation
  • C/C++ Build --> Settings --> GCC C++ Compiler --> Directories
  • Add the location of compiled Boost Library Include Path (/Users/marklagatuz/Downloads/boost_compiled/include for me)
3. Add the compiled Library to the Library search path during linking
  • C/C++ Build --> Settings --> GCC C++ Linker --> Libraries --> Library search path (-L)
  • Add the location of the compiled Boost Library (/Users/marklagatuz/Downloads/boost_compiled/lib for me)
4. Add the specific Library name to the Libraries
  • C/C++ Build --> Settings --> GCC C++ Linker --> Libraries --> Libraries (-l)
  • Add compiled Library name you would like to utilize
5. Finally save the configuration

You are ready to utilize the Boost Library during your development!

--
Resources

1. Boost Getting Started Guide
  • http://www.boost.org/doc/libs/1_45_0/more/getting_started/index.html

Monday, June 21, 2010

CUDA: Know your limits on global memory

I was coding away on an assignment when I ran into a conundrum: I was getting weird results when attempting to copy data onto the device. There would be instances when arrays copied onto the device would be accessible, yet inaccessible during another run.

The fact I'm coding CUDA kernels on OS X gives way to a dilemma: cuda-gdb is not available (yet) on OS X. I have to rely on old school debugging techniques ... a code walk through and print statements! After numerous tests and frustrations ... I figured out I was running into a problem with global memory:

marklagatuz$ /Developer/GPU\ Computing/C/bin/darwin/release/deviceQuery

Device 0: "GeForce 9400M"
Total amount of global memory: 265945088 bytes

The above reads approximately 265MB of global memory. I had 4 arrays consisting of 67MB each being copied onto the device. I was clearly running into memory issues. This would explain why each time a different array would cause problems.

Lesson learned: Check your device(s) limitations before coding away! Then again ... you should be doing that anyways!

Tuesday, June 15, 2010

Learned Something New (or actually a review of something old)!

Since I'm forcing myself to think in terms of OO (Object Orientation), I forgot that computers are still 1 and 0's! As I'm reading code to understand design patterns, algorithms, and methods others folks are using, I came across something I've never used before (at least in my own code): shift operators.

  • <<
  • >>
I've always thought of the chevrons as output redirection in scripting or in C++. I've forgotten they actually shift the bits either to the left or right:

(1 << 24) == 0001 1111 1111 1111 1111 1111 1111