LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-08-2017, 06:00 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
Attaching and detaching disk from virtual machine in kvm


Attaching and detaching disk from virtual machine (vm) in kvm


Code:
#Create file for virtual machine (vm) disk
~ # mkdir -p  /vm-images
~ # dd if=/dev/zero of=/vm-images/vm1-add.img bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 2.20875 s, 486 MB/s

#Add file to centos7-1024ram-minimal-clone.xml
virsh attach-disk centos7-1024ram-minimal-clone /vm-images/vm1-add.img vdb --config                          
Disk attached successfully

#less /etc/libvirt/qemu/centos7-1024ram-minimal-clone.xml
… … 
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/centos7-1024ram-minimal-clone.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/vm-images/vm1-add.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    … … 
…. …. 


# Reboot VM then login and see:
[root@Centos7-1024ram-minimal-clone ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1 1024M  0 rom  
vda             252:0    0   14G  0 disk 
├─vda1          252:1    0  500M  0 part /boot
└─vda2          252:2    0   11G  0 part 
  ├─centos-root 253:0    0   10G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
vdb             252:16   0    1G  0 disk            #WORKS!

#exit ssh here.

#Detaching the file disk does not work
# virsh detach-disk centos7-1024ram-minimal-clone /dev/vdb --config                                            
error: No disk found whose source path or target is /dev/vdb

# virsh detach-disk centos7-1024ram-minimal-clone vdb --config                                            
error: No disk found whose source path or target is vdb
What did I missed?
Thank you.
 
Old 03-11-2017, 03:43 PM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Try this...

Code:
virsh detach-disk centos7-1024ram-minimal-clone /vm-images/vm1-add.img vdb --config
It looks like you're using the subjective path (the path the VM guest sees) instead of the objective path (the path the VM host sees) when using virsh you're always talking to libvirt on the host, not libvirt on the guest.
 
Old 03-11-2017, 05:13 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dijetlo View Post
Try this...

Code:
virsh detach-disk centos7-1024ram-minimal-clone /vm-images/vm1-add.img vdb --config
It looks like you're using the subjective path (the path the VM guest sees) instead of the objective path (the path the VM host sees) when using virsh you're always talking to libvirt on the host, not libvirt on the guest.
Thank you.

Code:
$ virsh detach-disk centos7-1024ram-minimal-clone vdb --live --config                                 
Disk detached successfully
 
Old 03-11-2017, 11:01 PM   #4
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
Thank you.
Any time, Fanofig.
I've been wanting to learn more about Ovirt and the new KVM platform for a while now, your question gave me impetus to dig back into it, not to mention puzzling out a virsh command string which is always a special kind of fun (as in not really but it's worth practicing anyway)...

Last edited by dijetlo; 03-11-2017 at 11:02 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel-based Virtual Machine (KVM): Switching from KVM guest to host (e.g. Linux Mint) & maximize guest screen fanoflq Linux - Newbie 2 07-13-2016 07:10 PM
connecting to kvm virtual machine sanaz Linux - Virtualization and Cloud 1 10-06-2012 11:02 AM
CPU usage is high by KVM virtual machine leechaotang Linux - Kernel 1 11-30-2011 03:22 PM
How to detaching and re-attaching to background processes? logme64 Programming 3 10-20-2011 03:33 PM
KVM Virtual Machine CD CHANGE ashishverma1984 Fedora 2 12-12-2008 03:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration