添加磁盘及拓展

配置硬盘-添加磁盘-mount

配置说明

在该情景下,扩展硬盘已经添加,而我们要做的就是把这个新加的硬盘挂载到指定的目录,于是指定的目录就有了更多的空间。

比如说我们新加的盘挂载到 disk01 目录,于是效果就成了这样

[root@iZvv70fyhxewafqxnq26rfZ /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
# 将新加的盘 /dev/vdb1 挂载到了 /disk01目录下
/dev/vdb1       493G   73M  467G   1% /disk01
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G   24M   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vda3        39G  1.9G   35G   6% /
/dev/vda2       976M   89M  821M  10% /boot
tmpfs           3.2G     0  3.2G   0% /run/user/0

步骤总揽

① 创建挂载目录(挂载点)

② 查看扩展盘

③ 对新加的盘分区

④ 格式化分区

⑤ 设置自动挂载

⑥ 挂载

1. 查看磁盘的挂载信息和当前的目录信息

# 查看根目录
[root@iZvv70fyhxewafqxnq26rfZ ~]# cd /

# 当前目录下,没有disk01目录
[root@iZvv70fyhxewafqxnq26rfZ /]# ll
total 60
lrwxrwxrwx.   1 root root     7 Mar 11  2020 bin -> usr/bin
dr-xr-xr-x.   5 root root  4096 Apr 14 13:39 boot
drwxr-xr-x   17 root root  2920 Apr 14 13:39 dev
drwxr-xr-x.  87 root root  4096 Apr 14 13:39 etc
drwxr-xr-x.   2 root root  4096 Sep 29  2018 home
drwxr-xr-x.   4 root root  4096 Mar 11  2020 opt
dr-xr-xr-x  150 root root     0 Jan  1  1970 proc
dr-xr-x---.   6 root root  4096 Apr 14 13:39 root

# 查看当前磁盘的挂载信息
[root@iZvv70fyhxewafqxnq26rfZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G   25M   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vda3        39G  1.5G   35G   5% /
/dev/vda2       976M   89M  821M  10% /boot
tmpfs           3.2G     0  3.2G   0% /run/user/0

2. 查看系统分区信息,获取新添加的硬盘信息

# 重新扫描磁盘
[root@iZvv70fyhxewafqxnq26rfZ /]# partprobe

# 列出系统分区,可以看到新加的硬盘为 /dev/vdb1
[root@iZvv70fyhxewafqxnq26rfZ /]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x00054e7d

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      411647      204800   83  Linux
/dev/vda2          411648     2508799     1048576   83  Linux
/dev/vda3         2508800    83884031    40687616   83  Linux

Disk /dev/vdb: 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: 0xd290047c

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  1048575999   524286976   8e  Linux LVM

3. 对新加的盘进行分区

[root@iZvv70fyhxewafqxnq26rfZ /]# fdisk /dev/vdb
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 0xd290047c.

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): 1
First sector (2048-1048575999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): 
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

Calling ioctl() to re-read partition table.
Syncing disks.

说明:

fdisk /dev/sdb   对sdb进行分区
n 创建分区
p 创建主分区
1 设置分区号
enter 设置分区大小
p 打印当前分区表
w 保存更新

4. 格式化新分区

[root@iZvv70fyhxewafqxnq26rfZ /]# mkfs.ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131071744 blocks
6553587 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done    

5. 创建挂载点mkdir /disk01(挂载路径和目录可以自定义)

# 创建磁盘 disk01
[root@iZvv70fyhxewafqxnq26rfZ /]# mkdir disk01

6. 修改 fstab 文件使磁盘在开机时能够自动挂载

[root@iZvv70fyhxewafqxnq26rfZ /]# vim /etc/fstab
# 添加以下内容
/dev/vdb1  /disk01 ext4 defaults 0 0

7. 挂载并查看

[root@iZvv70fyhxewafqxnq26rfZ /]# mount -a
[root@iZvv70fyhxewafqxnq26rfZ /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G   24M   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vda3        39G  1.9G   35G   6% /
/dev/vda2       976M   89M  821M  10% /boot
tmpfs           3.2G     0  3.2G   0% /run/user/0
/dev/vdb1       493G   73M  467G   1% /disk01

配置硬盘-LVM 新加盘扩展

执行流程

① 查看是否采用了逻辑分区

② 扫描磁盘信息

③ 对新加载的磁盘进行分区

④ 查看当前物理卷

⑤ 创建新的物理卷

⑥ 增加原卷组大小

⑦ 对指定的逻辑卷扩容

1. 查看是否采用了逻辑分区

执行命令,如果没有反馈,需要联系管理员增加需求大小的磁盘

[root@nk-bdata ~]# lvs
LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root centos -wi-ao---- <795.17g                                                    
swap centos -wi-ao----    4.00g 

2. 扫描磁盘信息

[root@nk-bdata ~]# fdisk -l

Disk /dev/sda: 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 label type: dos
Disk identifier: 0x000b17d5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1640447      819200   83  Linux
/dev/sda2         1640448   104857599    51608576   8e  Linux LVM

Disk /dev/sdc: 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: 0xf84daa89

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  1048575999   524286976   8e  Linux LVM

Disk /dev/sdb: 268.4 GB, 268435456000 bytes, 524288000 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: 0x0c12b29a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   524287999   262142976   8e  Linux LVM

Disk /dev/mapper/centos-root: 853.8 GB, 853805105152 bytes, 1667588096 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: 4294 MB, 4294967296 bytes, 8388608 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

3. 对新加磁盘分区

[root@iZvv70fyhxewafqxnq26rfZ /]# 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 0xd290047c.
  
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): 1
First sector (2048-1048575999, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): 
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
  
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
  
Command (m for help): w
The partition table has been altered!
  
Calling ioctl() to re-read partition table.
Syncing disks.

4. 查看当前物理卷

[root@nk-bdata ~]# pvs
PV         VG     Fmt  Attr PSize    PFree 
/dev/sda2  centos lvm2 a--    49.21g     0 
/dev/sdb1  centos lvm2 a--  <250.00g     0 

# 创建新的物理卷
[root@nk-bdata ~]# pvcreate /dev/sdc1
Physical volume "dev/sdc1" successfully created.

# 查看当前的物理卷
[root@nk-bdata ~]# pvs
PV         VG     Fmt  Attr PSize    PFree 
/dev/sda2  centos lvm2 a--    49.21g     0 
/dev/sdb1  centos lvm2 a--  <250.00g     0 
/dev/sdc1  centos lvm2 a--  <500.00g 40.00m

5. 对原卷组进行扩容

# 对原卷组进行扩容
[root@nk-bdata ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended

# 再次查看物理卷
/dev/sdc1  centos lvm2 a--  <500.00g 40.00m

6. 给需要的逻辑卷扩容

# 对根目录进行扩容
[root@nk-bdata ~] lvextend --resize -L +500G /dev/centos/root


# 查看逻辑卷相关信息
[root@nk-bdata ~]# lvs
LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
root centos -wi-ao---- <795.17g                                                    
swap centos -wi-ao----    4.00g         
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值