Add disks to KVM virtual machines

Source: Internet
Author: User

Background:

Due to the glusterfs test on the KVM Vm, it is found that the KVM virtual storage space is insufficient.

Idea: Create a kvm img file with a size of 200 GB and import it to the corresponding virtual machine through virtual machine manager.

Steps:

The following uses virtual machine VM2 as an example.

  1. Create KVM img

    [[Email protected] 2] cd/D1/virtual_machine/Vm/2 # enter the VM file directory

    [[E-mail protected] 2] # qemu-IMG create vm2-1.img 200g

    Formatting 'vm2-1. IMG ', FMT = raw size = 214748364800 # Created successfully

    [[Email protected] 2] # ls

    Vm2-1.img (vm2.img)

  2. Use vmm to import files

    Disable VM2 first

    650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/36/F8/wKiom1Or30WzbU5YAANYj1ubhWY599.jpg "Title =" 11.jpg" alt = "wkiom1or30wzbu5yaanyj1ubhwy599.jpg"/> Click Finish to add the disk

    650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/36/F7/wKioL1Or4BOj8oUeAAFVqI-Oq6E324.jpg "Title =" 2.jpg" alt = "wKioL1Or4BOj8oUeAAFVqI-Oq6E324.jpg"/>

    IDE disk2 is the new disk.

    Start VM2

  3. New disk formatting Partition

    [[Email protected] ~] # Fdisk-L # view system Disks


    Disk/dev/SDB: 214.7 GB, 214748364800 bytes --- New Disk

    255 heads, 63 sectors/track, 26108 Cylinders

    Units = cylinders of 16065*512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes/512 bytes

    I/O size (minimum/optimal): 512 bytes/512 bytes

    Disk identifier: 0x00000000

    ....

     

    [[Email protected] ~] # Fdisk/dev/SDB # Add Disk Partitions

    Device contains neither a valid DOS partition table, Nor Sun, SGI or OSF disklabel

    Building a new dos disklabel with disk identifier 0xc6997a54.

    Changes will remain in memory only, until you decide to write them.

    After that, of course, the previous content won't be recoverable.


    Warning: Invalid flag 0x0000 of Partition Table 4 will be corrected by W (RITE)


    Warning: DOS-compatible mode is deprecated. It's stronugly recommended

    Switch off the mode (command 'C') and change display units

    Sectors (command 'U ').


    Command (M for help): p # print the current disk Information


    Disk/dev/SDB: 214.7 GB, 214748364800 bytes

    255 heads, 63 sectors/track, 26108 Cylinders

    Units = cylinders of 16065*512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes/512 bytes

    I/O size (minimum/optimal): 512 bytes/512 bytes

    Disk identifier: 0xc6997a54


    Device boot start end blocks ID system



    Command (M for help): N # Add a partition

    Command action

    E extended

    P primary partition (1-4)

    P # usually select the primary partition, so here is a p

    Partition Number (1-4): 1 # select 1 because it is the first score.

    First cylinder (1-26108, default 1): 26100G # Fill in the partition size 200g

    Last cylinder, + cylinders or + size {K, M, g} (26100-26108, default 26108 ):

    Using default value 26108


    Command (M for help): W # Write the partition to the hard disk

    The partition table has been altered!


    Calling IOCTL () to re-read partition table.

    Syncing disks.


  4. Format partitions


    [[Email protected] ~] # Mkfs. ext4/dev/SDB

    Mke2fs 1.41.12 (17-may-2010)

    /Dev/SDB is entire device, not just one partition!

    Proceed anyway? (Y, n) y

    Filesystem label =

    OS type: Linux

    Block size = 4096 (log = 2)

    Fragment size = 4096 (log = 2)

    Stride = 0 blocks, stripe width = 0 blocks

    13107200 inodes, 52428800 Blocks

    2621440 blocks (5.00%) reserved for the Super User

    First data block = 0

    Maximum filesystem blocks = 4294967296

    1600 block groups

    32768 blocks per group, 32768 fragments per group

    8192 inodes per group

    Superblock backups stored on blocks:

    32768,983 04, 163840,229 376, 294912,819 200, 884736,160 5632, 2654208,

    4096000,796 2624, 11239424,204 23887872


    Writing inode tables: Done

    Creating Journal (32768 blocks): Done

    Writing superblocks and filesystem accounting information: Done


    This filesystem will be automatically checked every 34 mounts or

    180 days, whichever comes first. Use tune2fs-C or-I to override.

  5. Create a directory Mount Partition

    Mkdir/d1


    [[Email protected] ~] # Mount/dev/sdb/d1

    [[Email protected] ~] # DF-H

    Filesystem size used avail use % mounted on

    /Dev/mapper/vg_livedvd-lv_root

    20 GB 5.2g 15g 27%/

    Tmpfs 3.9g 0 3.9g 0%/dev/SHM

    /Dev/sda1 485 m 37 m 423 M 8%/boot

    /Dev/SDB 197g 188 m 187g 1%/d1

Finished

Supplement:

Automatically mount/dev/SDB upon startup

/Etc/fstab adds the following content:

/Dev/sdb/d1 ext4 defaults 1 1

Restart the system

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.