How to install OS X Mavericks in VirtualBox?

If your host system is OS X, you can follow the instructions on: http://ntk.me/2012/09/07/os-x-on-os-x/

Requirement:
- Install OS X.app purchased in Mac App Store
- iesd

VirtualBox Settings:
- Operating System Version: Mac OS X (64 bit)
- Base Memory: 2048 MB (larger is better)
- Enable EFI

In the lastest VirtualBox, all the default settings work well. Some people encountered black screen upon booting the virtual machine. They reported that changing the default chipset ICH9 to PIIX3 fixes this issue.

  1. Prepare Install Disk

    gem install iesd
    

    iESD requires ruby-1.9.2 or later.

  2. Yosemite & Mavericks: The the new InstallESD.dmg is not bootable. Therefore, we need to create a bootable install disk with BaseSystem.dmg.

    iesd -i /Applications/Install\ OS\ X\ Mavericks.app -o Mavericks.dmg -t BaseSystem
    
  3. All Macs using Intel Haswell CPU (Macs after 2013) need to fake their CPU as Ivy Bridge in order to boot the virtual machine. Thank @danmccombs for this tip.

    VBoxManage modifyvm <vmname> --cpuidset 00000001 000306a9 00020800 80000201 178bfbff
    

    On Mac Pro Early 2009 and other Macs that have ECC memory, AppleTyMCEDriver.kext will cause a kernel panic during the boot. Thus we need to remove it.

    iesd -i /Applications/Install\ OS\ X\ Mavericks.app -o Mavericks.dmg -t BaseSystem --uninstall-extension AppleTyMCEDriver.kext
    
  4. Mountain Lion & Lion: The lastest VirtualBox does not require modifying InstallESD.dmg any more. However, if your virtual machine was freezed during the boot process due to AppleIntelCPUPowerManagement.kext, you need to install NullCPUPowerManagement.kext.

    iesd -i /Applications/Install\ OS\ X\ Mountain\ Lion.app -o Mountain\ Lion.dmg --install-extension NullCPUPowerManagement.kext
    
  5. The install process is same as normal OS X install on Mac


I was having problem with @Mark's answer exactly where he says - Install OS X.app purchased in Mac App Store.

Turns out to get that, you need to open Mac AppStore, hold Alt, go to Purchased tab, select to download your older OS X, and release the key.

(Tried to comment this on his answer but I don't have enough reputation to do that)

Source: Where May I (legally) get a Mac OS X .iso File to Virtualize OS X?