一、LVM类型
fdisk分区和更改类型
#选择准备的分区
fdisk /dev/vda
#n p enter enter enter 默认分成最大块
#更改新分的块为lvm类型
#t 3 8e w保存退出
dd if=/dev/urandom of=/dev/vda3 bs=512 count=64
扩容更分区
#把刚刚更改类型的建成一个卷
pvcreate /dev/vda3
#pvdisplay 查看
#vgdisplay 查看卷组的名称
#把刚刚的卷加入卷组
vgextend centos /dev/vda3
lvresize -L +500G /dev/mapper/centos-root
# resize2fs -p /dev/mapper/VolGroup-LogVol01
#resize*出现错误 看文件格式决定用什么 此处为xfs格式, vi /etc/fstab 可见
#btrfs filesystem resize +1G /
xfs_growfs /dev/mapper/centos-root
df -h
案例
computer宿主机根目录空间不足,home目录空间比较大。
#1、解除home目录挂载
umount /home
#2、检查文件系统的正确性(可不操作)
e2fsck -f /dev/hty-compute9-vg/home
#3、缩小卷文件系统的空间 有风险
resize2fs /dev/hty-compute9-vg/home 100G
#4、缩小卷lvm的空间
lvresize -L 50G /dev/hty-compute9-vg/home
#5、加大/目录的空间
lvextend -l+2 /dev/hty-compute9-vg/root
#6、更改文件系统
resize2fs -f /dev/hty-compute9-vg/root
#查询命令
lvs #查看卷信息
vgs #查看卷组信息
二、非LVM类型
1、删除与新建
(1)查看基本信息
(2)删除原有的根分区 /dev/vda1
(3)创建新的分区并保存
[root@localhost orcl11g]# fdisk /dev/vda
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): p
Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00005822
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209712509 104855231 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set
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.
2、刷新分区和刷新根分区
(1)刷新新分区
[root@localhost orcl11g]# partprobe /dev/vda
(2) 刷新根分区
[root@localhost orcl11g]# xfs_growfs /dev/vda1
meta-data=/dev/vda1 isize=256 agcount=51, agsize=524224 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=26213807, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 26213807 to 52428544
[root@vdl-ebbank-gsp2 orcl11g]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 3.9G 17M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 200G 94G 107G 47% /
tmpfs 783M 0 783M 0% /run/user/0