CentOS 7 根目录分区扩容
<ol><li>查看现有磁盘信息,可以看出根分区有96G</li>
</ol>
<pre><code># df -h
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/centos-root 96G2.0G 94G 3% /
devtmpfs 2.0G 02.0G 0% /dev
tmpfs 2.0G 02.0G 0% /dev/shm
tmpfs 2.0G8.5M2.0G 1% /run
tmpfs 2.0G 02.0G 0% /sys/fs/cgroup
/dev/sda1 1014M163M852M17% /boot
tmpfs 396M 0396M 0% /run/user/0
</code></pre>
<ol start="2">
<li>查看新增加的磁盘信息</li>
</ol>
<ul>
<li>fdisk</li>
</ul>
<pre><code># fdisk -l
Disk /dev/sda: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f
Device Boot Start End Blocks IdSystem
/dev/sda1 * 2048 2099199 1048576 83Linux
/dev/sda2 2099200 209715199 103808000 8eLinux LVM
Disk /dev/mapper/centos-root: 102.1 GB, 102131302400 bytes, 199475200 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: 4160 MB, 4160749568 bytes, 8126464 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
</code></pre>
<ul>
<li>parted</li>
</ul>
<pre><code># parted -l
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
NumberStart End Size Type File systemFlags
1 1049kB1075MB1074MBprimaryxfs boot
2 1075MB107GB 106GB primary lvm
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
NumberStartEnd Size File system Flags
1 0.00B4161MB4161MBlinux-swap(v1)
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 102GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
NumberStartEnd Size File systemFlags
1 0.00B102GB102GBxfs
</code></pre>
<ol start="3">
<li>根据以上信息,对新增加的磁盘进行分区</li>
</ol>
<pre><code># 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): m
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): p
Disk /dev/sda: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f
Device Boot Start End Blocks IdSystem
/dev/sda1 * 2048 2099199 1048576 83Linux
/dev/sda2 2099200 209715199 103808000 8eLinux LVM
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (209715200-977272831, default 209715200):
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-977272831, default 977272831):
Using default value 977272831
Partition 3 of type Linux and of size 366 GiB is set
Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): L
0Empty 24NEC DOS 81Minix / old Lin bfSolaris
1FAT12 27Hidden NTFS Win 82Linux swap / So c1DRDOS/sec (FAT-
2XENIX root 39Plan 9 83Linux c4DRDOS/sec (FAT-
3XENIX usr 3cPartitionMagic84OS/2 hidden C:c6DRDOS/sec (FAT-
4FAT16 <32M 40Venix 80286 85Linux extendedc7Syrinx
5Extended 41PPC PReP Boot 86NTFS volume set daNon-FS data
6FAT16 42SFS 87NTFS volume set dbCP/M / CTOS / .
7HPFS/NTFS/exFAT 4dQNX4.x 88Linux plaintext deDell Utility
8AIX 4eQNX4.x 2nd part 8eLinux LVM dfBootIt
9AIX bootable 4fQNX4.x 3rd part 93Amoeba e1DOS access
aOS/2 Boot Manag 50OnTrack DM 94Amoeba BBT e3DOS R/O
bW95 FAT32 51OnTrack DM6 Aux 9fBSD/OS e4SpeedStor
cW95 FAT32 (LBA) 52CP/M a0IBM Thinkpad hi ebBeOS fs
eW95 FAT16 (LBA) 53OnTrack DM6 Aux a5FreeBSD eeGPT
fW95 Ext'd (LBA) 54OnTrackDM6 a6OpenBSD efEFI (FAT-12/16/
10OPUS 55EZ-Drive a7NeXTSTEP f0Linux/PA-RISC b
11Hidden FAT12 56Golden Bow a8Darwin UFS f1SpeedStor
12Compaq diagnost 5cPriam Edisk a9NetBSD f4SpeedStor
14Hidden FAT16 <3 61SpeedStor abDarwin boot f2DOS secondary
16Hidden FAT16 63GNU HURD or Sys afHFS / HFS+ fbVMware VMFS
17Hidden HPFS/NTF 64Novell Netwareb7BSDI fs fcVMware VMKCORE
18AST SmartSleep65Novell Netwareb8BSDI swap fdLinux raid auto
1bHidden W95 FAT3 70DiskSecure Mult bbBoot Wizard hid feLANstep
1cHidden W95 FAT3 75PC/IX beSolaris boot ffBBT
1eHidden W95 FAT1 80Old Minix
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: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f
Device Boot Start End Blocks IdSystem
/dev/sda1 * 2048 2099199 1048576 83Linux
/dev/sda2 2099200 209715199 103808000 8eLinux LVM
/dev/sda3 209715200 977272831 383778816 8eLinux LVM
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.
</code></pre>
<blockquote>
<p>重启系统后,登陆系统。(一定要重启系统,否则可能无法继续下面的操作扩充新分区)</p>
</blockquote>
<blockquote>
<p>同时在进行下一步之前,说明一下pv、vg、lv的关系。</p>
<blockquote>
<p>一个硬盘f分区组成一个pv(物理卷)<br>
一个或者多个pv组成一个vg(卷组)<br>
一个vg可以划分出多个lv(逻辑卷)</p>
</blockquote>
</blockquote>
<ol start="4">
<li>查看物理卷</li>
</ol>
<pre><code># lvs
LV VG Attr LSize Pool Origin Data%Meta%Move Log Cpy%Sync Convert
root centos -wi-ao---- <95.12g
swap centos -wi-ao----<3.88g
</code></pre>
<ol start="5">
<li>创建物理卷</li>
</ol>
<ul>
<li>格式化分区(非必需,先格式化后面创建物理卷还是会擦除)</li>
</ul>
<pre><code># 查看系统的文件类型
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root xfs 99688900 202899697659904 3% /
devtmpfs devtmpfs 2010736 0 2010736 0% /dev
tmpfs tmpfs 2022628 0 2022628 0% /dev/shm
tmpfs tmpfs 2022628 8676 2013952 1% /run
tmpfs tmpfs 2022628 0 2022628 0% /sys/fs/cgroup
/dev/sda1 xfs 1038336166632 87170417% /boot
tmpfs tmpfs 404528 0 404528 0% /run/user/0
# 格式化为xfs
# mkfs.xfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=23986176 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=95944704, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=46848, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
</code></pre>
<ul>
<li>创建物理卷</li>
</ul>
<pre><code># pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? : y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
</code></pre>
<ol start="6">
<li>查看物理卷信息</li>
</ol>
<pre><code># pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 1
Allocated PE 25342
PV UUID 00mdqs-YJl2-Oq3k-OlGb-7mbi-iTtz-HJl7cw
"/dev/sda3" is a new physical volume of "366.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 366.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 6PYry3-VIRi-7DUc-5erS-yCEo-Laxu-ZkoYPo
# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No3
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 <99.00 GiB
PE Size 4.00 MiB
Total PE 25343
Alloc PE / Size 25342 / 98.99 GiB
FreePE / Size 1 / 4.00 MiB
VG UUID yde5y3-OOS3-UmyT-iHwv-zwJ5-yE63-9ZHI9O
</code></pre>
<ol start="7">
<li>将新增加的分区 /dev/sda3 加入到根目录分区中,也就是上面的VG Name: centos</li>
</ol>
<pre><code># vgextend centos /dev/sda3
Volume group "centos" successfully extended
</code></pre>
<ol start="8">
<li>重新查看卷组信息</li>
</ol>
<pre><code># vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No4
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 464.99 GiB
PE Size 4.00 MiB
Total PE 119038
Alloc PE / Size 25342 / 98.99 GiB
FreePE / Size 93696 / 366.00 GiB
VG UUID yde5y3-OOS3-UmyT-iHwv-zwJ5-yE63-9ZHI9O
</code></pre>
<ol start="9">
<li>进行卷扩容</li>
</ol>
<ul>
<li>扩容前</li>
</ul>
<pre><code># df -h
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/centos-root 96G2.0G 94G 3% /
devtmpfs 2.0G 02.0G 0% /dev
tmpfs 2.0G 02.0G 0% /dev/shm
tmpfs 2.0G8.5M2.0G 1% /run
tmpfs 2.0G 02.0G 0% /sys/fs/cgroup
/dev/sda1 1014M163M852M17% /boot
tmpfs 396M 0396M 0% /run/user/0
</code></pre>
<ul>
<li>进行卷扩容</li>
</ul>
<pre><code># lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from <95.12 GiB (24350 extents) to <461.12 GiB (118046 extents).
Logical volume centos/root successfully resized.
</code></pre>
<ol start="10">
<li>调整卷分区大小</li>
</ol>
<pre><code># xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=6233600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=24934400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=12175, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 24934400 to 120879104
</code></pre>
<ol start="11">
<li>最后,查看磁盘信息可以看出根目录分区大小已成功扩容。</li>
</ol>
<pre><code># df -h
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/centos-root462G2.0G460G 1% /
devtmpfs 2.0G 02.0G 0% /dev
tmpfs 2.0G 02.0G 0% /dev/shm
tmpfs 2.0G8.5M2.0G 1% /run
tmpfs 2.0G 02.0G 0% /sys/fs/cgroup
/dev/sda1 1014M163M852M17% /boot
tmpfs 396M 0396M 0% /run/user/0
</code></pre><br><br>
来源:https://www.cnblogs.com/lokion/p/10998317.html
頁:
[1]