ここでは、仮想マシン demo02 に新に仮想ディスクを追加する方法について紹介する。
ホストマシンにて、仮想マシンの仮想ディスクイメージが置かれているディレクトリへ移動する。
# cd /var/lib/libvirt/images/
#
# ls
blockstrage.img controller.img demo02-1.img demo03.img
compute.img demo.img demo02.img hp.img
#
追加する仮想ディスクイメージを作成する。ここでは、10Gの仮想ディスクを作成する。
# qemu-img create -f raw demo02-1.img 10G
Formatting 'demo02-1.img', fmt=raw size=10737418240
#
作成した仮想ディスクの情報を確認する。
# qemu-img info demo02-1.img
image: demo02-1.img
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 0
#
仮想ディスクを追加したい仮想マシンを停止する。
# virsh shutdown demo02
ドメイン demo02 はシャットダウン中です
#
仮想マシンの設定ファイルを編集し、追加したい仮想ディスクを追加する。(ここから)〜(ここまで)の情報を追加する。
# virsh edit demo02
〜(省略)〜
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/demo02.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
==(ここから)==
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/images/demo02-1.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
==(ここまで)==
ドメイン demo02 XML の設定は編集されました
#
仮想マシンを起動する。
# virsh start demo02
ドメイン demo02 が起動されました
#
仮想マシンの現在のパーティションを確認する。
# fdisk -l
Disk /dev/vda: 26.8 GB, 26843545600 bytes, 52428800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000f210e
デバイス ブート 始点 終点 ブロック Id システム
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 52428799 25164800 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk /dev/mapper/centos-root: 24.7 GB, 24691867648 bytes, 48226304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
#
追加する仮想ディスク用に、パーティションを新規作成する。ここでは、/dev/vdb で作成する。
# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xa6687793.
コマンド (m でヘルプ): m
コマンドの動作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
コマンド (m でヘルプ): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
最初 sector (2048-20971519, 初期値 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, 初期値 20971519): 20971519
Partition 1 of type Linux and of size 10 GiB is set
コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): L
0 空 24 NEC DOS 81 Minix / 古い Li bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux スワップ c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 隠し C: ド c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 拡張領域 c7 Syrinx
5 拡張領域 41 PPC PReP Boot 86 NTFS ボリューム da 非 FS データ
6 FAT16 42 SFS 87 NTFS ボリューム db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux プレーン de Dell ユーティリ
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX ブート可能 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 ブートマネ 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad ハ eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 拡張領域 (L 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隠し FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 診断 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隠し FAT16 <32M 61 SpeedStor ab Darwin ブート f2 DOS セカンダリ
16 隠し FAT16 63 GNU HURD または af HFS / HFS+ fb VMware VMFS
17 隠し HPFS/NTFS 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI スワップ fd Linux raid 自動
1b 隠し W95 FAT32 70 DiskSecure Mult bb 隠し Boot Wizar fe LANstep
1c 隠し W95 FAT32 75 PC/IX be Solaris ブート ff BBT
1e 隠し W95 FAT16 80 古い Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。
#
作成した /dev/vdb1 のパーティション情報を確認する。
# fdisk -l /dev/vdb1
Disk /dev/vdb1: 10.7 GB, 10736369664 bytes, 20969472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
#
作成した /dev/vdb1 に物理ボリューム(PV)を作成する。
# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
#
作成した物理ボリューム(PV)を状況を確認する。
# pvdisplay /dev/vdb1
"/dev/vdb1" is a new physical volume of "<10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID aqwjue-5wHR-sFwK-aqGB-NCVc-vfCO-P8b8KC
#