最近碰到服務(wù)器磁盤空間不足,需要擴(kuò)展邏輯分區(qū)的需求,特地做下小筆記,方便后續(xù)自己回憶。下圖是磁盤的相關(guān)概念示意圖:
文章來源:http://www.zghlxwxcb.cn/news/detail-605960.html
1、查看磁盤空間
[root@localhost ~]# df -h
#查看磁盤空間,根分區(qū)的大小是18G,已經(jīng)用了43%。
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 7.0G 9.5G 43% /
tmpfs 2.0G 76K 2.0G 1% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/sr0 3.6G 3.6G 0 100% /media/cdrom
2、創(chuàng)建磁盤分區(qū)
#1、首先查詢磁盤的相關(guān)信息,便于后續(xù)創(chuàng)建擴(kuò)展時(shí)使用
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00083529
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
#注意這里(Linux LVM類型的ID)后續(xù)擴(kuò)展需要用到
/dev/sda2 64 2611 20458496 8e Linux LVM
#/dev/sdb盤還有足夠的空間
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
#2、創(chuàng)建磁盤分區(qū)
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xac7c929b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
#輸入 p 回車
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b
Device Boot Start End Blocks Id System
#輸入“n”
Command (m for help): n
Command action
e extended
p primary partition (1-4)
#輸入“p”
p
#直接回車,使用默認(rèn)值
Partition number (1-4): 1#分區(qū)號(hào)
First cylinder (1-2610, default 1): #回車用默認(rèn)的
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): #回車用默認(rèn)的
Using default value 2610
Command (m for help): t #改變類型
Selected partition 1
#這里使用上述查詢出來的具體ID值
Hex code (type L to list codes): 8e #LVM的分區(qū)代碼
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 8e Linux LVM
#輸入“w”完成磁盤分區(qū)的創(chuàng)建
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#3、刷新磁盤分區(qū)的創(chuàng)建信息
[root@localhost ~]# partprobe
#將磁盤分區(qū)表變化信息通知內(nèi)核,請(qǐng)求操作系統(tǒng)重新加載分區(qū)表,有些小報(bào)錯(cuò)不要緊。
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
3、創(chuàng)建物理卷
#1、查詢當(dāng)前物理卷信息
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00083529
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac7c929b
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 8e Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes
255 heads, 63 sectors/track, 2285 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
#2、創(chuàng)建新的物理卷
[root@localhost ~]# pvcreate /dev/sdb1
#由fdisk -l查到LVM卷是/dev/sdb1,所以用/dev/sdb1來創(chuàng)建物理卷。
Physical volume "/dev/sdb1" successfully created
4、擴(kuò)展物理卷
#1、查詢卷組信息
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID qkBdcn-RQaR-ZliO-Ja2S-RhMC-stw8-CO213I
"/dev/sdb1" is a new physical volume of "19.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 19.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID H7tDqG-6AZv-yBSA-U0ov-Ni0y-dlPA-kAA83i
#2、擴(kuò)展物理卷組(注意這里的“VolGroup”,這是上面查詢處理的【VG Name】需要保持一致,替換成自己的磁盤名稱)
[root@localhost ~]# vgextend VolGroup /dev/sdb1
Volume group "VolGroup" successfully extended
You have new mail in /var/spool/mail/root
#3、查詢擴(kuò)展后物理磁盤卷組信息
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
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 39.50 GiB
PE Size 4.00 MiB
Total PE 10112
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 5118 / 19.99 GiB
VG UUID dc0vI9-KzGu-4S59-A1xv-NM4Y-rYBF-3jDNRn
5、擴(kuò)展邏輯卷
#1、擴(kuò)展邏輯分區(qū)磁盤(注意這里的路徑需要換成自己的,使用fdisk -l命令可查詢得到)
[root@localhost ~]# lvextend -l +100%free /dev/mapper/VolGroup-lv_root
#free也可以大寫FREE
Extending logical volume lv_root to 37.50 GiB
Logical volume lv_root successfully resized
[root@localhost ~]# blkid /dev/mapper/VolGroup-lv_root
#查看分區(qū)文件系統(tǒng)類型
/dev/mapper/VolGroup-lv_root: UUID="972fdddd-ddb8-469f-a342-e075eaeabeb2" TYPE="ext4"
#2、檢查分區(qū)
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_root
#e2fsck -f檢查分區(qū)
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/VolGroup-lv_root is mounted.
e2fsck: Cannot continue, aborting.
#3、根據(jù)具體的糞污文件系統(tǒng)類型執(zhí)行不同的命令
[root@localhost ~]# resize2fs /dev/mapper/VolGroup-lv_root
#如果分區(qū)是xfs系統(tǒng),則用xfs_growfs命令對(duì)文件系統(tǒng)進(jìn)行擴(kuò)展
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 9830400 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 9830400 blocks long.
[root@localhost ~]# df -h
#查看磁盤空間,根分區(qū)已擴(kuò)展到37G。
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 37G 7.0G 29G 20% /
tmpfs 2.0G 224K 2.0G 1% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/sr0 3.6G 3.6G 0 100% /media/cdrom
特別說明:不同的文件系統(tǒng)執(zhí)行不同的命令,例如:文章來源地址http://www.zghlxwxcb.cn/news/detail-605960.html
-
ext4類型,則使用命令:resize2fs /dev/mapper/VolGroup-lv_root
-
xfs類型,則使用命令:xfs_growfs /dev/mapper/VolGroup-lv_root
到了這里,關(guān)于centos邏輯分區(qū)磁盤擴(kuò)展的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!