Showing posts with label virtual machine. Show all posts
Showing posts with label virtual machine. Show all posts

13 March 2013

358. Gentoo in a virtual machine

This post took a LONG time to write, so hopefully someone, somewhere, will find it useful. My enthusiasm was also somewhat tempered during the installation. Gentoo just didn't speak to me. Maybe I'll feel differently in 6-12 months of Arch?

The post...

I'm sure that there are plenty of similar posts out there, and I admit that my main reason for writing this post isn't as much to get anyone else to play with gentoo (although it's certainly an interesting experience -- but probably a bit more fun on native hardware with a bit more oomph) as to provide myself with a written step-by-step instruction set if I should switch my mini-server to gentoo (I use it for testing/educational purposes).

I also realise that given that the most obvious advantage of gentoo is the hardware optimised binaries, running things in a virtual machine isn't going to show off the real strength of gentoo. Hopefully it might give an accurate impression of the complexity (or lack thereof) of gentoo as compared to other distros such as Arch and Debian.

Virtual machine
I'm doing this in a virtual machine. The principal reason is that I don't have any spare metal at the moment. The secondary reason is that because gentoo installation is very interactive, you will most likely not be able to do a complete installation in a single 2-hour sitting the first time (you'll have to look things up, think about modules etc. -- and compiling everything takes time), and doing things in a virtual machine makes it very easy to freeze the system until you have time to continue. Obviously you can also do it the old-fashioned way (simply chroot the system when you are ready to continue), but freezing is easier.

I probably should have switched to KVM by now, but since I'm not really that interested in using virtual machines for work, and since virtualbox is so simple to use, I'll be using Virtualbox here.

I wouldn't recommend trying Gentoo until you first feel somewhat familiar with the basic concepts on Linux (by using e.g. Debian), followed by trying a more hands-on distro like Arch, or one of the BSDs. Obviously, I'm biased since this is the path I've taken, but I still think that you're better off pushing yourself little by little, than suddenly jumping into something unfamiliar which then may turn into something that seems unfriendly and losing all interest as a consequence.

That's not to say that gentoo is difficult. What is or isn't difficult depends on your expectations and frame of reference. What I am saying is that gentoo will make a lot more sense if you have at least a conceptual idea of what is needed for a system to be bootable and useful (if you don't know that you need an X server, you won't enjoy this. If you haven't played with GRUB, you won't enjoy this).

Anyway.

I've followed http://www.gentoo.org/doc/
-- although I've focused on getting a working system quickly rather than spending a lot of time looking into what hardware I really have.

1. Create the virtual machine.
If you need help setting up a virtual machine you are most likely not going to enjoy gentoo (yet -- so come back in a few months), so I won't show that. Suffice to say that I created a machine with 1024 Mb RAM and 15 Gb HDD. The size of the harddisk is due to compilations normally requiring a fair amount of temporary storage space (you can probably get around it with tempfs if  you can spare it).

2. Get a gentoo cd. 
At this point we have an unpartitioned, unbootable harddrive so we need to boot our machine using some form of linux distro that can partition our virtual machine harddrive, as well as chroot gentoo. You don't need the gentoo cds for this, but it does make sense to use them.

You can use a minimal CD,a full DVD, or a stage 3 tarball. I'll use the CD.

Mirrors are found here: http://www.gentoo.org/main/en/mirrors2.xml
You will want to go to /gentoo/releases/amd64/current-iso and pick your architecture, e.g. I did

wget ftp://ftp.swin.edu.au/gentoo/releases/amd64/current-iso/install-amd64-minimal-20130110.iso
wget ftp://ftp.swin.edu.au/gentoo/releases/amd64/current-iso/install-amd64-minimal-20130110.iso.DIGESTS
sha512sum install-amd64-minimal-20130110.iso
77ab0ba00767b6d4668d0f4bf7effbf2af3f38a1bd7cef297a17076478fd46d05b15a80188da473cf7d7f8c220acbe615afd300de4af90011d54185be2697f7d install-amd64-minimal-20130110.iso
cat install-amd64-minimal-20130110.iso.DIGESTS
# SHA512 HASH 77ab0ba00767b6d4668d0f4bf7effbf2af3f38a1bd7cef297a17076478fd46d05b15a80188da473cf7d7f8c220acbe615afd300de4af90011d54185be2697f7d install-amd64-minimal-20130110.iso

3. Boot
Attach the iso to your virtual machine and boot/start.

Hit enter.
The fun begins :)

Note that everything in virtualbox 'just works' since there's a dhcp server etc. Real-world hardware may require a bit more work to get the network etc. up and running. Anyway, the gentoo manual tries to cover most eventualities, which may make it a bit more complicated to follow. We don't have to worry about most options.

4. Partition the drive
ls /dev/sd*
/dev/sda
fdisk /dev/sda

Hit n (for new partition), p (for primary), accept 1, and 2048, set +13G, then n, p, 2, and accept the defaults. Do a, then 1 to make partition 1 bootable. Do t, 2, 82 to set sda2 as swap. Hit w to write. You've now created one bootable root and one swap partition.

mkswap /dev/sda2
mkfs.ext4 /dev/sda1

This isn't the gentoo way -- we're using a single root here instead of making separate partitions for root, usr, home etc. On the other hand, since we're just exploring we might as well keep things simple.

5. Setting up the chroot
Make sure that the date/time is right.

date -s "18:08 20130307"
mount /dev/sda1 /mnt/gentoo
cd /mnt/gentoo
wget ftp://ftp.swin.edu.au/gentoo/releases/x86/current-stage3/stage3-i686-20121213.tar.bz2
tar xvjpf stage3-i686-20121213.tar.bz2

Extracting the stage3 file creates the standard linux file structure (/var, /boot, /dev, /etc, /proc etc.).
Edit the (/mnt/gentoo)/etc/ports/make.conf
vi etc/ports/make.conf
CFLAGS="-O2 -march=native -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j1"
CHOST="i686-pc-lnux-gnu"
USE="bindist"

If you have multiple cores, change the MAKEOPTS accordingly. The USE flag seems to be 'bindist' on i686, and 'bindist mmx sse sse2' on amd64. Presumably they depend on what gentoo detects on boot, and you will probably want to keep these.

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -r -o >> /mnt/gentoo/etc/portage/make.conf
cp /etc/resolv.conf etc/resolv.conf
mount -t proc none proc/
mount --rbind /sys sys/
mount --rbind /dev dev/

6. Enter the chroot -- set-up
chroot /mnt/gentoo /bin/bash
source /etc/profile
mkdir /usr/portage
emerge-webrsync

This will take a while, so don't give up if it seems stuck on 'Syncing local tree' and there's no network traffic.
.
emerge --sync
eselect profile list

There are seven different profiles on i686 and 13 on amd64 to choose from. I picked number 4 (default/gnome).
eselect profile set 4

I can't stand nano, so
emerge portage
emerge vim

Vim does take quite a while to install, so if you're happy with nano, stick with it.

Edit /etc/portage/make.conf
USE="bindist gnome gtk -kde -qt4"
Keep the USE flags that were there from the beginning and append gnome, gtk etc. I admit that I can't be bothered reading through /usr/portage/profiles/use.desc just in order to check out gentoo.

cp /usr/share/zoneinfo/Australia/Melbourne /etc/localtime
echo "Australia/Melbourne" > /etc/timezone

7. Compile/Install the kernel

emerge gentoo-sources
cd /usr/src/linux

Time to build a kernel! Do
make help|less

and look at the targets. Be aware that if you do 'emerge pciutils' as recommended by the gentoo guide this will take a long, long time since it pulls in 60 packages...but you need to if you want a working lspci.

My approach here is to first use make localmodconfig to get all the currently loaded modules, and then add more support manually via make menuconfig. Remember that if you screw things up you can always go back and redo it later. Build a minimal configuration, then explore what else you need to add (USB support etc.)

make localmodconfig
make menuconfig

IMPORTANT: 
1. Make sure to change 'Device Drivers/Serial ATA and Parallel ATA drivers' from (M) to (*).
2. Go to the submenu and make sure that AHCI SATA support is starred (i.e. not M) as well as 'Generic ATA support' Otherwise you'll probably find yourself consulting this post: http://wiki.gentoo.org/wiki/Knowledge_Base:Unable_to_mount_root_fs due to
VFS: Cannot open root device "sda1" or unknown-block(0,0)
Please append a correct "root=" boot option; here are the available partions:
...
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Anyway.

make
make modules_install
cp arch/x86_64/boot/bzimage /boot/vmlinuz-3.7.10
cp System.map /boot/System-3.7.10.map
ln -s /boot/System-3.7.10.map /boot/System.map

The first step make took me 16 minutes, which isn't bad for a single-core compile.

While you don't have to (since we have a single / partition), you might as well do
emerge genkernel
genkernel --install initramfs
mv /boot/initramfs-genkernel-x86_64-3.7.10-gentoo /boot/initramfs-3.7.10

You can edit /etc/conf.d/modules and list the modules you want to load. Have a look at the output of lsmod to get an idea. Doing 'lsmod > modules.list' might be a good idea for troubleshooting later.

8. Miscellaneous

Edit /etc/fstab
/dev/sda1 / ext4 defaults 0 2 /dev/sda2 none swap sw 0 0

Set a hostname:
echo 'HOSTNAME="turbotux"' > /etc/conf.d/hostname
echo '127.0.0.1 turbotux localhost' > /etc/hosts

If you don't set a domain name and don't want hostname.unknown_domain to greet you on boot, run
sed -i 's,\\O,,g' /etc/issue

Edit /etc/conf.d/keymap and set keymap.

echo 'en_AU.UTF-8 UTF-8' >> /etc/locale.gen
locale-gen
echo 'LANG="en_AU.UTF-8"'> /etc/env.d/02locale
env-update
source /etc/profile

emerge mlocate vixie-cron sysklogd

rc-update add sshd default
emerge dhcpcd

9. GRUB2
GRUB might be a better, albeit retro, learning experience, but GRUB2 has better auto-configuration features and I'm not interested in hand-configuring grub just yet.
echo 'sys-boot/grub:2' >> /etc/portage/package.accept_keywords
emerge grub:2
mkdir /boot/grub2
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-install /dev/sda

IMPORTANT: set a root password before restarting or you won't be able to log in:
passwd

exit
shutdown -h now
Remove the CD from the virtual machine. Start the machine again

10. Your first boot
If all went well (i.e. you did exactly what I did above) you'll be greeted with this:

You can now log in as root.

11. Installing Gnome 2

The current version of gnome in gentoo (stable) is 2.32. If you want that, just emerge gnome. If not, the easiest (not safest) way to is switch to testing which might not be the best choice for gentoo novices.
To set up gnome I'm following this post: http://www.gentoo.org/doc/en/gnome-config.xml
If you can't live a single day without gnome 3, then checkout http://en.gentoo-wiki.com/wiki/Gnome_3

Anyway, gnome 2.32:

Then do
emerge --sync
emerge --update --ask world
emerge gentoolkit
equery m gnome

Brace yourself, because this will take a while (549 packages!):
emerge --ask --autounmask-write gnome
dispatch-conf
emerge --ask gnome

Hit Yes when you run the first command (change Use params), u (use new) when you run the second command, and Yes for the third command (emerge new packages). This step took 660 minutes in a virtual machine with a single core assigned.

env-update
source /etc/profile
emerge --sync
rc-update add dbus default
/etc/init.d/dbus start

Create a user:
useradd -m verahill
emerge sudo gksu
echo 'verahill ALL=(ALL) ALL'>>/etc/sudoers
passwd verahill
su verahill
cd ~

Continue setting up gnome:
echo 'export XDG_MENU_PREFIX=-gnome' > ~/.xinitrc
echo 'exec gnome-session' >> ~/.xinitrc
ln -s /etc/xdg/menus/gnome-applications.menu /etc/xdg/menus/applications.menu 
startx

You shouldn't have to do both the XDG_MENU_PREFIX and the symlink, but I had to in order to get a working applications menu.

Without vbox guest additions installed


To install the vbox additions, click on Devices/Install Guest Additions in the virtual machine menu. The CD will fail to mount.
sudo mount -o loop /dev/sr0 /mnt
sh /mnt/autorun.sh


Reboot, then do startx again. If you want gdm to start, then see step three here: http://www.gentoo.org/doc/en/gnome-config.xml

With vbox guest additions installed
Sounds is another story entirely...http://wiki.gentoo.org/wiki/PulseAudio

Anyway, that's enough of Gentoo for me for now.

04 June 2012

173. ECCE in a virtual machine: step by step using virtualbox

!NOTE!
Pre-built binaries of ECCE now ONLY exist for 64 bit OS -- if you install a 32 bit version of debian you will have to compile ECCE yourself. It's not difficult, but please be aware of it.

!NOTE2! If you provide ECCE with 'localhost' as the hostname during installation, be aware that this will block outside access: http://www.nwchem-sw.org/index.php/Special:AWCforum/st/id858/#post_3178

See this post for ECCE 6.4 of Debian 7 (wheezy): http://verahill.blogspot.com.au/2013/05/434-ecce-64-on-debian-7-in-32-bit.html
!NOTE!

Sadly, not everyone uses linux. Some even refuse to give it a proper consideration. Since the goal here is science rather than OS enlightenment, we'll have to accept that some people will have to run ECCE in a virtual machine rather than using it natively (something like WINE but going the other direction would be nice).

Win/Mac users should not be surprised if graphics heavy applications like ECCE don't run very fast in a virtual machine though, but they will be the source of that frustration themselves.

Here's the whole sequence from downloading an iso to having ECCE ready to submit jobs from inside a virtual machine.

I'm doing all these steps on linux since I simply don't use or have access to windows (other than as a very small virtualbox install), so let me know if there's anything which won't work on windows. I'm particularly interested in XP since that's what most people in academia still use.

You can of course use these instructions on a proper debian installation as well.

The only reason this post is so long is because of the number of screen shots. It is NOT COMPLICATED OR DIFFICULT, so don't be put off by the length.

Index:
1. Install virtualbox
2. Set up the machine
3. Download the debian iso
4. Install debian in virtualbox
5. Customize your debian installation
6. Installing ECCE
7. Setting up ECCE
8. Launching a test calc.
9. Moving files back and forth between virtual debian and windows


1. Install Virtualbox
I've tested this step in my virtual XP machine, so it should work fine on a 'real' XP machine.

Download the windows installer: http://download.virtualbox.org/virtualbox/4.1.16/VirtualBox-4.1.16-78094-Win.exe . If the link doesn't work, then go to https://www.virtualbox.org/wiki/Downloads

Start the installer. It appears to be a bit buggy since the 'back' button doesn't work, so make sure that you think about your choices. Otherwise starting over isn't that hard.

 ...and start. You'll get a warning about network interfaces being reset. That's fine.

You get five of those Unsigned driver thingy warnings -- a Microsoft protection racket if you'd ask me (compatibility assurance is a good thing -- forcing developers to pay for warnings to go away isn't). Just click continue.


