Changing Disk Size of VM before VM installation using qemu kvm - virtual-machine

VM Disk Information
I wanted to change Disk Size upto 20G before vm Installation. The image already has Virtual size of 50G.

First, You should consider trying to compress the disk size.
sudo qemu-img -O qcow2 vmf5.img vmf5-compact.qcow2
If you really need those disk spaces, what you need to do:
sudo qemu-img resize /var/lib/libvirt/images/vmf5.img 20G
There is a document about qemu-img

Related

Ubuntu Server Backup and Restore via tar

I'm trying to learn how to backup and restore my Ubuntu Server via tar so I know that I have a safe system. After I untar and reboot, I have several issues, but they seem to be caused by a read-only file system. The source and destination server are both Ubuntu Server on the same version, 18.04.05 LTS. The source server is a VPS that has 6 GB RAM and 4vCPUs. The destination server is a VM on my FreeNAS machine with 6GB RAM and 2 vCPUs.
The primary applications that need to work are my Graylog server and Nagios server. I've mostly followed the instructions at Ubuntu.
First, my tar command is:
sudo tar -c --use-compress-program=pigz -f backup.tar.gz --exclude=/backup.tar.gz --exclude=/dev --exclude=/usr --exclude=/sbin --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/run --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/home/*/.cache --exclude=/home/*/.gvfs --exclude=/home/*/.local/share/Trash --exclude=/var/log --exclude=/var/cache/apt/archives --exclude=/usr/src/linux-headers* --one-file-system /
I use pigz to utilize the VPS's 4 vCPUs to take less time. I transfer this to my VM which as a fresh copy of Ubuntu Server 18.04.05 and untar with:
sudo tar -xvpzf backup.tar.gz -C / --numeric-owner
After I reboot, I get the following as soon as I boot:
Unable to setup logging. [Errno 30] Read-only file system: '/var/log/landscape/sysinfo.log'
run-parts: /etc/update-motd.d/50-lanscape-sysinfo exited with return code 1
mktemp: failed to create file via template '/var/lib/update-notifier/tmp.XXXXXXXXXX': Read-only file system
run-parts: /etc/update-motd.d/95-hwe-eol exited with return code 1
/usr/lib/update-notifier/update-motd-fsck-at-reboot: 33: /usr/lib/update-motd-fsck-at-reboot: cannot create /var/lib/update-notifier/fsck-at-reboot: Read-only file system
I do see that some areas of the system do work like the original source. My SSH port changes, hostname changes, etc. But I get these above errors and my Graylog and Nagios servers do not work.
So I'm wondering where I went wrong in my process and any help would be appreciated. The source is a live server with backups so I'm safe there. I'm just making sure I have my ducks in a row for the future.

Redis don't start

I have redis server 3.0.6 and ubuntu 16.04.
my config file
tcp-keepalive 60
#bind 127.0.0.1
requirepass qwerty
maxmemory-policy noeviction
appendonly yes
appendfilename redis-test.aof
and redis server don't run
Can't open the append-only file: Read-only file system
The error message is pretty clear: The file system on which redis-test.aof resides is mounted as read-only. The whole purpose of this file is to write changes to disk. So the disk must be writable.
Check if you used the ro option while mounting the drive. Run
$ mount
to list all the mountpoints. Check the one on which you want your aof file to reside.
To remount the disk as read-write, use the following command:
$ sudo mount -o remount,rw /partition/identifier /mount/point
If that doesn't help, see the system logs if there are any file system errors. To correct these, you will need to run fsck.

Convert qcow2 to vmdk and make it ESXi 6.0 Compatible

I am currently working on VMWare virtualization; I am trying to make a converted image from qcow2 to vmdk work with ESXi Server 6.0.
I have myImage.qcow2 with a disk which is thin provisioned for 300GB.
I used the image converter tool qemu with the following command
qemu-img convert -f qcow2 myImage.qcow2 -O vmdk myNewImage.vmdk
This command gives me a vmdk image which is only VMWare Workstation compatible. Therefore, in order to make it ESXi compatible I have to use the vmkfstools with the following command.
vmkfstools -i myImage.vmdk outputName.vmdk -d thin
The vmkfstools command gives me two files, an metadata.vmdk and the actual data.vmdk.
As mentioned above my disk is thin provisioned for 300GB and when I apply vmkfstools it expands the disk and gives me a size of 300GB.
Deploying the image through the vSphere Client works without any problem; however, for the purpose of this project I want to use the ovftool and doing so with such a large image is not feasible.
Is there a way for me to make my .vmdk ESXi compatible without vmkfstools expanding my image to 300GB?
Or Is there any other method for me to deploy those 300GB using the ovftool while the disk image is on the datastore, so that it doesn't have to be downloaded/uploaded through the deployment process?
I have been stuck on this for weeks and any help will be highly appreciated.
FYI: This support has been added in Qemu 2.1 and above as per changelogs
qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 SC-1.qcow2 SC-1.vmdk
This worked for me with VMware 6.7
The TL;DR is
qemu-img convert -f qcow2 -O vmdk -o subformat=streamOptimized source_qcow_image_path destination_path_to_vmdk
For example:
qemu-img convert -f qcow2 -O vmdk -o subformat=streamOptimized \
CentOS-7-x86_64-GenericCloud-1503.qcow2 \
CentOS-7-x86_64-GenericCloud-1503.vmdk
Update the vmdk version setting embedded in the converted image using this script:
* This is what actually worked for me *
printf '\x03' | dd conv=notrunc of=<vmdk file name> bs=1 seek=$((0x4))
For example:
printf '\x03' | dd conv=notrunc of=CentOS-7-x86_64-GenericCloud-1503.vmdk bs=1 seek=$((0x4))
source: https://kb.vmware.com/s/article/2144687

How do I check if an USB drive is bootable?

I just created an USB drive and would like to check if it's correctly bootable without rebooting my actual computer. How should I do?
Under Linux, you have to know which device path got the drive with for example with dmesg | tail after insertion, let's assume it's /dev/sdb.
Qemu
sudo qemu -hda /dev/sdb or sudo qemu-system-x86_64 -hda /dev/sdb for 64 bits.
VirtualBox
VBoxManage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/sdb
sudo chmod 666 /dev/sdb*
then add ~/usb.vmdk as a disk in a VM and boot on it
Don't hesitate to add other ways to do.
While it won't show if the stuff on the filesystem is capable of handling the whole boot thing you can check the boot flag with fdisk -l <drive> from a shell on a reasonably good *nix. (Which essentially tells the bios if it should try to boot the thingie or not.)

Changing password of a Virtual Machine

I have some virtual machines with me. I want to write a script which automates the following process...
It mounts the virtual machine (with linux as the os) to a location say /mnt/image
It modifies the /etc/passwd (or the equivalent file) to change the password of the user
Unmount the virtual machine
Since, I am using libvirt I am having some qcow2 images of the virtual machine. to mount the image on my ubuntu, I am using nbd module. Here are the commands that I am trying :
modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 image.qcow2
mount /dev/nbd0p1 /mnt/image
It gives me the error:
mount: special device /dev/nbd0p1 does not exist
When I replace nbd0p1 with nbdo I am getting the following error (though I am not sure what I am trying to do by this)
mount: you must specify the filesystem type
Any suggestions so as what could be the problem... ?
Check that /sys/modules/nbd/parameters/max_part has the expected value. If it's 0 or too low, the partitions /dev/nbd0p1, etc. will not be made available by the kernel. This can happen if the nbd kernel module was already loaded (with a different max_part parameter) when you ran modprobe.
You can fix that by unloading the module and modprobing it again.
[Not a direct answer to the question, but an alternate]
You can try to convert qcow2 image to raw and then, mount the raw image.
convert:
qemu-img convert -f qcow2 image.qcow2 -O raw image_raw.raw
mount:
sudo losetup /dev/loop0 image_raw.raw
sudo kpartx -a /dev/loop0
sudo mount /dev/mapper/loop0p3 /mnt/image
sudo mount /dev/mapper/loop0p2 /mnt/image/boot
Could it be that the partition isn't in the first slot in the MBR, or an extended partition is in use? Check to see if any other nbdXpY device nodes are being created, or run fdisk on it and print the partition table.
I stumbled on the same issue and same error but on a vdi
qemu-nbd -c /dev/nbd0 image.vdi
for me the solution was simple I just changed nbd0 to nbd1
qemu-nbd -c /dev/nbd1 image.vdi
and then:
sudo mount /dev/nbd1p1 /media/eddie/virtual
worked.
Please leave a comment if this worked for you also and on what type of image.