Code Snippet

Just another Code Snippet site

[Vagrant] How-To

Set Vagrant name :

Vagrant.configure('2') do |config|
  config.vm.define "foohost" do |foohost|
  end
end

Set VirtualBox name :

Vagrant.configure('2') do |config|
  config.vm.provider :virtualbox do |vb|
      vb.name = "foohost"
  end
end

Shared Folder :

config.vm.synced_folder "C:\\Windows\\Path\\", "/Vagrant/Target/Path"

Customize Virtual Box params :

  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
      vb.gui = false
      vb.name = "VM-1"
  #   # Customize the amount of memory on the VM:
     vb.memory = "2048"
  end

Network :

Define default bridge networl

config.vm.network "public_network", bridge: "Intel(R) 82579LM Gigabit Network Connection"
config.vm.network "public_network", bridge: [
  "Intel(R) 82579LM Gigabit Network Connection",
  "Intel(R) Centrino(R) Advanced-N 6205 #2",
]


4 thoughts on “[Vagrant] How-To

  • Olivier says:

    Since atlas.hashicorp.com is down, Vagrant file must be updated with the following line to download box from vagrantcloud.com :

    Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
    Vagrant.configure("2") do |config|
    ...
    
  • Olivier says:

    Resize disk (as root not vagrant sudo) :

    # find process currently using /home
    fuser -m /home
    
    # kill processes (if any)
    kill-9 XX
    
    # unmount /home
    umount /home
    
    # Resize "/dev/mapper/VolGroup-lv_home" from 30Go to 5Go
    fsck -f /dev/mapper/VolGroup-lv_home
    lvresize -r -L1G /dev/mapper/VolGroup-lv_home
    
    # Add 25Go to Resize "/dev/mapper/VolGroup-lv_root"
    lvresize -r -L+29G /dev/mapper/VolGroup-lv_root
    
    

    for centos, fuser is part of “psmisc” package

    for Centos/RHEL >= 7

    # find process currently using /home
    fuser -m /home
    
    # kill processes (if any)
    kill-9 XX
    
    #Backup folder
    xfsdump -f /tmp/home.dmp /home
    
    # unmount 
    umount /home
    
    # remove LV
    lvremove /dev/mapper/centos-home
    
    # recreate LV
    lvcreate -l 800 -n home centos
    
    # Format LV (XFS)
    mkfs.xfs /dev/mapper/centos-home
    
    # remount
    mount -a
    
    # restore backup
    xfsrestore -f /tmp/home.dmp /home
    
    # extend main LV to take 100%
    lvextend -l +100%FREE /dev/mapper/centos-root
    
    # Grow FS
    xfs_growfs /dev/mapper/centos-root
    
    # check result
    df -h
    

    https://blog.dbi-services.com/how-to-reduce-the-size-a-lvm-partition-formatted-with-xfs-filesystem-on-centos7/

  • Olivier says:

    Virtualbox CPU customization :

      config.vm.provider "virtualbox" do |vb|
        # Display the VirtualBox GUI when booting the machine
        vb.gui = false
        vb.name = "My New VM"
        #  # Customize the amount of memory on the VM:
        vb.memory = "20480"
        vb.cpus = 2
        # set video memory to 12M to avoid a VB warning message
        vb.customize ["modifyvm", :id, "--vram", "12"]
        vb.customize ["modifyvm", :id, "--cpuexecutioncap", "75"]
      end
    
  • Olivier says:

    resize disk space:
    Vagrant file :

    unless Vagrant.has_plugin?("vagrant-disksize")
        system("vagrant plugin install vagrant-disksize")
    end
    ...
    Vagrant.configure("2") do |config|
    ...
      config.disksize.size = "100GB"
    ...
    end
    

    Using vagrant ssh :

    sudo su -
    fdisk /dev/sda
    p
    n
    p
    3
    ENTER
    ENTER
    t
    3
    8e
    w
    reboot
    

    and

    sudo su -
    pvcreate /dev/sda3
    vgdisplay
    vgextend VolGroupOS /dev/sda3
    lvextend -l +100%FREE /dev/mapper/VolGroupOS-lv_root
    xfs_growfs /dev/mapper/VolGroupOS-lv_root
    df -h
    

    see https://gist.github.com/Gcaufy/2212eba360ca6a2f92cf
    and https://stackoverflow.com/a/26320277

    https://superuser.com/questions/332252/how-to-create-and-format-a-partition-using-a-bash-script

Leave a Reply to Olivier Cancel reply

Your email address will not be published. Required fields are marked *