Dec 15 2011

VirtualBox with Gentoo(1)

Category: English posts,TechnicalIuliana @ 10:38

As I have no computer using Linux in my house right now and I kinda miss it I decided to create a virtual machine with a gentoo on it. And as I will have to write some posts about setting up a full java development  environment on Linux and Windows I will use it for that too. I will post all the steps I make, because I’m no guru, so If I can do it, anybody will be able to just by following my steps. So, good luck and you are welcome to use the comment section for any problems you might encounter or questions I might answer.

Step1. Download and install VirtualBox.

Step2. Create a virtual machine following the instructions on the site and select operating system Gentoo. Select at least 1,5 GB memory and aVDI hard drive  of minimum 20 GB.

Step3. Download a Gentoo image from here.  I recommend the x86 version because 64bit version is not stable and given the fact that we’re gonna do a lot of stuff by hand I recommend the minimal iso. (install-x86-minimal-<release>.iso)

Step4. Start your machine from the VirtualBox window and select your iso as a boot device. When the window with the black linux console is opened the actual work beggins.

Step5.  You will see written on your virtual machine screen  “boot: “. If nothing is written the default option will be used. I used the gentoo-nofb, which disables the framebuffer,which will make things go faster in text mode. You will also asked to press enter for some default option at some time. (If you want a complete installation guide with technical explanations look here, because this article just specifies the steps to execute simply and blindly). After a lot of text is scrolled on your window  and the last line just contains just the word livecd#, you start executing the following tasks in this order: (print the commands and insert required data)

  1. Start the SSH server in order to be able to connect to your virtual machine via SSH :
    # /etc/init.d/sshd start
  2. Configure the network – use default configuration and test it:
    # net-setup eth0 (Blue screen appears:  hit <Enter>,
     then check option 2)My network is wired, <Enter>,
     then check option 1)Use DHCP to auto-detect my network settings, <Enter>)
    # ping -c 3 www.gentoo.org
  3. Preparing the disks:
    # fdisk /dev/sda/ 

    You’ll be greeted with a prompt that looks like this:

    #  Command (m for help): 

    We will be needing only a swap partition and a data partition, boot partition is not needed for virtual machines. These two can be created by following the next steps:

    #  Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    (Enter p)
    Partition number (1-4, default 1): (Hit Enter)
    First sector (2048-41943039, default 2048): (Hit Enter)
    Using default value 1
    Last sector +sectors, +size{K,M,G} (2048-41943039, default 41943039): +2048M (or + 2G)
    #  Command (m for help): t (type for the partition)
    Selected partition 1
    Hex code (type L to list codes): 82 (value corresponding to Linux swap) 
    #  Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    (Enter p)
    Partition number (1-4, default 2): (Hit Enter)
    Using default value 2
    First sector(4196352-41943039, default 4196352): (Hit Enter)
    Last sector +sectors, +size{K,M,G} (4196352-41943039, default 41943039): (Hit Enter)
    #  Command (m for help): p

    And the last printed thing should look like this:

    Device Boot   Start   End       Blocks  Id  System
    /dev/sda1    2048     4196351  2097152  82  Linux swap
    /dev/sda2    4196352  41943039 18873344 83    Linux
    #  Command (m for help): w (To save the partitions)
  4. Creating filesystems
    # mkswap /dev/sda1
    # swapon /dev/sda1

    (Activate swap)

    # mkfs.ext3 /dev/sda2
  5. Mounting
    # mount /dev/sda2 /mnt/gentoo
  6. Installing Gentoo instalation files:
    1.

    # cd /mnt/gentoo

    2.Go to http://www.gentoo.org/main/en/mirrors.xml and choose a mirror near you. Click on it then navigate to releases -> x86 > autobuilds -> current-stage3-i686 -> stage3-i686-<version>.tar.bz2 . Copy this link and use it as a parameter for command wget to download the archive.

    # wget http://<MIRROR>/gentoo/releases/x86/autobuilds/current-stage3-i686/stage3-i686-<version>.tar.bz2

    3.Go to http://www.gentoo.org/main/en/mirrors.xml and choose a mirror near you. Click on it then navigate to snapshots -> portage-latest.tar.bz2 . Copy this link and use it as a parameter for command wget to download the archive.

    # wget http://<MIRROR>/gentoo/snapshots/portage-latest.tar.bz2

    4.Unpack stage

    # tar xfp stage3-i686-<version>.tar.bz2  (I hope you did not left the /mnt/gentoo directory! Also, in case you are curious: x - extract; f - from file; p - keep permissions intact)

    5.Unpack portage

    # cd /mnt/gentoo/usr
    # tar xfp /mnt/gentoo/portage-latest.tar.bz2 
  7. Setting values for the new system:
    1.Hostname: 

    # cd /mnt/gentoo/etc/conf.d
    # nano hostname   (nano is a linux editor)

    The hostname file will be opened and inside you will see the following text: HOSTNAME=”localhost”. Navigate using arrow keys and replace localhost with a value you want. I used vm-gentoo-jules1. Then hit CTRL+X, then Y and <Enter> to save the changes. To test it:

    # cat hostname

    (the content of the hostname file will be displayed)
    2.Network:

    #  cp -L /etc/resolv.conf /mnt/gentoo/etc  (The "-L" option is needed to make sure we don't copy a symbolic link)
    #  cd /mnt/gentoo/etc/init.d
    #  ln -s net.lo net.eth0   (Creates symbolic link net.eth0 which will be needed at boot time to raise that network interface)
  8. 3.Timezone: timezone files are stored in /usr/share/zoneinfo . There is a folder for each continent which contains files for each each city with different timezone. That file has to be copied to /mnt/gentoo/etc and renamed to localtime. In my case what I did was this:
    #  cp /mnt/gentoo/usr/share/zoneinfo/Europe/Bucharest /mnt/gentoo/etc/localtime

    You will be asked if you want to override the file localtime, press Y to confirm and <Enter>.

This is all for now, I will come back with the next steps after I define them in the most possible simple manner.

Tags: , ,

Leave a Reply