When you're done, launch:



Download the extensions from here: http://download.virtualbox.org/virtualbox/4.1.16/Oracle_VM_VirtualBox_Extension_Pack-4.1.16-78094.vbox-extpack



Click on Machine, Preferences and select Exentions. Click on the small Blue rhomb with the orange triangle on it on the right side of the window, navigate your way to where you downloaded the extension and install it:

 And this is what it looks like when you're done:




2. Set up a new machine
Click on New. Follow the instructions.

A few things to think about:
* Assign a reasonable amount of RAM, whatever that means. I'd suggest 1-1.5 Gb if you have 4 Gb machine. I'm testing 512 Mb in this example to see what the lower requirements are.
* Definitely make your hard drive big enough from the beginning since expanding it isn't that easy.

Here's a series of screen grabs:

 Select Linux, Debian (64 bit if possible)
 Set the amount of RAM. The more the merrier, but leave enough for your OS.


 Use a dynamically expanding HDD.
 10 Gb is a good start, but you'll have to move computational files off of the virtual hard drive periodically. The underlying OS only uses a small amount of storage space, but ECCE -- depending on what you do in it -- can use a lot more.





3. Download the iso
Clicking the following URL will hopefully start a download:
http://ftp.nl.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/

If not, then have a look at this page: http://www.debian.org/distrib/netinst and click on AMD64 under Small CDs (180 Mb). This will get you the latest Debian Squeeze, which is a bit old but rock solid. Upgrading to testing is a breeze if you should want to do that later.


