KVM虚拟机磁盘扩容

创建磁盘

dd if=/dev/zero of=kubernetes-207_home_10G.img bs=1 count=1 seek=10G;

磁盘分区

[root@host-machine file]# fdisk kubernetes-207_home_10G.img

#创建一个新的分区
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended

#选择主分区
Select (default p): p

#主分区1
Partition number (1-4, default 1): 1

#第一扇区从xxx开始
First sector (2048-20971519, default 2048):
Using default value 2048

#最后扇区到xxx结束
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

#打印
Command (m for help): p

Disk kubernetes-207_home_10G.img: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x2b72a5ce

                      Device Boot      Start         End      Blocks   Id  System
kubernetes-207_home_10G.img1            2048    20971519    10484736   83  Linux

Command (m for help): w
The partition table has been altered!

Syncing disks.
KVM虚拟机磁盘扩容

磁盘格式化

[root@host-machine file]# mkfs.ext4 kubernetes-207_home_10G.img
mke2fs 1.42.9 (28-Dec-2013)
kubernetes-207_home_10G.img is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

磁盘挂载

virsh edit kubernetes-207
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/kubernetes-207_home_10G.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
#编辑是删除address行,此行是自动生成的,如果不删除,会报错。
mount /dev/vda /tmp/home/
上一篇:【论文】MCB


下一篇:Add project to working sets