Skip to content

Instantly share code, notes, and snippets.

@mikesmullin
Created April 13, 2011 12:56
Show Gist options
  • Save mikesmullin/917487 to your computer and use it in GitHub Desktop.
Save mikesmullin/917487 to your computer and use it in GitHub Desktop.
Install Ubuntu Server in VirtualBox
# download an ISO of Ubuntu 10.4 LTS Server
# NOTE: If your pc is 64-bit and can emulate 64-bit VMs get that one. If not, use the i386/32-bit iso
# http://releases.ubuntu.com/lucid/ubuntu-10.04-server-amd64.iso
# http://releases.ubuntu.com/lucid/ubuntu-10.04-server-i386.iso
# download and install latest VirtualBox (3.2.4 r62467)
# http://www.virtualbox.org/wiki/Downloads
# run VirtualBox
# click Machine > New (Ctrl+N)
# click Next
# type Name:
# select Operating System: Linux
# select Version: Ubuntu (64 bit)
# click Next
# click Next # keeping memory at 512 MB, the default
# click Next # to "Create new hard disk", the default
# click Next
# click Next # for "Dynamically expanding storage", the default
# change size to 20.00 GB because sometimes you need the room and it doesn't affect the .vdi size to raise this maximum limit
# click Next
# click Finish
# click Finish
# right-click on new vm for context menu
# click "Settings... (Ctrl+S)"
# click "System" > "Motherboard"
# uncheck "Floppy'
# click "System" > "Processor"
# check "Extended Features:" "Enable PAE/NX" # very important or you will get errors with Ubuntu Lucid
# click "Storage"
# under "SATA Controller", right-click on the .vdi and chose "Remove Attachment"
# right-click on "IDE Controller", choose "Add Hard Disk", and then select the .vdi file you just removed.
# This is because you have to use IDE; SATA is broken at the moment.
# under "IDE Controller", highlight "Empty" and ensure the right "Slot:" says "IDE Secondary Master"
# click the yellow-folder-with-green-up-arrow icon to the right of "CD/DVD Device:" to open the Virtual Media Manager
# click "Add" toolbar icon button to open the file browser dialog
# browse to and select your Ubuntu 10.04 Server .iso
# click Open
# click OK
# NOTE: sometimes at this point there is a bug in VirtualBox where the left menu that used to show General, System, Display, etc. is now collapsed. To fix you have to close the window and repeat steps to select .iso
# click Audio
# uncheck "Enable Audio"
# click Network
# select "Attached to:" "Bridged Adapter"
# NOTE: click "Advanced" and make note of the Mac Address if you need to have it added to your router. I prefer this way because I have mac address filtering enabled on my router.
# click USB
# uncheck "Enable USB Controller"
# click OK to close the window and save all your settings changes
# highlight the vm and click Start tollbar icon button
# when Ubuntu setup boots, it prompts you to select your language, with English being the default
# select language as you wish (e.g. English)
# press F4 at main menu and select "Install a Minimal Virtual Machine" then press enter twice to begin installation
# answer localization questions as you wish (e.g. US Keyboard)
# if asked, select "Do not configure network at this time"
# hostname can be whatever u like (e.g. development)
# chose your time zone
# choose "Guided - use entire disk"
# choose NO to "Encrypt my home directory" when prompted; it causes problems with keys
# choose "no automatic updates" when prompted
# do NOT choose any software to install when prompted, instead hit TAB and ENTER to skip
# YES to install GRUB bootloader
# CONTINUE to reboot
# once booted to prompt, login
sudo -i # become root
# NOTE: wherever you see the username 'mikesmullin' replace with your own in these instructions
# install ssh
apt-get install openssh-server
logout # of root
logout # of your user
# outside the vm, i also prefer to add a host entry for mysite.local to my /etc/hosts
# from outside the vm, ssh into the machine from now on
ssh mysite.local
sudo -i
visudo
# change line 28 to read:
%admin ALL=NOPASSWD: ALL
:wq
rm /etc/motd
logout # of root
logout # of your user
# now would also be a good time to install your ssh key
# so you don't have to type your password every time you ssh into the vm
# from your localhost (outside vm):
ssh-copy-id -i ~/.ssh/id_dsa.pub mysite.local # this assumes you already have generated an rsa ssh key
# install vbox guest additions
ssh mysite.local
sudo -i
apt-get update && apt-get dist-upgrade
reboot # to switch to latest kernel
# once vm is rebooted:
ssh mysite.local
sudo -i
apt-get install linux-headers-virtual build-essential psmisc wget vim
#apt-get install xserver-xorg xserver-xorg-core # NOTE: uncomment this for 32-bit systems
# in the vm window
# switch focus to the window entitled "[Running] - Oracle VM VirtualBox"
# click Devices > Install Guest Additions... (Host+D or RCtrl+D)
# NOTE: for some people the menubar at the top of that window is gone. if this is you, you can still use the keyboard shortcuts above and use the arrow keys left/right to switch menus or up/down to make your selection
# now resume from your ssh terminal:
cd /media && mkdir cdrom
mount /dev/cdrom cdrom && cd cdrom
./VBoxLinuxAdditions-amd64.run
reboot
# once vm is rebooted and at login prompt,
# at this point it is a good idea to make a snapshot of the virtual machine:
# switch focus to the window entitled "[Running] - Oracle VM VirtualBox"
# click Machine > Take Snapshot... (Host+S or RCtrl+S)
# name the snapshot "fresh ubuntu install"
# this way you will always have this point to roll-back to if you manage to mess up the next steps
# feel free and please remember to make as many snapshots as you like; you can never have too many, only too few.
# now resume from your ssh terminal:
ssh mysite.local
# setup src
# add your localhost directory containing your src code dir to vbox vm as a permanent shared folder named 'src'
sudo -i # become root
cd /media && mkdir src
echo "src /media/src vboxsf rw,uid=1000,gid=1000 0 0" >> /etc/fstab
mount -a
# NOTE: If you get the following error, go to vm Devices > Shared Folders...
# and make sure you add the ./src dir and check "Make Permanent"
# then run above cmd again.
# /sbin/mount.vboxsf: mounting failed with the error: Protocol error
cd /var/www && ln -s /media/src src && cd src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment