About Me

My photo
A Computer Enthusiast who's learning as much as I can, while attempting to share and re-distribute the knowledge! Enjoy! :D
Showing posts with label OS X. Show all posts
Showing posts with label OS X. Show all posts

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)
----------------------------

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!

Tuesday, June 1, 2010

Quickstart: CUDA using Bayreuth University CUDA Toolchain for Eclipse

I've been trolling through Google for a simple solution in integrating CUDA with Eclipse, and found a University which built an Eclipse plugin. This is a fantastic solution because my previous attempts required me to create my own Makefile (which partially defeats the purpose of using Eclipse!)

Here is my Quickstart for the plugin

Assumptions:
  • A fully functional C/C++ working environment (within the Eclipse IDE and on the command line)
  • A fully functional CUDA environment (including the CUDA Driver, Toolkit, and SDK
  • This assumes you are using OS X (Linux should be quite similar)
1. Install the Plugin (Trivial)
2. Add nvcc to your Path
  • Go to Eclipse --> Preferences
  • Click on C/C++ --> Environment
  • Under Environment variables to set --> click Add
  • Name = PATH (Note: Make sure PATH are all upper case)
  • Value = /usr/local/cuda/bin
  • Apply and OK
3. Create a new CUDA Project and Setup Compile and Build Environment
  • Ctrl + mouse click --> New --> C++ project
  • Under Project type box --> Executable --> select Empty Project
  • Name your project
  • Uncheck the following: Show project types and toolchains only if they are supported on the platform
  • Under Toolchains --> select CUDA Toolchain
  • Click Next
  • Click on Advanced Settings
  • Under C/C++ Build -->Environment --> Confirm PATH is set from previous step (should be USER: PREFS under Origin Column)
  • Under C/C++ Build --> Settings --> Tool Settings Tab --> CUDA NVCC Compiler --> Includes --> add /usr/local/cuda/include
  • Under C/C++ Build --> C++ Linker --> change Command from g++ to nvcc
  • Under C/C++ Build --> C++ Linker --> Libraries --> add cudart to Libraries (-l) and add /usr/local/cuda/lib to Library search path (-L)
  • Apply and OK
At this point you should have a fully functional CUDA Eclipse environment to develop CUDA Applications. Drop in some pre-built (non SDK dependent code) into the project and build it. If you want to run some of the SDK dependent code (located in /Developer/GPU Computing/C/bin/darwin/release), please follow the instructions located at Life Of A Programmer Geek.

*** UPDATE ***

When attempting to build my project, I was getting the following error message during the build phase:

make all
Building target: CUDAToolchainProject
ld: unknown option: -oCUDAToolchainProject
I tracked the problem down to not having "whitespaces" in between the following:
  • ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
  • This is located at --> --> Properties --> C/C++ Build --> Settings --> C++ Linker
  • Under Expert Settings --> Command line pattern
To mitigate the problem ... just add "whitespaces" in between the following:
  • ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX} ${OUTPUT} ${INPUTS}
However, I came across another error during the build phase:

Invoking: C++ Linker
g++ -L/usr/local/cuda/lib -o "CUDAToolchainProject" ./src/cu_mandelbrotCUDA_D.o ./src/cu_mandelbrotCUDA_H.o -lcudart
ld: warning: in ./src/cu_mandelbrotCUDA_D.o, file is not of required architecture
ld: warning: in ./src/cu_mandelbrotCUDA_H.o, file is not of required architecture
ld: warning: in /usr/local/cuda/lib/libcudart.dylib, file is not of required architecture
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [CUDAToolchainProject] Error 1

To mitigate this problem ... I changed the C++ Linker from g++ to nvcc
  • Properties --> C/C++ Build --> Settings --> C++ Linker
  • Command --> change from g++ to nvcc

The build phase completed successfully and an executable was generated!

The next steps are optional (If you want to follow Eclipse's general project structure, follow the next steps

4. Create Source Folders (Trivial)
  • Ctrl + mouse click --> New --> Source Folder
  • Name your folder
--

Resources

1. Bayreuth University Website
  • http://www.ai3.inf.uni-bayreuth.de/software/eclipsecudaqt/updates
2. NVIDIA CUDA forum: thread 160564
  • http://forums.nvidia.com/index.php?showtopic=160564
3. Life Of A Programmer Geek
  • http://lifeofaprogrammergeek.blogspot.com/2008/07/using-eclipse-for-cuda-development.html
4. Trial & Error