How to add a hard disk to a Linux virtual machine in KVM

Source: Internet
Author: User

[[email protected] ~]# df-htfilesystem Type Size used Avail use% mounted On/dev/mapper/volgroup-lv_root            Ext4 8.3G 937M 7.0G 12%/tmpfs tmpfs 119M 0 119M 0%/dev/shm/dev/vda1 Ext4 477M 33M 419M 8%/boot[[email protected] ~]# generate a new hard drive [[email protected] virhost]# qemu-img C Reate-f Raw O5cache.add.disk.raw 2GFormatting ' 05cache.add.disk.raw ', Fmt=raw size=2147483648 <disk type= ' file ' Devi Ce= ' disk ' > <driver name= ' qemu ' type= ' raw ' cache= ' None '/> <source file= '/home/virhost/05cache.add.dis  K.raw '/> <target dev= ' vda ' bus= ' virtio '/> <address type= ' pci ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x07 ' function= ' 0x0 '/> </disk>[[email protected] virhost]# virsh start 05cacheDomain 05cache started[[email&n Bsp;protected] virhost]# virsh attach-disk 05cache/home/virhost/05cache.add.disk.raw vdb--cache NoneDisk attached Successfullyvirsh Edit 05cache----------------><disk type= ' file ' device= ' disk ' > <driver name= ' qemu ' type= ' raw ' cache= ' None '/> &lt ; source file= '/home/virhost/05cache.img '/> <target dev= ' vda ' bus= ' virtio '/> <address type= ' PCI ' DOMA in= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x05 ' function= ' 0x0 '/> </disk> <disk type= ' block ' device= ' cdrom ' > & Lt;driver name= ' qemu ' type= ' raw '/> <target dev= ' hdc ' bus= ' IDE '/> <readonly/> <address typ E= ' drive ' controller= ' 0 ' bus= ' 1 ' target= ' 0 ' unit= ' 0 '/> </disk>[[email protected] ~]# FDISK-LDISK/DEV/VD a:10.7 GB, 10737418240 bytes16 heads, $ sectors/track, 20805 cylindersunits = cylinders of 1008 * = 516096 Bytessect or size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk identifier:0x000c1 Fb8 Device Boot Start End Blocks Id system/dev/vda1 * 3 1018 512000 L Inuxpartition 1 does not End on cylinder boundary./dev/vda2 1018 20806 9972736 8e Linux lvmpartition 2 does no end on Cyl Inder boundary.  disk/dev/vdb:2147 MB, 2147483648 bytes #挂上的新的硬盘16 heads, sectors/track, 4161 cylindersunits = cylinders of 1008 * 512 = 516096 bytessector Size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk identifier:0x00000000disk/dev/mapper/volgroup-lv_root:9168 MB, 9168748544 bytes255 heads, sectors/track, 1114 Cylin Dersunits = Cylinders of 16065 * 8225280 bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum  /optimal): bytes/512 bytesdisk identifier:0x00000000disk/dev/mapper/volgroup-lv_swap:1040 MB, 1040187392 bytes255  Heads, Sectors/track, 126 cylindersunits = cylinders of 16065 * = 8225280 bytessector size (logical/physical): 512 bytes/512 bytesi/o Size (minimum/optimal): bytes/512 bytesdisk identifier:0x00000000

To format a hard disk in a virtual machine

[Email protected] ~]# mkfs.ext4/dev/vdbmke2fs 1.41.12 (17-may-2010) Filesystem label=os type:linuxblock size=4096 (log= 2) Fragment size=4096 (log=2) stride=0 blocks, Stripe width=0 blocks131072 inodes, 524288 blocks26214 blocks (5.00%) reserve D for the Super Userfirst data block=0maximum filesystem blocks=53687091216 block groups32768 blocks per group, 32768 Frag  ments per group8192 inodes per groupsuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912Writing inode  Tables:done                            Creating Journal (16384 blocks): donewriting superblocks and filesystem accounting information:donethis FileSystem'll is automatically checked every mounts or180 days, whichever comes first.  Use Tune2fs-c or-i to override.

Next, build a directory to mount the new hard disk:

[[email protected] ~]# mkdir/nd[[email protected] ~]# mkdir/nd[[email protected] ~]# mount/dev/vdb/nd/# get the Uuid[[emai of the hard drive L protected] ~]# Blkid/dev/vdb
/dev/vdb:uuid= "A35e0890-3aa6-47a7-921c-c2cb9dd431e6" type= "Ext4"

To add a mount to the boot boot:

[[email protected] ~]# Cat/etc/fstab # #/etc/fstab# Created by Anaconda on Tue June to 08:57:38 2016## Accessible filesyst EMS, by reference, is maintained under '/dev/disk ' # See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) For more Info#/dev/mapper/volgroup-lv_root/                       ext4    defaults        1 1uuid=04e8e77f-2604-4683-833b-a06a7300c7a3/boot                   ext4    defaults        1 2/dev/mapper/volgroup-lv_swap swap                    swap    defaults        0 0TMPFS                   /dev/shm                tmpfs   defaults        0 0devpts                  /dev/pts                devpts  gid=5,mode=620  0 0sysfs                   /sys                    Sysfs   defaults        0 0proc                    /proc                   proc    defaults        0 0uuid= A35e0890-3aa6-47a7-921c-c2cb9dd431e6/nd  ext4     Defaults        

[Email protected] ~]# df-hfilesystem            Size  used Avail use% mounted on/dev/mapper/volgroup-lv_root                      8.3G  644M  7.3G   9%/tmpfs                 119M     0  119M   0%/dev/shm/dev/vda1             477M   33M  419M   8%/boot/dev/vdb              2.0G  3.0M  1.9G   1%/nd

How to add a hard disk to a Linux virtual machine in KVM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.