Sunday, May 1, 2011

Installing gentoo on vmware Virtual Machine



Why we need VM?


    Probably vmware.com should give good explanation for it but here are few points I made up.
  1. Create multi OS environment at your single machine! all running at once!
    Like on normal windows you would be switching between task/applications, with vm you would be doing same but among OSs, by pressing Alt+Tab! (Fascinating!!!)

  2. Replicating systems easily, helps a lot for setting up a test system.

  3. Helps develop client-server systems, where you can simulate client-server interaction to the maximum even on single host.

  4. Carry OS as file - OS becomes portable as good as file!





Nomenclatures

  • VM - Virtual Machine

  • Host OS - OS running over Physical system

  • Guest OS - OS running over Virtual system or VM



  • Things to Download before start



  • install-x86-minimal-20110426.iso

  • vmplayer



  • These files can be downloaded in advance on HostOS, or decided later on depending how to transfer those over VM.

  • linux-2.6.32.9.tar.bz2

  • stage3-i486-20110426.tar.bz2

  • portage-latest.tar.bz2



  • The problem we are going to face is how to transfer these downloads to VM guest OS. If we have internet connection available on Host OS, it cancels all of problems but if not then we need few of following methods to transfer files.

    If it is a Linux system hosting VM, then we could use scp or nfs to share these files.
    scp is convenient I think, but that will require to run sshd on host linux system. Make sure to test its working by trying login from another system if possible. Thing usually forgotten here is adding sshd to accept list of firewall or turning off firewall temporarily.

    If the hosts OS is windows. then probably it is better to burn these files on new ISO image file, and then mount that ISO image on VM. But On Windows it going to be a bit difficult to share these files. To create ISO image might need some third party software, and some search.


    Preparing Virtual Machine



    1. Install vmplayer


      After downloading vmplayer follow the setup procedure, Next Next Next..
      On Linux you would get a .bundle file. Like I got VMware-Player-3.1.4-385536.i386.bundle in my case, when I tried get vmplayer version for Linux.

      Need to run this file like
      $ ./VMware-Player-3.1.4-385536.i386.bundle
      This should take care of everything.

    2. Create new Virtual Machine



        Start the vmplayer
      • File -> Create a New Virtual Machine, a wizard will appear

      • Select option Installer Disc Image File (ISO)

      • Locate the already downloaded Gentoo Live CD Image.install-x86-minimal-20110426.iso. Then Next!

      • Select the Guest OS - Linux. Next! (Do make sure to pick right option for Version as "Other Linux 2.6.x Kernel"

      • Select the Guest OS - Linux. Next!

      • Name your virtual Machine. Next!

      • Set the disk size. 8G is my choice more than enough for my purpose. Next!

      • Virtual Machine is ready. Finish!



    3. Boot VM using the Gentoo Live Linux ISO file


        Double click the Virtual Machine named and created previously. It will start with booting Linux found on Gentoo Live ISO Image. This ISO Image will be mounted as a virtual CD.

        Yes everything appearing on VM Environment will be virtual now. The Guest OS is cheated for every physical device. There is option to couple physical device directly too. But for now we will use everything from virtual.

        Installing and Setting up Gentoo Linux
        A Gentoo Linux Installation LiveCD will kick start as you double click new VM. It will prompt you with first
        boot:
        Press Enter, and then keyboard layout. Choose it appropriately or keep the default 'us'
        To exit from VM shortcut keys Ctrl+Alt can always be used, VM takes exclusive control of Keybord and Mouse when working inside VM. So to get out to host OS, press Ctrl+Alt. Status bar of VM Window also indicates live actions those can be performed

          Steps to Install final Gentoo Linux
          These are instructions composed from this page http://www.gentoo.org/doc/en/gentoo-x86-quickinstall.xml.
        1. Create Linux partitions
          Need to use fdisk here, it might be the case we get warned many times for using this command. But we have a raw unused system here, can do almost anything with it. If things went wrong there is always option to redo again from start.

          $ fdisk /dev/sda

          Won't be going deep to explain /dev/sda but on Linux every physical device is treated as file. In our case every virtual device will be treated as file. The Virtual Hard drive of this VM will be represented with /dev/sda. When the kernel loads up it creates these device files. In our case the Linux from LiveCD will be creating these dev files. in /dev/ folder many of such device files can be found few for USB ports, few for Serial Port, RAM and many more. These files has zero existence as physical space it occupies on storage device but it possesses few bytes of info to form a bridge between user space application and device drivers running into kernel space.

          So for fdisk /dev/sda represents Virtual Hard Drive and it is going to work over it to allow partitioning.

          Use help when enter letter 'm', every command in fdisk is single letter followed by enter key.
          Use 'n' to create new partition, create 3 primary partitions with increasing size of

        2. 100M for boot

        3. 256M for swap

        4. Remaining space for root



        5. Use 'w' command to write partition table and 'q' to exit from it.
          This is what I have on my VM

          liveCD ~ # fdisk /dev/sda

          Command (m for help): p

          Disk /dev/sda: 8589 MB, 8589934592 bytes
          255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
          Units = sectors of 1 * 512 = 512 bytes
          Sector size (logical/physical): 512 bytes / 512 bytes
          I/O size (minimum/optimal): 512 bytes / 512 bytes
          Disk identifier: 0x3ba1b1df

          Device Boot Start End Blocks Id System
          /dev/sda1 2048 206847 102400 83 Linux
          /dev/sda2 206848 731135 262144 83 Linux
          /dev/sda3 731136 16777215 8023040 83 Linux


          format these partitions.


          liveCD ~ # mke2fs /dev/sda1
          livecd ~ # mkswap /dev/sda2 && swapon /dev/sda2
          liveCD ~ # mke2fs -j /dev/sda3


        6. Unpack stage over newly created partition table
          Mount the root filesystem first.

          liveCD ~ # mount /dev/sda3 /mnt/gentoo


          Need to copy stage3-i486-20110426.tar.bz2 From HostOS.

          So this can be done in using scp or nfs. Or use wget to download it directly.

          liveCD ~ # cd /mnt/gentoo
          liveCD ~ # wget http://ftp.romnet.org/gentoo/releases/x86/autobuilds/current-iso/stage3-i486-20110426.tar.bz2


          Unpack the stage

          liveCD ~ # tar xjpf stage3-i486-20110426.tar.bz2

          This will create root filesystem over /mnt/gentoo dir.

        7. chrooting into it

          liveCD ~ # cd /
          liveCD ~ # chroot /mnt/gentoo /bin/bash

          This will make /mnt/gentoo as '/' or root, files and directories other than /mnt/gentoo will go hidden.


        8. Adding more packages for better life on Gentoo
          TODO:!


        9. Compiling Linux Kernel 2.6.32
          Download the Linux source or scp it.

          liveCD ~ # cd /usr/src
          liveCD ~ # wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.9.tar.bz2
          liveCD ~ # tar xjf linux-2.6.32.9.tar.bz2


          Copy plain text from following link into /usr/src/linux-2.6.32.9/.config file
          .config for linux kernel compilation
          Make sure to keep UNIX line ending, if created file in windows text editor and then copied.

          Commands to compile

          liveCD ~ # cd linux-2.6.32.9
          liveCD ~ # make defconfig
          liveCD ~ # make bzImage modules modules_install


          We will copy compiled Linux kernel manually in boot folder.

          liveCD ~ # cp arch/x86/boot/bzImage /boot/bzImage-2.6.32.9


        10. Update configuration files and grub
          TODO:


        11. Install few pre-requesties
          TODO:

        12. Booting into Gentoo VM
          TODO:





    Contents here are composed for education purpose only.