Req. Ovftool command to overwrite memory size and CPU count described in ova file during deployment of VM - automation

I have a OVA file(MyOvafile.ova) which contain MemorySize=16GB and CPU count=4.
I have deployed the Ovftool on VMware ESXi server.
I am using the following command to deploy the VM:
/vmfs/volumes/DataStore1/vmware-ovftool/ovftool --memorySize:15360 --name=Test_VM -dm=thin -ds=DataStore1 /vmfs/volumes/DataStore1/OVA_V5.1_BSI-8/MyOvafile.ova
Now the problem i am facing:
As i am giving MemorySize of 15360MB but after deployment VM has the same values as defined in ova file (MyOvafile.ova i.e 16GB)
My Question:
How can i change the value of MemorySize and CPU count through ovftool command?

Apparently, this seems a bug in OVFTOOL (and documentation as well).
CPU and memory cannot be overridden by OVFTOOL's corresponding parameters.
However, there is hack by modifying it in VMX file of VM (and then using reconfigure command).
1) Get VMXfile Location (ending with .vmx) :
vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
72 Test_vm [datastore2] VM_name/VM_name.vmx rhel6_64Guest vmx-08
2) Modify vmx file (for example, using awk) for changing 'vCPUS=REQ_CPUs' entry.
3) Reconfigure .vmx file
vim-cmd vmsvc/reload <VM_ID>
Issue reported in VMware community: https://communities.vmware.com/message/2698710#2698710

Related

Boot QEMU KVM with libvirt/sVirt but without using virt-install tool in command line

Can anyone help me on how to boot QEMU KVM with libvirt/sVirt but without using virt-install tool in command line.
or using virsh tool
In order to use virt-install, you need to install the following:
yum install qemu-kvm qemu-img libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils tigervnc-server
Then, you can start the daemon:
systemctl start libvirtd
Now, download the OS you want to install, and then copy it to the folder shown below:
cp CentOS-7-x86_64-Everything-1708.iso /var/lib/libvirt/images/
Finally, run virt-install. Here is an example of what the script should look like:
os="--os-type=linux --os-
variant=centos7.0"
location="--location=/var/lib/libvirt/images/CentOS-7-x86_64-Everything-1708.iso"
cpu="--vcpus 2"
ram="--ram 2048"
name="centos7"
disk="--disk /dev/mapper/centos_192- root,size=40"
type="--virt-type qemu"
network="--network network=default"
graphics="--graphics none"
virt-install $os $network $disk $location $cpu $ram $type $disk $graphics --name=$name
After running virt-install, verify that the VM is running using virsh:
virsh list
Id Name State
----------------------------------------------------
4 centos7 running
Virt-install command-line options
Below are some command-line options, but this isn't an extensive list, so I encourage you to do some research in order to fully take advantage of this tool.
os="--os-type=linux --os-variant=centos7.0" --
Some of these commands have main options, as well as sub options. For example, if you type os-type=linux, then you need to further specify --os-variant=centos7.0. You can get a list of OSes that virt-install supports by typing osinfo-query os.
location="--location=/var/lib/libvirt/images/CentOS-7-x86_64-Everything-1708.iso"
This is where you've copied the ISO image file containing the OS you want to install.
cpu="--vcpus 2"
The CPU command-line option enables you to specify the number of vCPUs assigned to the VM. In this example, I'm assigning two vCPUs.
ram="--ram 2048"
The RAM command-line option enables you to specify the amount of memory assigned to the VM. In this example, I'm assigning 2,048 MBs -- or 2 GBs.
name="centos7"
The name command-line option enables you to assign a name to the VM. In this example, I'm naming the VM centos7.
disk="--disk /dev/mapper/centos_192-root,size=40"
This is where the VM will be installed and the size, in gigabytes, to be allocated. This must be a disk partition and not a mount point. Type df -h to list disk partitions.
type="--virt-type qemu"
The type command-line enables you to choose the type of VM you want to install. You can use KVM, QEMU, Xen or KQEMU. Type virsh capabilities to list all of the options. In this example, I'm using QEMU.
network="--network network=default"
Use network=default to set up bridge networking using the default bridge device. This is the easiest method, but there are other options.
graphics="--graphics none"
The graphics command-line option specifies that no graphical VNC or SPICE interface should be created. Use this for a kickstart installation or if you want to use a ttyS0 serial connection.

