Skip to content
November 30, 2014 / windperson

Create CentOS v6.5 Vagrant Box of Parallels Desktop

Prerequisite

Create & Prepare the base CentOS VM

  1. Create & install CentOS VM just follow Parallels Desktop Wizard, be sure to install Parallels Tools inside VM as official guide mentions.
  2. Use following command to enable networking if network is not available:
    ifup etho0
    

    Install openssh-client & curl:

    sudo yum install -y openssh-clients curl
    
  3. Modify
    /etc/sysconfig/network-scripts/ifcfg-eth0 network config file, let it content as following:

    DEVICE=eth0
    TYPE=Ethernet
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=dhcp
    
  4. Make sure ssh server is enabled on boot by:
    sudo chkconfig sshd on
    
  5. Create a “vagrant” user:
    useradd vagrant
    

    Add .ssh folder and set its permission:

    mkdir -m 0700 -p /home/vagrant/.ssh
    

    Download vagrant default ssh private key file from official source:

    curl https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub >> /home/vagrant/.ssh/authorized_keys
    

    Set precise premission of default ssh private key file authorised_keys:

    chmod 600 /home/vagrant/.ssh/authorized_keys
    

    Set correct owner of .ssh folder:

    chown -R vagrant:vagrant /home/vagrant/.ssh
    
  6. Modify /etc/sudoers file by these two commands:
    sudo sed -i 's/^\(Defaults.*requiretty\)/#\1/' /etc/sudoers
    sudo bash -c 'echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers'
    
  7. Clear yum cache to reduce resulting box file size:
    sudo yum clean all 
    
  8. Remove CentOS network config rule file so the new vm create from box can add network card via VagrantFile:
    sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
    
  9. Remove files in /tmp & /var/log to reduce resulting box file size:
    sudo rm -rf /tmp/*
    sudo rm -rf /var/log/*
    
  10. Clear command line history record:
    history -c 
    
  11. Shutdown vm:
    sudo shutdown -h now
    

Create Vagrant box format package file

  1. Remove all snapshot of that vm in Parallels Desktop configuration UI.
  2. Open Terminal window, change current directory to the vm file location:
    cd ~/Documents/Parallels/CentOS6.5-base.pvm/
    

    I use “CentOS6.5-base” as the created VM name in Parallels Desktop in this example.

  3. Use following command to defrage disk files of VM:
    prl_disk_tool compact -i --hdd ./CentOS6.5-base-0.hdd
    
  4. Remove all .log file to reduce box file size:
    rm -rf *.log
    
  5. Move up to parent folder, create a text file called “metadata.json” in this folder with content as following:
    {
        "provider": "parallels"
    }
    
  6. Create the box file with this command:
    tar cvzf CentOS-6.5-parallals.box CentOS\ 6.5-base.pvm metadata.json
    

Import Just Created Local Box

Import just created box file into local vagrant box repository via following command:

vagrant box add parallel_centos65 ./CentOS-6.5-parallals.box
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: