«

LVM XFS增加硬盘根分区容量

指尖二进制 • 1 年前 • 872 次点击 • LINUX


这里增加根分区大小

[root@bogon ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   38G  975M   37G    3% /
devtmpfs                 903M     0  903M    0% /dev
tmpfs                    913M     0  913M    0% /dev/shm
tmpfs                    913M  8.6M  904M    1% /run
tmpfs                    913M     0  913M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                    183M     0  183M    0% /run/user/0
[root@bogon ~]# fdisk -l

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b962c

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM

磁盘 /dev/mapper/centos-root:40.2 GB, 40227569664 字节,78569472 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

进行分区:

[root@bogon ~]# fdisk /dev/sdb 
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x7ec239df 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

重启服务器或者 partprobe

[root@bogon ~]# partprobe
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。

创建物理卷

[root@bogon ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

使用vgscan查询物理卷

[root@bogon ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "centos" using metadata type lvm2

使用新增物理卷扩展vg

[root@bogon ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

使用vgscan查询物理卷

[root@bogon ~]# vgscan 
  Reading all physical volumes.  This may take a while...
  Found volume group "centos" using metadata type lvm2

查询vg

[root@bogon ~]# 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               59.50 GiB
  PE Size               4.00 MiB
  Total PE              15233
  Alloc PE / Size       10103 / 39.46 GiB
  Free  PE / Size       5130 / 20.04 GiB
  VG UUID               TC5T4b-TqhV-31ce-uRMw-DWGe-i1NE-ASog0l

查询lv

[root@bogon ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                kIyK4E-UpXq-hlCu-2Opo-mOnR-f7ee-kHkbiD
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-09-23 21:07:40 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2xvCNH-dOB4-h3of-PSQy-bnVJ-fwR3-v58F0H
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-09-23 21:07:41 +0800
  LV Status              available
  # open                 1
  LV Size                37.46 GiB
  Current LE             9591
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

扩展lv

[root@bogon ~]# lvextend -L +20G /dev/mapper/centos-root
 GiB (14711 extents).
  Logical volume root successfully resized.

若不是xfs我们可以用resize2fs

[root@Mysql01-213-66 ~]# resize2fs -f /dev/mapper/vg_mysql0121366-LogVol01
resize2fs 1.41.12 (17-May-2010)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/vg_mysql0121366-LogVol01
Couldn't find valid filesystem superblock.

[root@bogon ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=2455296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=9821184, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=4795, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9821184 to 15064064

查看根分区已经扩容了

[root@bogon ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   58G  975M   57G    2% /
devtmpfs                 903M     0  903M    0% /dev
tmpfs                    913M     0  913M    0% /dev/shm
tmpfs                    913M  8.6M  904M    1% /run
tmpfs                    913M     0  913M    0% /sys/fs/cgroup
/dev/sda1                497M  125M  373M   25% /boot
tmpfs                    183M     0  183M    0% /run/user/0
还没收到回复