Why is fdisk -l showing different results for the same vdi virtual drive when different virtual machines are used in VirtualBox

VirtualBox (Version 5.2.24 r128163 (Qt5.6.2)) user with xubuntu guest (Ubuntu 18.04.2 LTS) and Windows 10 host here.
I recently tried to resize my vdi from ~100GB to 200GB. In windows I used the command:
./VBoxManage modifyhd "D:\xub2\xub2.vdi" --resize 200000
That went fine. Then I used a gparted live cd to create a vm, attached the vdi and resize the partitions:
gparted gui
All looks good. If I then use the 'fdisk -l' command whilst in the gparted vm the increased partition sizes are visible as expected.
fdisk -l results for vdi attached to gparted vm
If I try and resize the file system for one of the newly resized logical drives with 'resize2fs /dev/sda5' I am told it is already 46265856 blocks long and there is nothing to do.
However....
If I then re-attach this vdi to an ubuntu vm and boot up with the vdi, the 'fdisk -l' command gives different results and is basically telling me that the drive is still 100GB in size.
fdisk -l results for the same vdi attached to ubuntu vm
The 'df' command confirms that it is not resized.
df command output with same vdi attached to ubuntu vm
If I try the command 'resize2fs /dev/sda5' I get the result:
The filesystem is already 22003712 (4k) blocks long. Nothing to do!
How can I fix this and make the ubuntu vm see that the disk and partitions have been increase in size?
Ok. I will answer my own question (thank you for the negative vote anonymous internet).
This issue occurs when you have existing snapshots of the drive that you are trying to expand associated with a VirtualBox VM.
I found this described in VirtualBox's documentation.
https://forums.virtualbox.org/viewtopic.php?f=35&t=50661
One suggested solution is to delete the snapshots, however I got an error message when I attempted that.
The solution that worked for me was to clone my VM. The cloned VM (which did not have any snapshots associated with it), behaved as expected and showed the correct size for the resized disk.
To be clear: the situation I described above is 100% true.
Hope that helps someone.

Vmware Workstation - Cannot open disks xxxx or one of the snapshot disks it depends on

I'm running Centos7 using Vmware workstation on windows 7 laptop. All was well until I restarted my laptop this morning & my VM started complaining as below
The parent virtual disk has been modified since the child was created. The content ID of the parent virtual disk does not match the corresponding parent content ID in the child
Cannot open the disk 'C:\Users\<user>\Documents\Virtual Machines\CentOS 64-bit\CentOS 64-bit-000003.vmdk' or one of the snapshot disks it depends on.
Module 'Disk' power on failed.
Failed to start the virtual machine.
Below is the image of the folder containing the VM & the image of the VM itself.
I've looked through the vmware log & found the disk ID
2016-03-21T15:56:15.685+13:00| vmx| I125: DISKLIB-LINK : Opened 'C:\virtmac\CentOS 64-bit.vmdk' (0xe): monolithicSparse, 419430400 sectors / 200 GB.
2016-03-21T15:56:15.685+13:00| vmx| I125: DISKLIB-LINK : DiskLinkIsAttachPossible: Content ID mismatch (parentCID b0f614a0 != a0549cb5)
All you have to do is to delete the .lck file from the folder of your vmdk files.
It is generally present at
C:\Users\UserName\Documents\Virtual Machines\VMWareName
Also you can just move the lck files one folder up to ensure you do not delete any other file by mistake.
Deleting all .lck files in the folder should technically solve the problem.
If you use VMs such as Kali Linux, it might happen that the AV quarantines parts of the .vmdk files. In my case I had to restore it from the Windows Defender quarantined files see the screenshot attached
If you are using Kali in VM,
Go to the main directory (Configuration File).
Determine the missing file partition. Ex: kali-linux-2022.3-vmware-amd64-s003.vmdk
Copy any other partition and give it a name of a messing partition.
> copy kali-linux-2022.3-vmware-amd64-s004.vmdk kali-linux-2022.3-vmware-amd64-s003.vmdk
In case you face a Busybox Initramfs Error
type (initramfs) fsck /dev/sda1 -y

reboot VM (run on vbox) into specific (compiled) kernel from shell

