
1、使用root用户登录到Linux系统。
2、右键点击计算机桌面空白处,点击“Open Teminal”,打开命令终端。
3、输入 fdisk -l 命令,查看当前系统的磁盘分区。
4、打开VMware管理客户端,右键点击要添加硬盘的虚拟机,点击“编辑设置”,编辑虚拟机的设置。
5、在虚拟机属性界面,点击“添加”—“硬盘”,添加一个新的硬盘。
6、等待虚拟机配置完成即可。
今天上了存储,之前有些项目LINUX虚拟机需要扩容,所以做了下测试,希望对大家有用。
1、首先需要做在线硬盘扩容的话,需要保证虚拟机没有快照。
第一种方法:在原有的硬盘上直接改变磁盘置备的大小
改之前:25G
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 25G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 15G 0 part
│ ├─rhel-root 253:0 0 66.4G 0 lvm /
│ └─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
└─sda3 8:3 0 9G 0 part
└─rhel-root 253:0 0 66.4G 0 lvm /
改之后:40G
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 25G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 15G 0 part
│ ├─rhel-root 253:0 0 66.4G 0 lvm /
│ └─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
└─sda3 8:3 0 9G 0 part
└─rhel-root 253:0 0 66.4G 0 lvm /
通过partprobe命令也无法识别出来
重启之后,识别出来40G空间
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 15G 0 part
│ ├─rhel-root 253:0 0 66.4G 0 lvm /
│ └─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
└─sda3 8:3 0 9G 0 part
└─rhel-root 253:0 0 66.4G 0 lvm /
sda1+sda2+sda3=25G,所以sda还有15G可以用
[root@localhost ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): p
已选择分区 4
起始 扇区 (52428800-83886079,默认为 52428800):
将使用默认值 52428800
Last 扇区, +扇区 or +size{K,M,G} (52428800-83886079,默认为 83886079):
将使用默认值 83886079
分区 4 已设置为 Linux 类型,大小设为 15 GiB
命令(输入 m 获取帮助):t
分区号 (1-4,默认 4):8e
分区号 (1-4,默认 4):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@localhost ~]#
[root@localhost ~]# partprobe
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 15G 0 part
│ ├─rhel-root 253:0 0 66.4G 0 lvm /
│ └─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
├─sda3 8:3 0 9G 0 part
│ └─rhel-root 253:0 0 66.4G 0 lvm /
└─sda4 8:4 0 15G 0 part
将sda4加进去
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 5 2 0 wz--n- 73.98g 5.98g
[root@localhost ~]# lvm
lvm> pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
lvm> vgextend rhel /dev/sda4
Volume group "rhel" successfully extended
lvm> lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID IIuZXp-olio-8mnv-zOYn-hm9a-CjWb-89C75z
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-04-17 16:33:20 +0800
LV Status available
# open 2
LV Size 1.60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 8PMjP0-HifX-qHKj-CqN2-dnnd-Ln0N-9Th9bK
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-04-17 16:33:21 +0800
LV Status available
# open 1
LV Size 66.39 GiB
Current LE 16997
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
lvm> lvextend -L +15G /dev/rhel/root
Size of logical volume rhel/root changed from 66.39 GiB (16997 extents) to 81.39 GiB (20837 extents).
Logical volume rhel/root successfully resized.
lvm> EXIT
No such command 'EXIT'. Try 'help'.
lvm> exit
Exiting.
[root@localhost ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=512 agcount=18, agsize=877824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=15045632, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 15045632 to 21337088
这里是redhat7,文件系统是xfs,所以用命令xfs_growfs 如果是redhat6,ext4的文件系统,则是resize2fs命令
扩容后最终
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 15G 0 part
│ ├─rhel-root 253:0 0 81.4G 0 lvm /
│ └─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
├─sda3 8:3 0 9G 0 part
│ └─rhel-root 253:0 0 81.4G 0 lvm /
└─sda4 8:4 0 15G 0 part
└─rhel-root 253:0 0 81.4G 0 lvm /
缺点,需要重启一次
第二种方法:直接添加硬盘,而不是在原有的上面只接更改大小
添加的硬盘直接可以识别出来,直接按照第一种方法的重启之后的步骤一步一步就可以了。
优点:不需要重启
这里以Red hat AS4 为例。当磁盘分区发现不够用时,能想道的第一个做法就是增加分区大小。但是一般Linux如果没有采用逻辑卷管理,则动态增加分区大小很困难,一个能想道的办法就是,备份分区文件系统数据,删除分区,然后再重新创建分区,恢复备份的文件系统,这个做法比较玄,可能删除分区后导致系统无法启动。第二个做法就是,创建一个新的逻辑分区(当然必须有未使用的磁盘空间能分配),将文件系统从老分区拷贝到新分区,然后修改fstab,使用新分区/文件系统替换老的分区/文件系统
第三种做法是,创建一个新的逻辑分区,将新的逻辑分区格式化ext3(或其他类型)的文件系统,mount到磁盘空间不够的文件系统,就跟原来的分区/文件系统一样的使用。
这里采用的是第三种方式:
sdb为第二个SCSI硬盘。
[root@hdp0 hadoop]# /sbin/fdisk /dev/sdb
The number of cylinders for this disk is set to 8942.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522894267641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 6521173 4192933+ 83 Linux
可以看出sdb1,2,3为主分区,sdb4为扩展分区。后面的sdb5,6,7则为逻辑分区。柱面编号(Start,End)是连续的,sdb7只用道了1173,而从扩展分区看最大到8942,也就是说,还有7769个柱面是空闲的,一个柱面大小为8225280,约为8M大小。还剩7769*8225280bytes,约62G未使用。
新增加一个逻辑分区(注:若涉及到主分区和扩展分区,实际情况可能比这个复杂,这里4个主分区(包括扩展分区)都分过了,所以只能分逻辑分区)
Command (m for help): n
First cylinder (1174-8942, default 1174):
Using default value 1174
增加大小为10G
Last cylinder or +size or +sizeM or +sizeK (1174-8942, default 8942): +10240M
增加后看一下,多了一个逻辑分区/dev/sdb8
Command (m for help): p
Disk /dev/sdb: 73.5 GB, 73557090304 bytes
255 heads, 63 sectors/track, 8942 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 130 1044193+ 83 Linux
/dev/sdb2 131 391 2096482+ 82 Linux swap
/dev/sdb3 392 521 1044225 83 Linux
/dev/sdb4 522894267641682+ 5 Extended
/dev/sdb5 522 586 522081 83 Linux
/dev/sdb6 587 651 522081 83 Linux
/dev/sdb7 6521173 4192933+ 83 Linux
/dev/sdb81174241910008463+ 83 Linux
可以看到,增加了一个sdb8的分区,柱面号从1174到2419.
写入分区表,执行分区 *** 作
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: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
分区完后,是看不到文件系统的
[root@hdp0 hadoop]# df -m
Filesystem 1M-块已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 49411 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 49487 382 19% /var
重启机器
reboot
格式化文件系统
[root@hdp0 hadoop]#/sbin/mkfs.ext3 /dev/sdb8
mount文件系统,/home/develop 为/home下一目录
[root@hdp0 hadoop]#mount /dev/sdb8 /home/develop
查看文件系统,可以看到新建立的分区/文件系统已经挂载上,能够使用了。
[root@hdp0 hadoop]# df -m
Filesystem 1M-块已用 可用 已用% 挂载点
/dev/sdb1 1004 582 372 62% /
none 1014 0 1014 0% /dev/shm
/dev/sdb3 1004 807 147 85% /home
/dev/sdb5 49411 458 3% /opt
/dev/sdb7 4031 3272 554 86% /usr
/dev/sdb6 49487 382 19% /var
/dev/sdb8 962154 9079 1% /home/develop
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)