主要的命令集放在一起,
# fdisk -l
# fdisk /dev/sda
1 后面是具体的操作步骤
[root@itcast01 /]# fdisk -l
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000efe3e
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 62914559 30968832 8e Linux LVM
磁盘 /dev/mapper/centos-root:28.0 GB, 28001173504 字节,54689792 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2000 MB, 2000683008 字节,3907584 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:1707 MB, 1707081728 字节,3334144 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
然后下面进行格式 化增加的内存分区 输入 p -> 3 后, 默认大小分区需要自己回车确认
[root@itcast01 /]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):p
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000efe3e
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 62914559 30968832 8e Linux LVM
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分区号 (3,4,默认 3):3
起始 扇区 (62914560-104857599,默认为 62914560):
将使用默认值 62914560
Last 扇区, +扇区 or +size{K,M,G} (62914560-104857599,默认为 104857599):
将使用默认值 104857599
分区 3 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
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)
正在同步磁盘。
重启vm 里的linux 再次查看系统内存
[root@itcast01 /]# fdisk -l
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000efe3e
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 62914559 30968832 8e Linux LVM
/dev/sda3 62914560 104857599 20971520 8e Linux LVM
磁盘 /dev/mapper/centos-root:28.0 GB, 28001173504 字节,54689792 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2000 MB, 2000683008 字节,3907584 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:1707 MB, 1707081728 字节,3334144 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
格式化分区,mkfs.ext3 /dev/sda3一直挂载的分区是sda3;
[root@itcast01 /]# mkfs.ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
6.输入以下指令: 这里要注意一下,自己的用户组是哪个
lvm //进入lvm管理
lvm>pvcreate /dev/sda3
lvm>vgextend centos /dev/sda3 //将初始化过的分区加入到虚拟卷组centos
lvm>vgdisplay -v
lvm>lvextend -l +5119 /dev/mapper/centos-root
lvm>pvdisplay //查看卷容量
lvm>quit
具体操作如下 lvextend -l +5119 /dev/mapper/centos-root 这是总共自由的分区加入组 Total PE / Free PE 5119 / 5119
lvm> vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size <49.53 GiB
PE Size 4.00 MiB
Total PE 12679
Alloc PE / Size 7560 / 29.53 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID M8tETf-tDdk-caFp-X7ci-TfNw-4Vqk-DFIaHv
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID KSx2iP-Lq4S-LSlO-c0DX-5rZc-uifQ-V6FRH1
LV Write Access read/write
LV Creation host, time localhost, 2017-11-29 20:23:36 +0800
LV Status available
# open 1
LV Size <26.08 GiB
Current LE 6676
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID zYxQye-Ofw8-nSnw-EvMp-JTdw-59EQ-xk9j3Y
LV Write Access read/write
LV Creation host, time localhost, 2017-11-29 20:23:37 +0800
LV Status available
# open 2
LV Size 1.86 GiB
Current LE 477
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID WLOjQt-xb4I-mwVD-CHhk-Zisl-Biqo-xFK3Ej
LV Write Access read/write
LV Creation host, time localhost, 2017-11-29 20:23:37 +0800
LV Status available
# open 1
LV Size <1.59 GiB
Current LE 407
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Physical volumes ---
PV Name /dev/sda2
PV UUID QTcLva-VRiC-UMDw-uNZS-1CE8-OeZj-GCR1Py
PV Status allocatable
Total PE / Free PE 7560 / 0
PV Name /dev/sda3
PV UUID FJ8TAN-zZUX-GMa3-nOY5-HO2D-NBDm-OSeWoL
PV Status allocatable
Total PE / Free PE 5119 / 5119
lvm> lvextend -l+5119 /dev/mapper/centos-root
Size of logical volume centos/root changed from <26.08 GiB (6676 extents) to 46.07 GiB (11795 extents).
Logical volume centos/root successfully resized.
lvm> quit
Exiting.
7.使用命令xfs_growfs /dev/mapper/centos-root扩展容量。
8.使用df -h可以看到扩展成功。
[root@itcast01 /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1709056 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=6836224, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3338, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 6836224 to 12078080
[root@itcast01 /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 47G 17G 30G 37% /
devtmpfs 2.9G 0 2.9G 0% /dev
tmpfs 2.9G 0 2.9G 0% /dev/shm
tmpfs 2.9G 9.1M 2.9G 1% /run
tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
/dev/sda1 473M 283M 191M 60% /boot
/dev/mapper/centos-home 1.6G 523M 1.1G 33% /home
tmpfs 581M 4.0K 581M 1% /run/user/42
tmpfs 581M 28K 581M 1% /run/user/0
查看命令
[root@itcast01 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 476M 0 part /boot
├─sda2 8:2 0 29.5G 0 part
│ ├─centos-root 253:0 0 46.1G 0 lvm /
│ ├─centos-swap 253:1 0 1.9G 0 lvm [SWAP]
│ └─centos-home 253:2 0 1.6G 0 lvm /home
└─sda3 8:3 0 20G 0 part
└─centos-root 253:0 0 46.1G 0 lvm /
sr0 11:0 1 1024M 0 rom
[root@itcast01 /]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-ao---- <1.59g
root centos -wi-ao---- 46.07g
swap centos -wi-ao---- 1.86g