簡單總結:
1、在VMware中給Linux虛擬機擴展磁盤
2、進入虛擬機查看磁盤:fdisk -l
3、操作分區表:fdisk /dev/sda,對新增的磁盤空間進行分區
4、格式化新分出來的磁盤分區:mkfs.xfs /dev/sda3 (可以用df -Th命令查看分區類型)
5、卷擴容。把格式化后的分區創建為物理卷(phisycal volumn):pvcreate /dev/sda3 (顯示物理卷的命令是:pvdisplay)
6、文件系統擴容:xfs_growfs /dev/mapper/centos-root
7、完成磁盤擴展,查看結果:df -h
一、首先在虛擬機中調整硬盤容量
二、在linux系統中進行配置
1、查看硬盤:fdisk -l
[root@oracle_db user]# fdisk -l
磁盤 /dev/sda:268.4 GB, 268435456000 字節,524288000 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000a9550
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
磁盤 /dev/mapper/centos-root:29.0 GB, 28982640640 字節,56606720 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
2、操作分區表
[root@oracle_db user]# fdisk /dev/sda
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.
Command (m for help): m
Command action
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)
鍵入p 查看分區數量
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000ccdc8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
由此判斷我們增加的分區號應該為3(dev/sda1,dev/sda2……接下來應該是dev/sda3了吧)
鍵入n,增加一個分區,得到:
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
鍵入 p,主分區,并鍵入3(編號),也可以回車默認,默認起始扇區和結束扇區即可(鍵入兩次Enter)
Select (default p): p
Partition number (3,4, default 3):
First sector (41943040-104857599, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 30 GiB is set
鍵入t,修改分區類型為8e:
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
鍵入w,寫分區表,然后重啟:
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@localhost .ssh]# reboot
Connection closing...Socket close.
3、格式化
[root@localhost ~]# mkfs.xfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
如果不清楚類型的話,可以查詢之前的分區是用的什么格式
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 12M 3.8G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 15G 2.7G 85% /
/dev/sda1 xfs 1014M 151M 864M 15% /boot
tmpfs tmpfs 781M 0 781M 0% /run/user/0
4、卷擴容:
pvcreate /dev/sda3 初始化剛才的分區
[root@localhost ~]# pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
vgextend centos /dev/sda3 將初始化過的分區加入到虛擬卷組centos
[root@localhost ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
lvextend -L +29G /dev/centos/root 擴展已有卷的容量
[root@localhost ~]# lvextend -L +29G /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.00 GiB (11775 extents).
Logical volume centos/root successfully resized.
pvdisplay查看卷容量
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID iE79X6-Jp4j-8vSk-HZPI-yF6z-5xf6-o4Xjsx
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 30.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 7679
Free PE 255
Allocated PE 7424
PV UUID A4cQsp-WHHt-65i0-O0CQ-wm1G-hLVT-x0Co1l
5、文件系統擴容
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, 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 4455424 to 12057600
如果不是xfs,則執行命令: resize2fs /dev/mapper/centos-root
6、查看結果
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 15G 32G 32% /
/dev/sda1 1014M 151M 864M 15% /boot
tmpfs 781M 0 781M 0% /run/user/0