4. Installing Debian
Select your new machine, and click on settings.

 Click on Storage
 Mount the iso you downloaded
 When all is good it should look like this:
Hit OK.

Two things you'll need to know at this point:

  • Right CTRL is your 'host' key. Hit (right) CTRL to release the mouse from the virtual desktop
  • Switch between full-screen mode using (right) CTRL+f (host+f)

Now you're ready to start your virtual machine, so click on Start, which brings you to this:


Most of the choices are fairly simple to answer so I won't cover them.
I selected:
Hostname - vecce
Domain name -- (empty)
Pick the mirror country that correspond to the country you're in. As for the actual mirror server, the first choice is normally ok. You can see if your uni is on the list, which will make it even faster.
Don't type anything when it asks for root password (done twice) since it's better (imho) to use sudo.
Our new user is called ecce, and this user will automatically be granted sudo powers.

Once you get to the partitioning, make sure to select Manual, and follow the screenshots below:
 First you need to format your harddrive. Remember, by harddrive we're really talking about a file on your disk, so screwing this up will NOT affect your windows computer in any shape or form.







 Having a Swap partition for a virtual HDD makes absolutely no sense.


Now your base system will install, and you'll eventually get to this screen. De-select the graphical desktop environment since we want to save space and resources -- gnome is wonderful, but demanding. We'll put LXDE on it later.
Install grub to the MBR. Remember, our harddrive is still just a file on your physical harddrive.

