Skip to main content

Adding HDD to KVM/Virtual Machine.

Adding HDD to Virtual Machine.

Steps to create virtio HDD.
  1. First Create a image using qemu-img command.
  2. Add image to VM as a virtio HDD.
  3. This will appear as /dev/vda in the VM, format it using the mke2fs command.
  4. Add to /etc/fstab, so that the device can be mounted on boot up.
Details below.

First Create a image using qemu-img command.

Below is the command to create image.
[ahmed@ahmed-server ~]# qemu-img create VM-1-NEW-HDD.img 100G
This will create a HDD with 100GB disk.

Add image to VM as a virtio HDD.

Method 1 - Adding image from virt-manager UI.

Steps to Adding from the UI.
  1. Select a VM, right-click -> open.
  2. Next on the screen select view -> details.
  3. In the new window select Add Hardware -> Storage -> select managed or other existing storage.
    • Select Device Type : virtio
    • Select Storage Format : raw
'Adding New HDD'
After Adding the HDD we can see it as below.
'After Adding HDD'

Method 2 - Adding image using virsh command.

To edit the VM configuration use below command.
[ahmed@ahmed-server ~]# virsh edit VM-1
Format
virsh edit 
To add the image to the server add the below xml tag.
<disk type='file' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source file='/virtual_machines/images/VM-1-ADD.img'/>
  <target dev='vda' bus='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
Now reboot the VM, after restart you will see the new device.
[ahmed@ahmed-server ~]# fdisk -l
'fdisk output'

Added image will appear as /dev/vda in the VM, format it using the mke2fs command.

Before we mount the device we need to format the device.
[ahmed@ahmed-server ~]# mke2fs -j /dev/vda
This will format the device.

Add to /etc/fstab, so that the device can be mounted on boot up.

# /etc/fstab 
# 
# Column Details here : http://man7.org/linux/man-pages/man5/fstab.5.html          
# ------------------------------------------------------------------
/dev/vda            /data            ext3        defaults    0 0
Now we can check by mounting.
[ahmed@ahmed-server ~]# mount -a 
Check by running below command.
[ahmed@ahmed-server ~]# df -h
'DF OUTPUT'

Useful Links.

http://xmodulo.com/install-configure-kvm-centos.html
http://www.cyberciti.biz/faq/kvm-virtualization-in-redhat-centos-scientific-linux-6/
https://www.howtoforge.com/vnc-server-installation-centos-6.5
http://wiki.centos.org/HowTos/KVM
https://www.howtoforge.com/virtualization-with-kvm-on-a-centos-6.4-server-p4
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/sect-Virtualization-Virtualized_block_devices-Adding_storage_devices_to_guests.html
http://unix.stackexchange.com/questions/92967/how-to-add-extra-disks-on-kvm-based-vm
http://www.techotopia.com/index.php/Adding_a_New_Disk_Drive_to_a_CentOS_6_System
http://blog.zwiegnet.com/linux-server/add-new-hard-drive-to-centos-linux/
http://man7.org/linux/man-pages/man5/fstab.5.html
​

Comments

Post a Comment

Popular posts from this blog

Installing Zabbix Version 2.4 Offline (Zabbix Server without Internet).

There might be situations where you have a remote/zabbix server which does not have internet connectivity, due to security or other reasons. So we create a custom repo on the remote/zabbix server so that we can install zabbix using rpms Here is how we are planning to do this. Download all the dependency rpms on a machine which has internet connection, using yum-downloadonly or repotrack . Transfer all the rpms to the remote server. Create a repo on the remote server. Update yum configuration. Install. NOTE: This method can be used to install any application, but here we have used zabbix as we had this requirement for a zabbix server. Download dependent rpms . On a machine which has internet connection install the package below. And download all the rpms . Make sure the system are similar (not required to be identical - At-least the OS should be of same version) mkdir /zabbix_rpms yum install yum-downloadonly Downloading all the rpms to location /zabbix_rpms/ ,...

Access Filter in SSSD `ldap_access_filter` [SSSD Access denied / Permission denied ]

Access Filter Setup with SSSD ldap_access_filter (string) If using access_provider = ldap , this option is mandatory. It specifies an LDAP search filter criteria that must be met for the user to be granted access on this host. If access_provider = ldap and this option is not set, it will result in all users being denied access. Use access_provider = allow to change this default behaviour. Example: access_provider = ldap ldap_access_filter = memberOf=cn=allowed_user_groups,ou=Groups,dc=example,dc=com Prerequisites yum install sssd Single LDAP Group Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = memberOf=cn=Group Name,ou=Groups,dc=example,dc=com Multiple LDAP Groups Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = (|(memberOf=cn=System Adminstrators,ou=Groups,dc=example,dc=com)(memberOf=cn=Database Users,ou=Groups,dc=example,dc=com)) ldap_access_filter accepts standa...

Setting up ssl https On Nagios XI Server

HTTPS is a protocol for secure communication over a computer network which is widely used on the Internet. HTTPS consists of communication over Hypertext Transfer Protocol (HTTP) within a connection encrypted by Transport Layer Security or its predecessor, Secure Sockets Layer. The main motivation for HTTPS is authentication of the visited website and protection of the privacy and integrity of the exchanged data. Intro Courtesy Wikipedia Full SSL support requires Nagios XI version 2011R1.6 or later. Before we start. Check if the below packages are install, they should be if you are using latest Nagios XI, but check them anyways. yum install mod_ssl openssl Creating Key and Certificate Lets generate the key for the server. openssl genrsa -out ca.key 2048 Output for the command. [ahmed@nagiosserver ~]$ openssl genrsa -out ca.key 2048 Generating RSA private key, 2048 bit long modulus ...........................................................................................