无福消瘦 發表於 2019-9-3 14:41:00

centos 根目录扩容

<ol start="0">
<li>添加一块磁盘<br>
参考上一篇博文VMware Workstation 添加磁盘 挂载目录(centos)</li>
</ol>
<hr>
<ol>
<li>查看当前磁盘挂载情况</li>
</ol>
<pre><code># fdisk -l
Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bd826

   Device Boot      Start         End      Blocks   IdSystem
/dev/sda1   *      2048   2099199   1048576   83Linux
/dev/sda2         20992001048575999   523238400   8eLinux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x2890866a

   Device Boot      Start         End      Blocks   IdSystem
/dev/sdb1            2048   209715199   104856576   83Linux

Disk /dev/sdc: 107.4 GB, 107374182400 bytes, 209715200 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-root: 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 /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: 480.0 GB, 479954206720 bytes, 937410560 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>
<hr>
<ol start="2">
<li>磁盘分区</li>
</ol>
<pre><code># fdisk /dev/sdc //选择操作的磁盘
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb9ce2594.

Command (m for help): p//查看磁盘分区情况(当前未分区)

Disk /dev/sdc: 107.4 GB, 107374182400 bytes, 209715200 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: 0xb9ce2594

Device Boot      Start         End      Blocks   IdSystem

Command (m for help): n //重新分区
Partition type:
p   primary (0 primary, 0 extended, 4 free)
e   extended
Select (default p): p//主分区
Partition number (1-4, default 1)://主分区编号 默认即可
First sector (2048-209715199, default 2048)://主分区开始扇区 默认即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199)://主分区结束扇区 默认即可
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t //更改分区的系统id
Selected partition 1

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 &lt;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 &lt;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 //选择8e(lvm)
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p//查看分区情况

Disk /dev/sdc: 107.4 GB, 107374182400 bytes, 209715200 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: 0xb9ce2594

Device Boot      Start         End      Blocks   IdSystem
/dev/sdc1            2048   209715199   104856576   8eLinux LVM

Command (m for help): w //保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
</code></pre>
<hr>
<ol start="3">
<li>创建物理卷</li>
</ol>
<pre><code># pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
# pvdisplay// 查看物理卷信息
--- Physical volume ---
PV Name               /dev/sda2
VG Name               centos
PV Size               &lt;499.00 GiB / not usable 3.00 MiB
Allocatable         yes
PE Size               4.00 MiB
Total PE            127743
Free PE               1
Allocated PE          127742
PV UUID               3ajula-aPHg-hffV-1iC5-N7yq-aQjk-wVze0M

"/dev/sdc1" is a new physical volume of "&lt;100.00 GiB"
--- NEW Physical volume ---
PV Name               /dev/sdc1
VG Name
PV Size               &lt;100.00 GiB
Allocatable         NO
PE Size               0
Total PE            0
Free PE               0
Allocated PE          0
PV UUID               w2DoiS-Vvz7-jm0E-ofTL-mebV-9d9E-PYwa8s

# vgdisplay // 查看物理卷信息
--- Volume group ---
VG Name               centos
System ID
Format                lvm2
Metadata Areas      1
Metadata Sequence No4
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               &lt;499.00 GiB
PE Size               4.00 MiB
Total PE            127743
Alloc PE / Size       127742 / 498.99 GiB
FreePE / Size       1 / 4.00 MiB //此时没有扩展内存
VG UUID               X10fAx-IgS1-V7fr-1VSd-jzjT-4ufc-mxD24J
</code></pre>
<hr>
<ol start="4">
<li>将新增加的分区/dev/sdc1加入到根目录分区centos中</li>
</ol>
<pre><code># vgextend centos /dev/sdc1
Volume group "centos" successfully extended
# vgdisplay// 查看物理卷信息
--- Volume group ---
VG Name               centos
System ID
Format                lvm2
Metadata Areas      2
Metadata Sequence No5
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               598.99 GiB
PE Size               4.00 MiB
Total PE            153342
Alloc PE / Size       127742 / 498.99 GiB
FreePE / Size       25600 / 100.00 GiB//此时扩展内存为100G
VG UUID               X10fAx-IgS1-V7fr-1VSd-jzjT-4ufc-mxD24J
</code></pre>
<hr>
<ol start="5">
<li>进行卷扩容</li>
</ol>
<pre><code># lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
</code></pre>
<hr>
<ol start="6">
<li>调整卷分区大小</li>
</ol>
<pre><code># xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3276800 blks
      =                     sectsz=512   attr=2, projid32bit=1
      =                     crc=1      finobt=0 spinodes=0
data   =                     bsize=4096   blocks=13107200, imaxpct=25
      =                     sunit=0      swidth=0 blks
naming   =version 2            bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
      =                     sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 39321600
</code></pre>
<hr>
<ol start="7">
<li>查看扩容结果</li>
</ol>
<pre><code># df -Th
Filesystem            Type      SizeUsed Avail Use% Mounted on
/dev/mapper/centos-root xfs       150G   49G102G33% /   //扩容成功
devtmpfs                devtmpfs3.8G   03.8G   0% /dev
tmpfs                   tmpfs   3.9G   03.9G   0% /dev/shm
tmpfs                   tmpfs   3.9G   12M3.8G   1% /run
tmpfs                   tmpfs   3.9G   03.9G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M142M873M14% /boot
/dev/mapper/centos-home xfs       447G1.2G446G   1% /home
tmpfs                   tmpfs   781M   0781M   0% /run/user/0
</code></pre>
<p>此文为本人原创文章,转载请注明出处!!!</p><br><br>
来源:https://www.cnblogs.com/lillcol/p/11452915.html
頁: [1]
查看完整版本: centos 根目录扩容