That's basically it. Click continue in the screen below, and your virtual system will restart.
 And here's what'll great you on reboot:

You're now ready to log on and do some damage.

5. Customize your debian installation
So log on:

 Make sure you have working internet by e.g. doing
ping -c 3 google.com

Now, type
sudo apt-get install lxde
type your password (you'll get a warning about great reponsibilities etc.), and answer yes to any questions

Once the install has finished, type
sudo shutdown -r now
which will cause a reboot which will bring you to this screen:

I use gnome 3/gnome-shell myself, so I'm not particularly familiar with LXDE, so if anything looks weird in the following steps, that's why.

Log on:
You'll find your terminal (LXTerminal) by clicking on what constitutes the Start Menu down on the left:
First install a web browser (in this case chromium -- essentially a re-branded Chrome):
sudo apt-get install chromium-browser
Start chromium by clicking on the web browser icon in the panel launcher down in the bottom left corner:
6. Installing ECCE
Download ECCE:



Install csh by typing
sudo apt-get install csh 
in the terminal
Then do
cd ~/Downloads
chmod +x install_ecce.v6.3.rhel5-gcc4.1.2-m64
csh install_ecce.v6.3.rhel5-gcc4.1.2-m64
Select Full Install [3]

Change the hostname to localhost
Set the application install path to /home/ecce/ecce-v6.3/apps and the server directory to /home/ecce/ecce-v6.3/server
Then install.

Now, start leafpad:

Open ~/.bashrc (the ~ means it's in your home folder). You do that by clicking on File, Open, then click on file system, home, ecce, hit ctrl+H to show hidden files, and select .bashrc
Add the following to the end of the file:
export ECCE_HOME=/home/ecce/ecce-v6.3/apps
export PATH=$PATH:${ECCE_HOME}/scripts
alias startecceserver='/home/ecce/ecce-v6.3/server/ecce-admin/start_ecce_server'
alias stopecceserver='/home/ecce/ecce-v6.3/server/ecce-admin/stop_ecce_server'




Save, and exit leafpad.

Type
source ~/.bashrc
in your terminal. This will make the terminal read the new settings.
You still can't start since you're missing java:

So, in your terminal, do
sudo apt-get install default-jre

First make sure the ecce server isn't running
stopecceserver
then launch ecce
ecce
You're now being invited to set a new password:


Clicking OK launches what is called the Gateway:

7. Setting up ECCE
You're more than half-way there. The exact set up will depend on what you're trying to achieve and I've documented it elsewhere on this blog.

However, because I'm writing this guide with a couple of specific people in mind, I'll show how to set up a remote ROCKS site to submit to, using node hopping.

In the terminal, type
ecce -admin
 Set up as shown in the screen shot:

Don't forget to hit add/change queue first, then add/change in the bottom left, then close.

Because we're doing a lot of cool, advanced stuff we need to do some manual editing: we need to define the public url, and we need to define our SGE (Sun Grid Engine) settings and finally, we need to set up a couple of environment variables.

In the terminal, do
cd ~/ecce-v6.3/apps/siteconfig/
chmod u+rw CONFIG.rocks
Otherwise the file will be write-protected.


Using leafpad, open the CONFIG.rocks file which is found in /home/ecce/ecce-v6.3/apps/siteconfig/


Add the following (look at the screenshot below):
frontendMachine: rocks.university.edu

SGE {
#$ -S /bin/csh
#$ -cwd
#$ -l h_rt=$walltime
#$ -l h_vmem=$memoryG
#$ -j y
#$ -pe orte $totalprocs    
}

NWChemEnvironment{
            LD_LIBRARY_PATH /usr/lib/openmpi/1.3.2-gcc/lib/
}

NWChemCommand {
        /opt/openmpi/bin/mpirun -n $totalprocs $nwchem $infile > $outfile
}
Gaussian-03Command {
    setenv GAUSS_SCRDIR /tmp
    setenv GAUSS_EXEDIR /share/apps/gaussian/g09/bsd:/share/apps/gaussian/g09/local:/share/apps/gaussian/g09/extras:/share/apps/gaussian/g09
        time /share/apps/gaussian/g09/g09 $infile  $outfile }




Save and exit. (note the $memoryG so you don't put in 4000 but instead use 4 when setting memory during submission in launcher)

In the ECCE gateway, click on Machine Browser

Select rocks and click on Set Up Remote Access, give the user name and password. If all goes well, if you hit e.g. Disk Usage, you should see this:

8. Launching a test calc
Click on Organizer in the Gateway.






If you can't select basis set, theory etc. at this point, close the editor, then open again. Might be because it's the first run ever.


And launch:
 When it's done, it looks like this. Depending on your SGE set-up everything can be very fast, or every step can take a minute. To follow in real-time, click in Viewer. To see the output file, hit Run Mgmt and select tail -f. To look at output fiel from completed run, go to Run Mgmt and select Output.
It's fun, and easy!

9.  Moving files back and forth between your virtual debian and windows
First shut down your virtual machine, then click on settings.



When your virtual machine is running you can access it from e.g. windows using sftp with e.g. Filezilla like this:






I hope this guide has been useful. Again, it's long because of the level of detail, not because it's difficult in any way.

Learning how to use ECCE properly is a completely different tutorial. I might put up some examples with increasing complexity in the future.