Im running ubuntu 14.04 with vbox . In this machine I compiled and run kernel 3.14 which I choose from the grub menu when ubuntu load on vbox.
The host also run on ubuntu 14.04.
I wanted to ask - is there a way to load the guest ubuntu into specific kernel with a command on shell?
I can start running a vm on vbox trough command line with this command :
VBoxManage startvm ubuservloc --type headless
but its not quite exactly what I need.
I don't know of any way to directly communicate from the host to the guest's GRUB, but there are several indirect ways you could go:
mount the /boot filesystem from the host and drop a file there that is read by the guest's grub.cfg.
VBoxManage controlvm keyboardputscancode to type a hotkey which is assigned to the correct kernel in GRUB (shortly after starting the VM)
Configure GRUB to listen to a (virtual) serial port and select the kernel by writing to that file
In case a second reboot is acceptable (first boot into default kernel and then reboot into desired kernel) there are also several ways (you can use the grub-set-default command from guest to choose your desired kernel and issue a reboot). Some I can think of here:
VBoxManage guestcontrol run to call a shell script from host in the guest (after guest additions have been loaded)
VBoxManage guestproperty to set a property from host and VBoxControl guestproperty to read it from an init script and decide from there
Just SSH into the guest and reboot from there :D
Obviously, if you always want to boot that kernel, why not make it default? And in case always you want to alternately boot two different kernels, you can also set the default for next boot to another one direclty from grub.cfg.

VirtualBox: extend partition

