使用LVM将新硬盘添加到现有的Linux系统中-演道网

LVM(逻辑卷管理)是一种灵活和高级的选项,可用于管理大多数主要Linux发行版的硬盘。 使用LVM管理磁盘比传统的工具(如fdisk , parted或gparted)容易。

目录

  • 1.查看当前硬盘及分区情况
  • 2.初始化/dev/sdb为PV(physical volume)
  • 3.PV加入至VG组。
  • 4.创建lv
  • 5.格式化逻辑分区
  • 6.挂载硬盘/data
  • 7.迁移zabbix的mysql数据库(附加操作)

1.查看当前硬盘及分区情况

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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

其中/dev/sdb是我需要增加的硬盘

2.初始化/dev/sdb为PV(physical volume)

命令如下:

[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@localhost ~]# pvdisplay
  "/dev/sdb" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5d602Y-xPFg-RWj8-OUcS-H6M4-Rkn4-UXWofX

3.PV加入至VG组。

[root@localhost ~]# vgcreate VGroup00 /dev/sdb
  Volume group "VGroup00" successfully created
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               100.00 GiB
  PE Size               4.00 MiB
  Total PE              25599
  Alloc PE / Size       0 / 0   
  Free  PE / Size       25599 / 100.00 GiB
  VG UUID               dxt5j1-EM7w-C24F-y0Fm-ZbW4-6LfY-IbIfY2

4.创建lv

[root@localhost ~]# lvcreate -l +100%free -n LVol00 VGroup00
  Logical volume "LVol00" created.
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VGroup00/LVol00
  LV Name                LVol00
  VG Name                VGroup00
  LV UUID                DVpdmE-JOJi-WvtU-gHVy-okP3-cw2s-Vfl1eh
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain.localdomain, 2019-10-28 09:39:34 +0800
  LV Status              available
  # open                 0
  LV Size                100.00 GiB
  Current LE             25599
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

以上命令,把所有的空闲空间划至/dev/VGroup00/LVol00空间中。

5.格式化逻辑分区

[root@localhost ~]# mkfs.ext4 /dev/VGroup00/LVol00
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26213376 blocks
1310668 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
800 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

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

6.挂载硬盘/data

[root@localhost ~]# mkdir -p /data
[root@localhost ~]# mount /dev/VGroup00/LVol00 /data
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              29G   26G  2.4G  92% /
tmpfs                 3.9G  4.0K  3.9G   1% /dev/shm
/dev/sda1             477M  105M  347M  24% /boot
/dev/mapper/VGroup00-LVol00
                       99G   60M   94G   1% /data

7.迁移zabbix的mysql数据库(附加操作)

原来mysql的数据目录在/var/lib/mysql。把它
迁移至/data/mysql目录中。

7.1 关闭相关服务

service zabbix-server stop
service httpd stop
service mysqld stop

7.2 迁移目录

[root@localhost ~]# cd /var/lib/
[root@localhost lib]# mv mysql /data/

mkdir -p /var/lib/mysql
chown -R mysql:mysql mysql

7.3 修改my.cnf

# Remove leading # and set to the amount of RAM for the most important data
# Remove leading # to turn on a very important data integrity option: logging<

转载自演道,想查看更及时的互联网产品技术热点文章请点击http://go2live.cn

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注