Centos为硬盘新增容量分区并挂载到根目录

1.查看硬盘的情况。

 

可以看到硬盘新增了大小,但是没有被用起来。

下面我要做的其实就是lvm扩展

[root@Slave2 ~]# 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): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x0001784c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux 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): 3
First sector (33554432-838860799, default 33554432): 33554432
Last sector, +sectors or +size{K,M,G} (33554432-838860799, default 838860799): 838860799
Partition 3 of type Linux and of size 384 GiB is set

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x0001784c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM
/dev/sda3        33554432   838860799   402653184   83  Linux

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@Slave2 ~]#

 

用 partprobe /dev/sda3 没有启作用,重启后生效

可以看到sda3为刚刚新增的分区。

开始扩容:

创建物理卷:

[root@Slave2 ~]# lvm
lvm> pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
lvm> 

查看物理卷和卷组:

lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <15.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               0
  Allocated PE          3839
  PV UUID               VZ9vj7-442j-SGbv-3ZRj-gdDs-kQuK-YIPcEj
   
  "/dev/sda3" is a new physical volume of "384.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               384.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               TRQMxO-ouRd-E4GM-mL60-R4Ub-3FsX-BjiXZF
   
lvm> 

 

将物理卷加入到卷组:

   
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               398.99 GiB
  PE Size               4.00 MiB
  Total PE              102142
  Alloc PE / Size       3839 / <15.00 GiB
  Free  PE / Size       98303 / <384.00 GiB
  VG UUID               e6v5QC-dUMm-yUWn-KSy7-5eOx-ttq6-5eyDID
   
lvm> 

 

将卷组剩余空间添加到逻辑卷组 /dev/centos/root

lvm> lvextend -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 397.39 GiB (101732 extents).
  Logical volume centos/root successfully resized.
lvm> 

同步到文件系统

lvm> exit
  Exiting.
[root@Slave2 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=877824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3511296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3511296 to 104173568
[root@Slave2 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.8M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  398G  9.9G  388G   3% /
/dev/sda1               1014M  150M  865M  15% /boot
tmpfs                    1.6G     0  1.6G   0% /run/user/0
[root@Slave2 ~]# 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
CentOS中添加硬盘并扩容到根分区的步骤如下: 1. 首先,确保你已经连接好了新的硬盘到计算机,并且已经被识别到了系统中。你可以通过使用`sudo fdisk -l`命令来查看所有已连接的硬盘分区。 2. 接下来,使用`sudo fdisk /dev/sdX`命令(X代表新硬盘的设备名)来对新硬盘进行分区。按下n创建新分区,然后选择主分区或扩展分区,然后设置分区的起始和结束柱面等信息。 3. 分区创建完成后,我们需要将新分区格式化为文件系统。使用`sudo mkfs.ext4 /dev/sdX1`命令(X代表新分区的序号)将分区格式化为ext4文件系统。 4. 接下来,我们需要将新分区挂载到系统中。首先创建一个目录作为挂载点,比如`sudo mkdir /mnt/newdisk`。然后使用`sudo mount /dev/sdX1 /mnt/newdisk`命令将新分区挂载到该目录上。 5. 现在我们可以将根分区的数据复制到新硬盘上。使用`sudo rsync -avxHAX / /mnt/newdisk`命令来复制根分区的数据。这可能需要一些时间,所以请耐心等待。 6. 复制完成后,我们需要更新/boot/grub/menu.lst文件以指向新硬盘的根分区。打开该文件,找到原来的根分区的设备名,并将其替换为新硬盘的设备名。 7. 最后,我们需要更新grub并重新启动。使用`sudo grub-install /dev/sdX`命令,将grub安装到新硬盘上。然后,使用`sudo reboot`命令重新启动计算机。 在重启后,系统将会使用新硬盘的扩容根分区运行。你可以使用`df -h`命令来检查根分区的大小是否已经扩容成功。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值