step1:创建一个qcow2格式的磁盘镜像
[root@kvm ~]# qemu-img create -f qcow2 /kvm/centos1_1.qcow2 5G
Formatting '/kvm/centos1_1.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536
[root@kvm ~]# virsh destroy centos1
Domain centos1 destroyed
step2:编辑/etc/libvirt/qemu/centos1.xml 增加磁盘模块
1
2
3
4
5
6
7
8
|
[root@kvm ~]
# vim /etc/libvirt/qemu/centos1.xml
或者
[root@kvm ~]
# virsh edit centos1
<disk
type
=
'file'
device=
'disk'
>
<driver name=
'qemu'
type
=
'qcow2'
cache=
'none'
/>
<
source
file
=
'/kvm/centos1_1.qcow2'
/>
<target dev=
'vdb'
bus=
'virtio'
/>
<
/disk
>
|
开启虚拟机
1
2
|
[root@kvm ~]
# virsh start centos1
[root@kvm ~]
# virsh console centos1
|
step3:分区
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@localhost ~]
# fdisk -l
Disk
/dev/vda
: 16.1 GB, 16106127360 bytes
16 heads, 63 sectors
/track
, 31207 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x000e5856
Device Boot Start End Blocks Id System
/dev/vda1
* 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2
1018 20806 9972736 8e Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3
20807 31207 5242104 83 Linux
Disk
/dev/vdb
: 5368 MB, 5368709120 bytes
16 heads, 63 sectors
/track
, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk
/dev/mapper/VolGroup-lv_root
: 14.5 GB, 14533263360 bytes
255 heads, 63 sectors
/track
, 1766 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
Disk
/dev/mapper/VolGroup-lv_swap
: 1040 MB, 1040187392 bytes
255 heads, 63 sectors
/track
, 126 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
|
分区
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@localhost ~]
# fdisk /dev/vdb
Command (m
for
help): p
Command (m
for
help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-10402, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10402, default 10402):
Using default value 10402
Command (m
for
help): p
Disk
/dev/vdb
: 5368 MB, 5368709120 bytes
16 heads, 63 sectors
/track
, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x3d00f46a
Device Boot Start End Blocks Id System
/dev/vdb1
1 10402 5242576+ 83 Linux
Command (m
for
help): w
The partition table has been altered!
|
1
2
3
4
5
6
7
8
9
|
[root@localhost ~]
# partx /dev/vdb
# 1: 63- 10485215 ( 10485153 sectors, 5368 MB)
# 2: 0- -1 ( 0 sectors, 0 MB)
# 3: 0- -1 ( 0 sectors, 0 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
[root@localhost ~]
# ll /dev/vdb*
brw-rw----. 1 root disk 252, 16 Jan 17 01:22
/dev/vdb
brw-rw----. 1 root disk 252, 17 Jan 17 01:22
/dev/vdb1
|
格式化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@localhost ~]
# mkfs.ext4 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310644 blocks
65532 blocks (5.00%) reserved
for
the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables:
done
Creating journal (32768 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
|
挂载/自动挂载
1
2
3
|
[root@localhost ~]
# mkdir /data
[root@localhost ~]
# mount /dev/vdb1 /data/
EXT4-fs (vdb1): mounted filesystem with ordered data mode. Opts:
|
1
2
3
4
5
6
7
|
[root@localhost ~]
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 14G 685M 12G 6% /
tmpfs tmpfs 246M 0 246M 0%
/dev/shm
/dev/vda1
ext4 477M 33M 419M 8%
/boot
/dev/vdb1
ext4 4.8G 10M 4.6G 1%
/data
|
1
2
|
[root@localhost ~]
# vi /etc/fstab
/dev/vdb1
/data
ext4 defaults 0 0
|
本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1735600