Linux添加硬碟擴充已有分區存儲空間方式 總體步驟 磁碟初始化分區 創建物理捲 擴展卷組 擴展邏輯捲 通知文件系統生效 磁碟初始化分區 已有磁碟200G,添加一塊1T的磁碟 執行結果 第二塊磁碟分區已經創建,分配空間1T(全部空間) 創建物理捲 現有物理捲如下: [root@oracledb ...
Linux添加硬碟擴充已有分區存儲空間方式
總體步驟
磁碟初始化分區
創建物理捲
擴展卷組
擴展邏輯捲
通知文件系統生效
磁碟初始化分區
[root@oracledb ~]# fdisk -l
磁碟 /dev/sda:214.7 GB, 214748364800 位元組,419430400 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:dos
磁碟標識符:0x0000373a
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
磁碟 /dev/sdb:1099.5 GB, 1099511627776 位元組,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:gpt
Disk identifier: 0416CD57-7203-48B1-8D1C-6604E73EAFE5
# Start End Size Type Name
1 2048 2147483614 1024G Linux filesyste
磁碟 /dev/mapper/centos-root:53.7 GB, 53687091200 位元組,104857600 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟 /dev/mapper/centos-swap:8455 MB, 8455716864 位元組,16515072 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟 /dev/mapper/centos-home:151.5 GB, 151523426304 位元組,295944192 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
已有磁碟200G,添加一塊1T的磁碟
[root@oracledb ~]# fdisk /dev/sdb
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在記憶體中,直到您決定將更改寫入磁碟。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):p
磁碟 /dev/sdb:1099.5 GB, 1099511627776 位元組,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:dos
磁碟標識符:0x55c66695
設備 Boot Start End Blocks Id System
/dev/sdb1 2048 2147483647 1073740800 83 Linux
命令(輸入 m 獲取幫助):m
命令操作
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)
命令(輸入 m 獲取幫助):g
Building a new GPT disklabel (GUID: 0416CD57-7203-48B1-8D1C-6604E73EAFE5)
命令(輸入 m 獲取幫助):p
磁碟 /dev/sdb:1099.5 GB, 1099511627776 位元組,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:gpt
Disk identifier: 0416CD57-7203-48B1-8D1C-6604E73EAFE5
# Start End Size Type Name
命令(輸入 m 獲取幫助):n
分區號 (1-128,預設 1):
第一個扇區 (2048-2147483614,預設 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-2147483614,預設 2147483614):
已創建分區 1
命令(輸入 m 獲取幫助):p
磁碟 /dev/sdb:1099.5 GB, 1099511627776 位元組,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:gpt
Disk identifier: 0416CD57-7203-48B1-8D1C-6604E73EAFE5
# Start End Size Type Name
1 2048 2147483614 1024G Linux filesyste
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁碟。
[root@oracledb ~]#
執行結果
[root@oracledb ~]# fdisk -l
磁碟 /dev/sda:214.7 GB, 214748364800 位元組,419430400 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:dos
磁碟標識符:0x0000373a
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
磁碟 /dev/sdb:1099.5 GB, 1099511627776 位元組,2147483648 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟標簽類型:gpt
Disk identifier: 0416CD57-7203-48B1-8D1C-6604E73EAFE5
# Start End Size Type Name
1 2048 2147483614 1024G Linux filesyste
磁碟 /dev/mapper/centos-root:53.7 GB, 53687091200 位元組,104857600 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟 /dev/mapper/centos-swap:8455 MB, 8455716864 位元組,16515072 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁碟 /dev/mapper/centos-home:151.5 GB, 151523426304 位元組,295944192 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
第二塊磁碟分區已經創建,分配空間1T(全部空間)
創建物理捲
現有物理捲如下:
[root@oracledb ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <199.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 50943
Free PE 1
Allocated PE 50942
PV UUID mBYtSA-2Hzk-QXQd-cDxv-P4Mu-6tX4-UVsrUd
創建物理捲
[root@oracledb dev]# pvcreate /dev/sdb1
WARNING: ext3 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
Wiping ext3 signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
[root@oracledb dev]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <199.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 50943
Free PE 1
Allocated PE 50942
PV UUID mBYtSA-2Hzk-QXQd-cDxv-P4Mu-6tX4-UVsrUd
"/dev/sdb1" is a new physical volume of "<1024.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <1024.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1aGhki-as5k-8Eqh-Hraf-HS9x-SgZT-mij9Hz
擴展卷組
現有捲組
[root@oracledb dev]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 5BZGt4-mAIC-EAS1-o2T8-hyAD-1gXU-sG7Pwt
執行擴展
[root@oracledb dev]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
[root@oracledb dev]# vgdisplay
--- 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 1.19 TiB
PE Size 4.00 MiB
Total PE 313086
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 262144 / 1.00 TiB
VG UUID 5BZGt4-mAIC-EAS1-o2T8-hyAD-1gXU-sG7Pwt
擴展邏輯捲
現有邏輯捲
[root@oracledb dev]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID VnspUh-5yWi-xLcu-LWeK-d3Bx-YfqO-i5opYp
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:08 +0800
LV Status available
# open 2
LV Size <7.88 GiB
Current LE 2016
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 0vTVTH-bxb8-02kQ-QWvd-yLdY-olDQ-dXacRh
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:09 +0800
LV Status available
# open 1
LV Size <141.12 GiB
Current LE 36126
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID HzVl83-V4BV-V6OA-32IE-fnPR-NPwF-4KPvk5
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:11 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
擴展/dev/centos/home捲(/home分區)
[root@oracledb dev]# lvextend -l +100%FREE /dev/centos/home
Size of logical volume centos/home changed from <141.12 GiB (36126 extents) to <1.14 TiB (298270 extents).
Logical volume centos/home successfully resized.
[root@oracledb dev]#
[root@oracledb dev]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID VnspUh-5yWi-xLcu-LWeK-d3Bx-YfqO-i5opYp
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:08 +0800
LV Status available
# open 2
LV Size <7.88 GiB
Current LE 2016
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 0vTVTH-bxb8-02kQ-QWvd-yLdY-olDQ-dXacRh
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:09 +0800
LV Status available
# open 1
LV Size <1.14 TiB
Current LE 298270
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID HzVl83-V4BV-V6OA-32IE-fnPR-NPwF-4KPvk5
LV Write Access read/write
LV Creation host, time localhost, 2017-10-17 19:44:11 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
通知文件系統生效
檢查文件系統類型
[root@oracledb dev]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Oct 17 19:44:14 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=d3ec0225-abeb-47ef-a209-9c1ba481bb02 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
註意,xfs文件系統使用 xfs_growfs,ext文件系統使用 resize2fs;xfs文件系統只支持增大不支持縮小
[root@oracledb dev]# xfs_growfs /dev/centos/home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=9248256 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=36993024, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=18063, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 36993024 to 305428480
[root@oracledb dev]#
調整成功
[root@oracledb dev]# df -h
文件系統 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root 50G 7.8G 43G 16% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 4.0K 7.8G 1% /dev/shm
tmpfs 7.8G 9.1M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 234M 781M 24% /boot
/dev/mapper/centos-home 1.2T 2.3G 1.2T 1% /home
tmpfs 1.6G 0 1.6G 0% /run/user/1001
tmpfs 1.6G 12K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/1000