文章目录
1. 整体操作思路图
2. 文件系统现状分析
(1) 用 df 指令查看文件系统的磁盘空间使用情况。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 4.2G 14G 23% /
tmpfs 499M 1004K 498M 1% /dev/shm
/dev/sda1 93M 52M 36M 60% /boot
/dev/sda3 20G 18G 690M 97% /home
以上信息显示 /home 目录已占用分区97%的空间。因为采用标准分区,不能在原有的基础上扩容。为了以后更好地管理磁盘,我们需要将现有的标准分区转换成 LVM 分区。
目前有两种可选方案:
- 一添加新的磁盘,划分 LVM 分区,迁移旧磁盘文件到新磁盘;
- 二把原磁盘剩余空间划分为 LVM 分区,迁移旧分区文件到新的 LVM 分区。
(2) 用 fdisk 指令查看分区情况。
[root@localhost ~]# fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 2563 20480000 83 Linux
/dev/sda3 2563 5113 20480000 83 Linux
/dev/sda4 5113 12162 56622080 5 Extended
/dev/sda5 5113 5374 2097152 82 Linux swap / Solaris
以上信息显示 /dev/sda4 为扩展分区,约有56G的可用空间。所以,选用第二种方案为皆。
3. 重新划分磁盘剩余可用空间
因为swap交换区在 /dev/sda4 扩展分区内,为数据安全起见,我们需要先关闭 swap 交换区,再通过 fdisk 指令的一系列操作来实现分区的删除和建立。
(1) 关闭系统交换区
# 查看系统物理内存及 swap 内存情况
[root@localhost ~]# free
total used free shared buffers cached
Mem: 1020936 476744 544192 142312 17996 293256
-/+ buffers/cache: 165492 855444
Swap: 2097148 135024 1962124 # 交换区在使用中
# 关闭所有交换区,并显示详细信息
[root@localhost ~]# swapoff -av
swapoff on /dev/sda5
[root@localhost ~]# free
total used free shared buffers cached
Mem: 1020936 579804 441132 177268 18152 329192
-/+ buffers/cache: 232460 788476
Swap: 0 0 0 # 交换区已关闭
(2) 重新划分可用空间
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's ...
Command (m for help): d # 删除 /dev/sda4 扩展分区
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 100.0 GB, 100030242816 bytes
........此处省略........
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Li