I have virtualbox-4.1.0 with centos-5.6 installed in. Now I would like to extend the VM image, which I previously allocated for virtual machine installation, it was 8Gb, that's not enough now. Is there a way to extend the partition without loosing information?
Actually in centos I have one root fs with my home dir etc. so this partition eventually would need to be resized.
Thanks in advance for suggestions!
It can be done in 4 steps :
Clone your VMDK to VDI format with VBoxManage Tool.
Resize the disk to create free space with VBoxManage Tool.
Modify the filesystem to allocate free space for your drive with GParted.
Add created disk space to Linux FileSystem.
The detailed steps are below (tested with "Virtual Machine CentOS 6.4" and "VirtualBox 4.2.18");
Observe disk format of the virtualbox file, if it is not *.vdi, convert disk format from *.wmdk to *.vdi. Open windows terminal:
$ VBoxManage clonehd --format VDI "path_of_wmdk_file" "path_of_vdi_file"
Resize disk size of vdi file. Open windows terminal. For example to do disk size ~500 GB => 512000;
$ VBoxManage modifymedium "path_of_vdi_file" --resize 512000
Choose *.vdi file instead of *.wmdk file as disk
Virtual Machine -> Settings -> Storage -> Controller : SATA (Right Click on *.wmdk file) -> Remove Attachment -> Add HardDisk and choose newly created *.vdi file
Download "gparted-live-x.xx.x-x-ixxx.iso" file from http://gparted.sourceforge.net/download.php. Mount this iso file as CD.
Virtual Machine -> Settings -> Storage -> Controller IDE (Right Click) -> Add CD/DVD -> Select gparted-live-x.xx.x-x-ixxx.iso file
Run virtual machine, Virtual Machine will boot from this CD. Choose default values with pressing "Enter", "Enter" ... until Gpart ISO GUI starts. Select tool gpart program and start.
Extend disk size as below;
Right click on partitions and if "possible" click on "Disable Active Partion".
Extend Partition as much as possible from GUI (for this case 500GB).
Right click the partition which is disabled and select "Enable Active Partion".
Apply and wait until the operations finished.
Shut down virtual machine.
Unmount gparted-live-x.xx.x-x-ixxx.iso.
Virtual Machine -> Settings -> Storage-> Controller IDE (Right Click on gparted-live-x.xx.x-x-ixxx.iso) -> Remove Attachement
Start the virtual machine.
Open linux terminal and login as root. Run commands below;
lvm vgdisplay
=> Free PE / Size 122880 / 480.00 GiB
lvm lvdisplay /dev/VolGroup/lv_root
=> Current LE 3978
Calculate the sum of the values above. In this case : 122880 + 3978 = 126858 <- will be used in the next command
lvm lvresize -l 126858 /dev/VolGroup/lv_root
resize2fs /dev/VolGroup/lv_root
lsblk
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 500G 0 disk
+¦sda1 8:1 0 500M 0 part /boot
L¦sda2 8:2 0 499.5G 0 part
+¦VolGroup-lv_root (dm-0) 253:0 0 480G 0 lvm /
L¦VolGroup-lv_swap (dm-1) 253:1 0 4G 0 lvm [SWAP]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Check whether the filesystem extended or not with creating a huge file:
fallocate -l 480G /test_file
Remove the test file of course:
rm -rif /test_file
I'm using a CentOS7 virtualbox, and I finally enlarged my partition /dev/mapper/centos-root - gparted doesn't work for me because I do not have a desktop on CentOS7 virtualbox.
Power off your CentOS virtual machine
Go into the directory of your *.vdi image. If you don't know where it is, look at your Virtualbox Manager GUI virtualbox -> settings -> storage -> *.vdi -> location e.g. mine is located under ~/VirtualBox VMs/CentOS7/CentOS.vdi
Back up your image just in case anything goes wrong
$ cp CentOS7.vdi CentOS7.backup.vdi
Resize your virtual storage size, e.g. 200 GB
$ VBoxManage modifyhd CentOS7.vdi --resize 204800
Power on your CentOS virtual machine, issue
$ sudo fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 209715199 104344576 8e Linux LVM
Use fdisk utility to delete/create partitions
$ sudo fdisk /dev/sda
You are in the fdisk utility interactive mode, issue following commands: (mostly just follow the default recommendation)
d - delete a partition
2 - select a partition to delete (/dev/sda2 here)
n - create a new partition
p - make it a primary partition
2 - make it on the same partition number as we deleted
<return> - set the starting block (by default)
<return> - set end ending block (by default)
w - write the partition and leave the fdisk interactive mode
Reboot your CentOS machine
$ sudo reboot
Resize the physical volume and verify the new size
$ sudo pvresize /dev/sda2
$ sudo pvscan
Take a look at your logical mapping volume to see what volume you want to enlarge, in my case, /dev/mapper/centos-root
Resize the file system by adding -r option, it will take care of resizing for you
$lvextend -r -l +100%FREE /dev/mapper/centos-root
Resize the file system:
$resize2fs /dev/mapper/fedora-root
For CentOS 7: $xfs_growfs /dev/mapper/fedora-root
Last check:
$df -h.
Reference:https://blog.jyore.com/2013/06/virtualbox-increase-size-of-rhelfedoracentosscientificos-guest-file-system/#comment-2879
I found this nugget at the link following. I worked perfect for me and only took 5 seconds.
As of VirtualBox 4 they added support for expansion.
VBoxManage modifyhd filename.vdi --resize 46080
That will resize a virtual disk image to 45GB.
https://superuser.com/questions/172651/increasing-disk-space-on-virtualbox
It can be done with 3 steps :
cloning your VMDK to VDI format using VBoxManage
resize the disk to create free space using VBoxManage
modify the filesystem to allocate free space to your drive, using GParted
Don't forget the last part, otherwise, you will have unallocated free space and your disk will still appear as full.
I wrote a tutorial here to resize your VM Disk
At some point the VBoxManage utility changed the syntax a little bit. It's worth noting that this doesn't work on all vm types so beware if you have a *.vmdk. An example command to change your HD to 40GB is:
$ VBoxManage modifyhd MyVirtualImage --resize 40960
For reference I am on VirtualBox 4.2.1, Mac 10.8.2
From the VirtualBox FAQ:
You have to clone the data from the VDI you already have to a new, larger VDI and expand the partition(s). You can use tools like CloneZilla to clone the virtual hard drive to the bigger one and Gparted to increase the partition size. Another method is to use CloneVDI by mpack and clone the VDI with a larger size, then resize the partition(s) with Gparted.
Since 4.0.0, you can use VBoxManage modifyhd --resize to resize the max size of the VDI. You can only make it bigger. After that, use Gparted to increase the partition size inside the VDI.
Alternatively you could attach another VDI and mount your /home there.
Search for CloneVDI tool on the Oracle VirtualBox forums. It worked for me and is a much easier GUI based program for anyone nervous at the command line. Also allows conversion from fixed to dynamic mode which VBoxManage.exe doesn't support (yet).
https://forums.virtualbox.org/viewtopic.php?f=6&t=22422
I spent a long time googling and finally got it working for me. ( before I found this ) And I wanted a place to save my work
use vboxmanage to add space to the disk image
use gparted to resize so all space is used
use blivet-gui to create a new volume :
Below is commands I copied from terminal in fedora :
dnf install blivet-gui
blivet-gui
lvremove /dev/mapper/fedora00-00
lvextend -l +100%FREE /dev/mapper/fedora00-root