- [root@testandy ~]# fdisk -l
- 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: 0x00020dcb
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 411647 204800 83 Linux
- /dev/sda2 411648 67545087 33566720 8e Linux LVM
- /dev/sda3 67545088 84322303 8388608 83 Linux
- /dev/sda4 84322304 88516607 2097152 5 Extended
- Disk /dev/mapper/CentOS-root: 5368 MB, 5368709120 bytes, 10485760 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 /dev/mapper/CentOS-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/CentOS-home: 5368 MB, 5368709120 bytes, 10485760 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 /dev/mapper/CentOS-var: 30.1 GB, 30064771072 bytes, 58720256 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 /dev/mapper/CentOS-00: 4 MB, 4194304 bytes, 8192 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
- [root@testandy ~]#
- [root@testandy ~]# 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): help
- h: unknown command
- 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)
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 5
- First sector (84324352-88516607, default 84324352):
- Using default value 84324352
- Last sector, +sectors or +size{
- K,M,G
- } (84324352-88516607, default 88516607): +2G
Value out of range.
- Last sector, +sectors or +size{
- K,M,G
- } (84324352-88516607, default 88516607): +1G
- Partition 5 of type Linux and of size 1 GiB is set
- 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: 0x00020dcb
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 411647 204800 83 Linux
- /dev/sda2 411648 67545087 33566720 8e Linux LVM
- /dev/sda3 67545088 84322303 8388608 83 Linux
- /dev/sda4 84322304 88516607 2097152 5 Extended
- /dev/sda5 84324352 86421503 1048576 83 Linux
- 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: 0x00020dcb
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 411647 204800 83 Linux
- /dev/sda2 411648 67545087 33566720 8e Linux LVM
- /dev/sda3 67545088 84322303 8388608 83 Linux
- /dev/sda4 84322304 88516607 2097152 5 Extended
- /dev/sda5 84324352 86421503 1048576 83 Linux
- Command (m for help): t
- Partition number (1-5, default 5):
- Hex code (type L to list all codes): 8e
- Changed type of partition 'Linux' to 'Linux LVM'
- 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: 0x00020dcb
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 411647 204800 83 Linux
- /dev/sda2 411648 67545087 33566720 8e Linux LVM
- /dev/sda3 67545088 84322303 8388608 83 Linux
- /dev/sda4 84322304 88516607 2097152 5 Extended
- /dev/sda5 84324352 86421503 1048576 8e Linux LVM
- Command (m for help):
- 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@testandy ~]#
文章目录
需求描述
具体步骤
查看本机磁盘环境
添加磁盘分区
开始扩容
同步到文件系统
参考内容
需求描述
由于测试环境需要, 虚拟机根目录需要扩容至 120G.
具体步骤
查看本机磁盘环境
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用 % 挂载点
- /dev/mapper/CentOS-root 35G 5.5G 30G 16% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 0 3.9G 0% /dev/shm
- tmpfs 3.9G 11M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 1014M 275M 740M 28% /boot
- tmpfs 783M 52K 783M 1% /run/user/0
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- fd0 2:0 1 4K 0 disk
- sda 8:0 0 500G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─CentOS-root 253:0 0 35G 0 lvm /
└─CentOS-swap 253:1 0 4G 0 lvm [SWAP]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
可以看到根目录总容量为 35G, 设备 sda 的总容量为 500G.
添加磁盘分区
需要 120G 容量, 已有 35G, 还需添加 85G 容量.
[root@localhost ~]# fdisk /dev/sda
欢迎使用 fdisk (util-Linux 2.23.2).
更改将停留在内存中, 直到您决定将更改写入磁盘.
使用写入命令前请三思.
命令(输入 m 获取帮助):n
- Partition type:
- p primary (2 primary, 0 extended, 2 free)
- e extended
- Select (default p):
- Using default response p
分区号 (3,4, 默认 3):
起始 扇区 (83886080-1048575999, 默认为 83886080):
将使用默认值 83886080
Last 扇区, + 扇区 or +size{K,M,G} (83886080-1048575999, 默认为 1048575999):+85G
分区 3 已设置为 Linux 类型, 大小设为 85 GiB
命令(输入 m 获取帮助):w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- [root@localhost ~]# partprobe
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
然后查看分区是否创建:
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- fd0 2:0 1 4K 0 disk
- sda 8:0 0 500G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 39G 0 part
│ ├─CentOS-root 253:0 0 35G 0 lvm /
│ └─CentOS-swap 253:1 0 4G 0 lvm [SWAP]
└─sda3 8:3 0 85G 0 part
- sr0 11:0 1 1024M 0 rom
可以看到 sda2 分区已创建.
开始扩容
创建物理卷:
- [root@localhost ~]# lvm
- lvm> pvcreate /dev/sda3
- Physical volume "/dev/sda3" successfully created.
- 1
- 2
- 3
- 4
查看物理卷和卷组:
- lvm> pvdisplay
- --- Physical volume ---
- PV Name /dev/sda2
- VG Name CentOS
- PV Size <39.00 GiB / not usable 3.00 MiB
- Allocatable yes (but full)
- PE Size 4.00 MiB
- Total PE 9983
- Free PE 0
- Allocated PE 9983
- PV UUID twmUZh-Vnqq-W5Pd-v3ms-6OkH-sSTs-nv8aA8
- "/dev/sda3" is a new physical volume of "85.00 GiB"
- --- NEW Physical volume ---
- PV Name /dev/sda3
- VG Name
- PV Size 85.00 GiB
- Allocatable NO
- PE Size 0
- Total PE 0
- Free PE 0
- Allocated PE 0
- PV UUID vTD91f-b28E-GgL0-XsqI-ipQ5-rscT-GcQbT6
- lvm> vgdisplay
- --- Volume group ---
- VG Name CentOS
- System ID
- Format lvm2
- Metadata Areas 1
- Metadata Sequence No 3
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 2
- Open LV 2
- Max PV 0
- Cur PV 1
- Act PV 1
- VG Size <39.00 GiB
- PE Size 4.00 MiB
- Total PE 9983
- Alloc PE / Size 9983 / <39.00 GiB
- Free PE / Size 0 / 0
- VG UUID 238Yz8-MEQa-NT6a-3aHC-J3TZ-mGux-e9vqPf
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
将物理卷加入到卷组:
- lvm> vgextend CentOS /dev/sda3
- Volume group "centos" successfully extended
- lvm> vgdisplay
- --- Volume group ---
- VG Name CentOS
- System ID
- Format lvm2
- Metadata Areas 2
- Metadata Sequence No 4
- VG Access read/write
- VG Status resizable
- MAX LV 0
- Cur LV 2
- Open LV 2
- Max PV 0
- Cur PV 2
- Act PV 2
- VG Size 123.99 GiB
- PE Size 4.00 MiB
- Total PE 31742
- Alloc PE / Size 9983 / <39.00 GiB
- Free PE / Size 21759 / <85.00 GiB
- VG UUID 238Yz8-MEQa-NT6a-3aHC-J3TZ-mGux-e9vqPf
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
可以看到卷组的 Free size 增加了
将卷组剩余空间 (刚添加的 85G) 添加到逻辑卷 / dev/CentOS/root :
- lvm> lvextend -l +100%FREE /dev/CentOS/root
- Size of logical volume CentOS/root changed from <35.00 GiB (8959 extents) to 119.99 GiB (30718 extents).
Logical volume CentOS/root successfully resized.
1
2
3
同步到文件系统
之前只是对逻辑卷扩容, 还要同步到文件系统, 实现对根目录的扩容.
- [root@localhost ~]# xfs_growfs /dev/CentOS/root
- meta-data=/dev/mapper/CentOS-root isize=512 agcount=4, agsize=2293504 blks
- = sectsz=512 attr=2, projid32bit=1
- = crc=1 finobt=0 spinodes=0
- data = bsize=4096 blocks=9174016, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0 ftype=1
- log =internal bsize=4096 blocks=4479, version=2
- = sectsz=512 sunit=0 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- data blocks changed from 9174016 to 31455232
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
然后再查看挂载情况:
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用 % 挂载点
- /dev/mapper/CentOS-root 120G 5.5G 115G 5% /
- devtmpfs 3.9G 0 3.9G 0% /dev
- tmpfs 3.9G 0 3.9G 0% /dev/shm
- tmpfs 3.9G 11M 3.9G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 1014M 275M 740M 28% /boot
- tmpfs 783M 52K 783M 1% /run/user/0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
可以发现有 120G 的空间挂载在根目录上.
- over !!!
- ---------------------
来源: http://www.bubuko.com/infodetail-2989587.html