1、通过虚拟机添加硬盘一定的大小
首先我用的vbox,和vmware添加内存的方式不一样,VMware里面相对就简单很多,vbox就不太一样了。
1.1 首先配置一下环境变量,就是将vbox的安装目录配置到电脑环境变量里面(这里不做介绍),当然,你也可以不用配置环境变量,直接打开cmd进入到vbox的安装目录也可以。
1.2 打开cmd运行VBoxManage list hdds,找到目标虚拟机
C:\Users\ageeklet>VBoxManage list hdds
UUID: 43ecf7cb-91eb-4bd2-ab1f-23fc2f96c896
Parent UUID: base
State: created
Type: normal (base)
Location: C:\Users\ageeklet\VirtualBox VMs\centos6\centos6.vdi
Storage format: VDI
Capacity: 20480 MBytes
Encryption: disabled
UUID: 5412a636-8b87-4bb0-9029-4cdca7b2efd4
Parent UUID: 43ecf7cb-91eb-4bd2-ab1f-23fc2f96c896
State: created
Type: normal (differencing)
Location: C:\Users\ageeklet\VirtualBox VMs\centos6\Snapshots/{5412a636-8b87-4bb0-9029-4cdca7b2efd4}.vdi
Storage format: VDI
Capacity: 20480 MBytes
Encryption: disabled
UUID: 27acacd2-e259-457a-a5a7-1e59db65e5fc
Parent UUID: 5412a636-8b87-4bb0-9029-4cdca7b2efd4
State: created
Type: normal (differencing)
Location: C:\Users\ageeklet\VirtualBox VMs\centos6\Snapshots/{27acacd2-e259-457a-a5a7-1e59db65e5fc}.vdi
Storage format: VDI
Capacity: 20480 MBytes
Encryption: disabled
UUID: 14edd3e9-a033-4428-aa17-d232d7d31041
Parent UUID: 27acacd2-e259-457a-a5a7-1e59db65e5fc
State: created
Type: normal (differencing)
Location: C:\Users\ageeklet\VirtualBox VMs\centos6\Snapshots/{14edd3e9-a033-4428-aa17-d232d7d31041}.vdi
Storage format: VDI
Capacity: 20480 MBytes
Encryption: disabled
UUID: 73e1dee1-bbcb-40f3-9b4f-d45d58da1b6e //目标虚拟机
Parent UUID: base
State: created
Type: normal (base)
Location: C:\Users\ageeklet\VirtualBox VMs\centos6-Oracle\centos6-Oracle.vdi
Storage format: VDI
Capacity: 20480 MBytes
Encryption: disabled
1.3 使用VBoxManage modifyhd命令添加内存,复制目标虚拟机的UUID,给定需要添加的硬盘大小
C:\Users\ageeklet>VBoxManage modifyhd 73e1dee1-bbcb-40f3-9b4f-d45d58da1b6e --resize 40000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
2 在虚拟机中操作
2.1 首先确定是否添加成功
[root@oracle ~]# fdisk -l
Disk /dev/sda: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 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: 0x0008f90d
我这里原先只有20G,通过操作添加到40G了。
2.2 创建分区
[root@oracle ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n // 输入 n 表示创建新分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3 //输入 3 表示sda3,因为前面已经有两个了
First cylinder (2611-5099, default 2611): //回车,按默认值
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-5099, default 5099): //回车,按默认值
Using default value 5099
Command (m for help): w //输入 w 保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@oracle ~]# fdisk -l //查看sda3分区已经加进去了
Disk /dev/sda: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 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: 0x0008f90d
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2611 20765696 8e Linux LVM
/dev/sda3 2611 5099 19986197+ 83 Linux
2.3 将/dev/sda3分区设置为LVM格式
[root@oracle ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): t //change a partition's system id
Partition number (1-4): 3
Hex code (type L to list codes): 8e //LVM格式的标识
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@oracle ~]# fdisk -l
Disk /dev/sda: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 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: 0x0008f90d
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2611 20765696 8e Linux LVM
/dev/sda3 2611 5099 19986197+ 8e Linux LVM
2.4 重启机器之后将添加的物理硬盘,初始化为物理卷,以便被LVM使用
[root@oracle ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@oracle ~]# vgextend lvm_group /dev/sda3
Volume group "lvm_group" successfully extended
2.5 给swap添加内存
[root@oracle ~]# swapoff -a //关闭swap内存
[root@oracle ~]# lvextend /dev/lvm_group/lvm_swap -L 3G //添加至3G
Size of logical volume lvm_group/lvm_swap changed from 1.00 GiB (256 extents) to 3.00 GiB (768 extents).
Logical volume lvm_swap successfully resized.
[root@oracle ~]# mkswap /dev/lvm_group/lvm_swap
mkswap: /dev/lvm_group/lvm_swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 3145724 KiB
no label, UUID=1463e1d0-a01a-4397-9caf-5a488444feab
[root@oracle ~]# swapon -a //打开swap内存
[root@oracle ~]# free -m //查看swap内存是否添加成功
total used free shared buffers cached
Mem: 2006 98 1907 0 10 29
-/+ buffers/cache: 58 1947
Swap: 3071 0 3071
2.6 给其他分区添加物理硬盘,如根分区(/)
[root@oracle ~]# lvextend -L +10G /dev/lvm_group/lvm_root //增加10G的
Size of logical volume lvm_group/lvm_root changed from 18.80 GiB (4813 extents) to 28.80 GiB (7373 extents).
Logical volume lvm_root successfully resized.
[root@oracle ~]# fdisk -l
......
Disk /dev/mapper/lvm_group-lvm_root: 30.9 GB, 30924603392 bytes
255 heads, 63 sectors/track, 3759 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
......
原先为20G,增加了10G大小。
*** 可以用lvdisplay和vgdisplay查看卷组信息
[root@oracle ~]# vgdisplay
--- Volume group ---
VG Name lvm_group
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 38.86 GiB
PE Size 4.00 MiB
Total PE 9948
Alloc PE / Size 8141 / 31.80 GiB
Free PE / Size 1807 / 7.06 GiB
VG UUID X6e8bB-u2Tp-0ddx-px81-5MCn-NLJo-x6Kbo0
[root@oracle ~]# lvdisplay
--- Logical volume ---
LV Path /dev/lvm_group/lvm_root
LV Name lvm_root
VG Name lvm_group
LV UUID wiZX8Q-swId-bV6R-aYYC-e4ye-IHrh-DjY8tj
LV Write Access read/write
LV Creation host, time db-server, 2018-08-15 08:46:05 +0800
LV Status available
# open 1
LV Size 28.80 GiB
Current LE 7373
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/lvm_group/lvm_swap
LV Name lvm_swap
VG Name lvm_group
LV UUID nDW5I7-AfYa-1KXU-HHNT-l8Hz-PqOK-eJ4ZVs
LV Write Access read/write
LV Creation host, time db-server, 2018-08-15 08:46:10 +0800
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 768
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1