Skip to content

[CEMRACS 2016] Practical sessions

Alexandre Ancel edited this page Jul 11, 2016 · 5 revisions

Introduction

For the practical sessions of the first week, you will work with PETSc and FreeFEM++. In order for you to be ready to participate to these sessions, you will need to have several libraries/software installed on your computer.

The easiest way to be able to use those software will be to follow this tutorial.

Software

You will use the following software:

  • VirtualBox: It is a virtualization software. It means that it allows you to run guest operating systems on your computer. In our case, we will be virtualizing an Ubuntu desktop OS. This will be able to run on Windows, Mac OS X and any Linux System.
  • Vagrant: This software allows you to configure and run lightweight and reproducible development environments. In our case, you can see it as a meta-virtualizer. In fact, it will allow you to generate a virtualized system for VirtualBox, by using a simple script.

Installation

First download and install VirtualBox. Choose the right version according to your operating system in the following link.
Then install Vagrant. Again choose the correct version for your OS at the following link.

If you are using a Windows PC, you will need to reboot your system for Vagrant to be usable.

Generating the virtual system

Loading from a box (if you have been provided one)

  • Import the image from the box file and name it:
vagrant box add CEMRACS-2016 ./package.box
  • Check if the image has been correctly imported:
vagrant box list
  • Create a base Vagrantfile for the image to launch:
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "CEMRACS-2016"

  # Tell vagrant how it can login  
  config.ssh.username = "ubuntu"
  config.ssh.password = "cemracs"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder ".", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    vb.memory = "1024"
    # Customize the number of processors available
    vb.cpus = "2"
  end
end

  • Load the VM from the box and start it with:
vagrant up

Creating the system from zero

Create a file named VagrantFile (with no extension) on your computer. And copy the following content into it:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrant configuration
Vagrant.configure(2) do |config|
  # Use Ubuntu 16.04 as base
  config.vm.box = "ubuntu/xenial64"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Change the name the VB
    vb.name = "CEMRACS-2016"

    # Display the VirtualBox GUI when booting the machine
    vb.gui = true
  
    # Customize the amount of memory on the VM:
    vb.memory = "1024"
    # Customize the number of processors available
    vb.cpus = "2"
  end
  
  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  config.vm.provision "shell", inline: <<-SHELL
    if [[ -z `cat /etc/default/keyboard| grep fr` ]]; then
      echo "Changing keyboard layout to fr"
      echo 'XKBMODEL="pc105"' > /etc/default/keyboard
      echo 'XKBLAYOUT="fr"' >> /etc/default/keyboard
      echo 'XKBVARIANT=""' >> /etc/default/keyboard
      echo 'XKBOPTIONS=""' >> /etc/default/keyboard
      echo 'BACKSPACE="guess"' >> /etc/default/keyboard
    fi

    # Change ubuntu user password
    echo "ubuntu:cemracs" | chpasswd      

    echo "Installing packages"
    # Do not ask for graphical confirmations and assume default config with DEBIAN_FRONTEND=noninteractive
    sudo apt-get update
    DEBIAN_FRONTEND=noninteractive sudo apt-get install -y ubuntu-desktop virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
    sudo apt-get install -y petsc-dev slepc-dev "*freefem*"
  SHELL
end

Once the file is created, you will need to open a terminal on your computer:

  • On Linux, use xterm for example
  • On Mac OS X, either iTerm or Terminal
  • On Windows, launch the command prompt (Use the search area in the Start menu and type cmd to find it)

Once the terminal is opened, go into the directory, where you put the file named Vagrantfile. You can also copy it to the directory where the terminal is launched. Before building the image, try typing vagrant. It should display information about the options available to Vagrant. If an error is displayed, try reinstalling Vagrant or reboot your computer.

You are now ready to built the virtual system, to do so, type the following command (You must be in the same directory as the Vagrantfile):

vagrant up

Additionally, you can specify the provider with the --provider=virtualbox. If you have other virtualization software, it will ensure that you use VirtualBox. The build will start and install all the required dependencies automatically. During the process, VirtualBox should open a window showing the launch of the virtual image. The process will not be over until the vagrant up command ends.

Once the vagrant up command has finished. Reboot the virtual system, with the following commands:

vagrant halt
vagrant up

Once the vagrant up command ends you will have a VirtualBox window showing an Ubuntu prompt ready to login.

To shut down the system once you are done working with it, use the vagrant down command. If you want to delete all contents of the virtual system, use the vagrant destroy command (Pay attention you will have to totally reconfigure your system after running this command).

Accessing the virtual system

You have to ways to access the virtual system :

  • Use the VirtualBox window to login into the system user interface
  • Use ssh to access the system with the command line. By default, the virtual system will be available at the following address 127.0.0.1:2222. So you can access it with the following command:
ssh [email protected] -p 2222

The two available logins are ubuntu and cemracs. You can use the one you want. The password is cemracs.