aliyun添加数据盘后的物理分区和lvm逻辑卷两种挂载方式

一、普通磁盘分区管理方式

1.对磁盘进行分区
列出磁盘
# fdisk -l


# 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 0x4765885b.


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


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


Calling ioctl() to re-read partition table.
Syncing disks.
# 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: 0x635e6c7d


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048    83886079    41942016   83  Linux


Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0x4765885b


   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  2097151999  1048574976   83  Linux


2.对磁盘格式化成ext4格式
# 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
65536000 inodes, 262143744 blocks
13107187 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2409627648
8000 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, 214990848


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


3.将新的磁盘挂载在/data目录下
mkdir /data
# mount /dev/vdb1 /data


查看是否挂载成功
# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      ext4       40G  1.3G   37G   4% /
devtmpfs       devtmpfs   32G     0   32G   0% /dev
tmpfs          tmpfs      32G     0   32G   0% /dev/shm
tmpfs          tmpfs      32G  292K   32G   1% /run
tmpfs          tmpfs      32G     0   32G   0% /sys/fs/cgroup
tmpfs          tmpfs     6.3G     0  6.3G   0% /run/user/0
/dev/vdb1      ext4      985G   77M  935G   1% /data


4.添加自动挂载,重启系统后依然生效


vim /etc/fstab
/dev/vdb1 /data ext4 defaults 0 0


二、逻辑卷的方式

安装逻辑卷管理、vim、unzip、iftop等工具
yum install -y lvm2 vim unzip iftop


# 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: 0x635e6c7d


   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048    83886079    41942016   83  Linux


Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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




# 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 0x31ab9b87.


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

# 更加规范的做法是在分区时需要一个修改磁盘分区格式为linux lvm 代码为8e的操作

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


Calling ioctl() to re-read partition table.
Syncing disks.
# cat /proc/partitions
major minor  #blocks  name


  11        0    1048575 sr0
 253        0   41943040 vda
 253        1   41942016 vda1
 253       16 2097152000 vdb
 253       17 2097150976 vdb1


# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created.
# vgcreate myvg /dev/vdb1
  Volume group "myvg" successfully created
# vgdisplay 
  --- Volume group ---
  VG Name               myvg
  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               1.95 TiB
  PE Size               4.00 MiB
  Total PE              511999
  Alloc PE / Size       0 / 0   
  Free  PE / Size       511999 / 1.95 TiB
  VG UUID               RpMeCU-gIV2-kEe5-fe6C-8iVI-xe0i-vf4ocp
   
# lvcreate -L 1.95T -n mylv myvg
  Rounding up size to full physical extent 1.95 TiB
  Logical volume "mylv" created.
# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                e1nL7K-0qyc-BHt8-x9oO-1gGC-6qWn-a52o6x
  LV Write Access        read/write
  LV Creation host, time iZ2ze47of4mpxkhhzcgjheZ, 2017-01-07 12:18:26 +0800
  LV Status              available
  # open                 0
  LV Size                1.95 TiB
  Current LE             511181
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
# mke2fs -t ext4 -b 2048 /dev/myvg/mylv 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
130863104 inodes, 1046898688 blocks
52344934 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1315438592
63898 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 
2048000, 3981312, 5619712, 10240000, 11943936, 35831808, 39337984, 
51200000, 107495424, 256000000, 275365888, 322486272, 967458816


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


# mkdir /data
# mount /dev/myvg/mylv /data
# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/vda1             ext4       40G  1.3G   37G   4% /
devtmpfs              devtmpfs   32G     0   32G   0% /dev
tmpfs                 tmpfs      32G     0   32G   0% /dev/shm
tmpfs                 tmpfs      32G  356K   32G   1% /run
tmpfs                 tmpfs      32G     0   32G   0% /sys/fs/cgroup
tmpfs                 tmpfs     6.3G     0  6.3G   0% /run/user/0
/dev/mapper/myvg-mylv ext4      2.0T   24M  1.9T   1% /data

开机自启动挂载分区
vim /etc/fstab
加入以下内容:
/dev/myvg/mylv /data ext4 defaults,noatime 0 0

# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Tue May  3 13:48:10 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=80b9b662-0a1d-4e84-b07b-c1bf19e72d97 /                       ext4    defaults        1 1
/dev/myvg/mylv /data ext4 defaults,noatime 0 0
 

示例

新购买的ECS数据盘1T,用了阿里云的400G数据盘作为模板
登录进去后数据盘只有400G,在控制台关闭ECS,重新初始化磁盘


[root@eus-timed-task01:~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 79G 9.0G 66G 13% /
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
[root@eus-timed-task01:~]# mount -a
[root@eus-timed-task01:~]# mount
/dev/vda1 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

# 想通过格式化/dev/vdb1 成ext4

[root@eus-timed-task01:~]# mkfs.ext4 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
/dev/vdb1 is apparently in use by the system; will not make a filesystem here!

解决办法:
[root@eus-timed-task01:~]# dmsetup status
VG_Data-lv_data: 0 838852608 linear
[root@eus-timed-task01:~]# dmsetup remove_all
[root@eus-timed-task01:~]# demesup status
-bash: demesup: command not found
[root@eus-timed-task01:~]# dmsetup status
No devices found
[root@eus-timed-task01:~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created

# lvm分区
[root@eus-timed-task01:~]# vgcreate /dev/vdb1
Please enter a physical volume path.
Run `vgcreate --help' for more information.
[root@eus-timed-task01:~]# vgcreate myvg /dev/vdb1
Volume group "myvg" successfully created
[root@eus-timed-task01:~]# vgdisplay
--- Volume group ---
VG Name myvg
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 1000.00 GiB
PE Size 4.00 MiB
Total PE 255999
Alloc PE / Size 0 / 0
Free PE / Size 255999 / 1000.00 GiB
VG UUID oeMYkq-8l6C-dHZx-In5b-3m8m-3jj5-dihQ3M

--- Volume group ---
VG Name VG_Data
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 400.00 GiB
PE Size 4.00 MiB
Total PE 102399
Alloc PE / Size 102399 / 400.00 GiB
Free PE / Size 0 / 0
VG UUID 6dlcbY-mLx3-spKv-DUQ3-Av2S-7fVD-ye8JVC

# 100磁盘使用率
[root@eus-timed-task01:~]# lvcreate -l 100%VG -n mylv myvg
Logical volume "mylv" created.
[root@eus-timed-task01:~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID iq0LKn-bDSO-QPAn-C0mV-jADG-vc4W-PRPawO
LV Write Access read/write
LV Creation host, time eus-timed-task01, 2018-08-08 03:00:50 -0700
LV Status available
# open 0
LV Size 1000.00 GiB
Current LE 255999
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Path /dev/VG_Data/lv_data
LV Name lv_data
VG Name VG_Data
LV UUID Yn1sTI-gAop-kodn-cvsN-OYnN-fNES-n7l9uk
LV Write Access read/write
LV Creation host, time iZrj9citgdpobfu83gsgodZ, 2018-06-15 00:05:23 -0700
LV Status NOT available
LV Size 400.00 GiB
Current LE 102399
Segments 1
Allocation inherit
Read ahead sectors auto

[root@eus-timed-task01:~]# mke2fs -t ext4 -b 2048 /dev/myvg/mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 524285952 blocks
26214297 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1061158912
32000 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312, 5619712, 10240000, 11943936, 35831808, 39337984,
51200000, 107495424, 256000000, 275365888, 322486272

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

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@eus-timed-task01:~]# ls /data
[root@eus-timed-task01:~]# mount /dev/myvg/mylv /data
[root@eus-timed-task01:~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 79G 6.2G 69G 9% /
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/mapper/myvg-mylv
ext4 985G 23M 935G 1% /data
[root@eus-timed-task01:~]# vim /etc/fstab
/dev/myvg/mylv /data ext4 defaults,noatime 0 0

# 重新启动看能否正常挂载

逻辑卷扩容的示例


示例:将/aliyun的逻辑卷分区由110G增加到150G


# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               120.00 GiB
  PE Size               4.00 MiB
  Total PE              30719
  Alloc PE / Size       28160 / 110.00 GiB
  Free  PE / Size       2559 / 10.00 GiB
  VG UUID               v5LSS8-E5HW-htEL-ioet-Up3T-zUFz-vtCzlA


[root@mini2 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        30G  1.8G   29G   6% /
devtmpfs                devtmpfs  907M     0  907M   0% /dev
tmpfs                   tmpfs     917M     0  917M   0% /dev/shm
tmpfs                   tmpfs     917M  8.6M  908M   1% /run
tmpfs                   tmpfs     917M     0  917M   0% /sys/fs/cgroup
/dev/mapper/centos-data xfs        40G   33M   40G   1% /data
/dev/mapper/myvg-mylv   ext4      109G   19M  103G   1% /aliyun
/dev/sda1               xfs       297M  115M  183M  39% /boot
tmpfs                   tmpfs     184M     0  184M   0% /run/user/0


1.新增一块60G的硬盘,分区
# 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 0x58d7841e.


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


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


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


2.将新增加的分区/dev/sdc1扩容到物理卷myvg中
# vgextend myvg /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
  Volume group "myvg" successfully extended
# 可以看到由10G扩展到了59.99G
[root@mini2 ~]# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               169.99 GiB
  PE Size               4.00 MiB
  Total PE              43518
  Alloc PE / Size       28160 / 110.00 GiB
  Free  PE / Size       15358 / 59.99 GiB
  VG UUID               v5LSS8-E5HW-htEL-ioet-Up3T-zUFz-vtCzlA


# lvdisplay /dev/myvg/mylv
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                3H0Qgm-tDJr-BJ96-Y0Vh-TMOE-1EZv-DN3qUE
  LV Write Access        read/write
  LV Creation host, time mini2, 2017-01-07 13:55:37 +0800
  LV Status              available
  # open                 1
  LV Size                110.00 GiB
  Current LE             28160
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2


3.扩展物理边界为150G
[root@mini2 ~]# lvextend -L 150G /dev/myvg/mylv
  Size of logical volume myvg/mylv changed from 110.00 GiB (28160 extents) to 150.00 GiB (38400 extents).
  Logical volume mylv successfully resized.
可以看到已经有110变成了150G
[root@mini2 ~]# lvdisplay /dev/myvg/mylv
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                3H0Qgm-tDJr-BJ96-Y0Vh-TMOE-1EZv-DN3qUE
  LV Write Access        read/write
  LV Creation host, time mini2, 2017-01-07 13:55:37 +0800
  LV Status              available
  # open                 1
  LV Size                150.00 GiB
  Current LE             38400
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2


[root@mini2 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        30G  1.8G   29G   6% /
devtmpfs                devtmpfs  907M     0  907M   0% /dev
tmpfs                   tmpfs     917M     0  917M   0% /dev/shm
tmpfs                   tmpfs     917M  8.6M  908M   1% /run
tmpfs                   tmpfs     917M     0  917M   0% /sys/fs/cgroup
/dev/mapper/centos-data xfs        40G   33M   40G   1% /data
/dev/mapper/myvg-mylv   ext4      109G   19M  103G   1% /aliyun
/dev/sda1               xfs       297M  115M  183M  39% /boot
tmpfs                   tmpfs     184M     0  184M   0% /run/user/0


4.扩展逻辑边界,可以看到磁盘分区/aliyun由109G变成了148G
[root@mini2 ~]# resize2fs /dev/myvg/mylv 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /aliyun; on-line resizing required
old_desc_blocks = 110, new_desc_blocks = 150
The filesystem on /dev/myvg/mylv is now 78643200 blocks long.


[root@mini2 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        30G  1.8G   29G   6% /
devtmpfs                devtmpfs  907M     0  907M   0% /dev
tmpfs                   tmpfs     917M     0  917M   0% /dev/shm
tmpfs                   tmpfs     917M  8.6M  908M   1% /run
tmpfs                   tmpfs     917M     0  917M   0% /sys/fs/cgroup
/dev/mapper/centos-data xfs        40G   33M   40G   1% /data
/dev/mapper/myvg-mylv   ext4      148G   17M  141G   1% /aliyun
/dev/sda1               xfs       297M  115M  183M  39% /boot
tmpfs                   tmpfs     184M     0  184M   0% /run/user/0

 

UCLOUD对数据盘扩容后需要控制台重启,并进入系统后进行如下操作:

//针对ext4文件格式的操作系统(如CentOS6):

umount /dev/vdb
e2fsck -f /dev/vdb
resize2fs /dev/vdb
mount /dev/vdb /data

 

ucloud升级磁盘空间后需要做的操作:

具体:

[root@u04rdp01 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 6.2G 32G 17% /
tmpfs tmpfs 7.8G 12K 7.8G 1% /dev/shm
/dev/vdb ext4 493G 492G 0 100% /data
[root@u04rdp01 ~]# umount /dev/vdb
[root@u04rdp01 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 6.2G 32G 17% /
tmpfs tmpfs 7.8G 12K 7.8G 1% /dev/shm
[root@u04rdp01 ~]# e2fsck -f /dev/vdb
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb: 32929/32768000 files (0.5% non-contiguous), 131018675/131072000 blocks
[root@u04rdp01 ~]# resize2fs /dev/vdb
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vdb to 262144000 (4k) blocks.
The filesystem on /dev/vdb is now 262144000 blocks long.

[root@u04rdp01 ~]# mount /dev/vdb /data
[root@u04rdp01 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 6.2G 32G 17% /
tmpfs tmpfs 7.8G 12K 7.8G 1% /dev/shm
/dev/vdb ext4 985G 492G 443G 53% /data


//针对xfs文件格式的操作系统(如CentOS7)//
umount /dev/vdb
xfs_repair /dev/vdb
mount /dev/vdb /data
xfs_growfs /data


#美西,# 为了避免阿里云磁盘扩容麻烦直接跳过fdisk分区
fdisk -l
pvcreate /dev/vdb
vgcreate myvg /dev/vdb
lvcreate -l 100%VG -n mylv myvg
mkfs.xfs -f /dev/myvg/mylv
mount /dev/myvg/mylv /data

# vim /etc/fstab

/dev/mapper/myvg-mylv /data                    xfs defaults 0 0

# 简单扩容

pvcreate /dev/sdb
vgextend centos7_vGroup001 /dev/sdb
lvextend -l +100%FREE /dev/centos7_vGroup001/root
# ext4扩容
# resize2fs /dev/centos7_vGroup001/root

# xfs扩容
# xfs_growfs /dev/centos7_vGroup001/root

 

云服务在线磁盘扩容

# 为了避免阿里云磁盘扩容麻烦直接跳过fdisk分区
fdisk -l
pvcreate /dev/vdb
vgcreate myvg /dev/vdb
lvcreate -l 100%VG -n mylv myvg
mkfs.xfs -f /dev/myvg/mylv
mkdir /data
mount /dev/myvg/mylv /data
df -Th
echo "/dev/myvg/mylv /data xfs defaults,noatime 0 0" >> /etc/fstab


# aws

pvcreate /dev/nvme1n1
vgcreate myvg /dev/nvme1n1
lvcreate -l +100%VG -n mylv myvg
mkfs.xfs -f /dev/myvg/mylv
mkdir /data
mount /dev/myvg/mylv /data


# vim /etc/fstab
/dev/myvg/mylv /data xfs defaults,noatime 0 0
# /dev/myvg2/mylv2 /ssd xfs defaults,noatime 0 0


# 新版的在线扩容,不需要重启服务器的方法,直接在原有磁盘上加容量,然后执行如下命令,前提是没有对 /dev/vdb 进行 fdisk分区


# xfs 文件格式扩容
pvresize -v /dev/vdb && lvextend -l +100%FREE /dev/myvg/mylv && xfs_growfs /dev/myvg/mylv

# ext4 文件格式扩容
pvresize -v /dev/vdb && lvextend -l +100%FREE /dev/myvg/mylv && resize2fs /dev/myvg/mylv

 

#################

 

在线lvm扩容,已经对 /dev/vdb 进行了分区,有了/dev/vdb1,这时候磁盘扩容选择在线扩容

参考https://help.aliyun.com/document_detail/131143.htm?spm=a2c4g.11186623.2.20.ee6d4eb7kwcOVV#task-1797418

# pvresize /dev/vdb1
  Physical volume "/dev/vdb1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

# lvextend -L +100GB /dev/myvg/mylv 
  Size of logical volume myvg/mylv changed from <200.00 GiB (51199 extents) to <300.00 GiB (76799 extents).
  Logical volume myvg/mylv successfully resized.

# pvs
  PV         VG   Fmt  Attr PSize    PFree  
  /dev/vdb1  myvg lvm2 a--  <300.00g 100.00g
# lvextend -L +100GB /dev/myvg/mylv 
  Size of logical volume myvg/mylv changed from <200.00 GiB (51199 extents) to <300.00 GiB (76799 extents).
  Logical volume myvg/mylv successfully resized.

# resize2fs /dev/myvg/mylv 
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /data; on-line resizing required
old_desc_blocks = 200, new_desc_blocks = 300
The filesystem on /dev/myvg/mylv is now 157284352 blocks long.

 以下命令多测试几次就可以成功了

[root@sz_cc_cbs_download01:~]# growpart /dev/vdb 1
CHANGED: partition=1 start=2048 old: size=629143519 end=629145567 new: size=943716319 end=943718367
[root@sz_cc_cbs_download01:~]# pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/vdb1  myvg lvm2 a--  <300.00g    0 
   
[root@sz_cc_cbs_download01:~]# vgs
  VG   #PV #LV #SN Attr   VSize    VFree
  myvg   1   1   0 wz--n- <300.00g    0 
[root@sz_cc_cbs_download01:~]# pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/vdb1  myvg lvm2 a--  <300.00g    0 
[root@sz_cc_cbs_download01:~]# pvresize /dev/vdb
  Failed to find physical volume "/dev/vdb".
  0 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@sz_cc_cbs_download01:~]# pvresize /dev/vdb1 # 多执行几次
  Physical volume "/dev/vdb1" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@sz_cc_cbs_download01:~]# pvresize /dev/vdb 1
  Failed to find device for physical volume "1".
  Failed to find physical volume "/dev/vdb".
  0 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@sz_cc_cbs_download01:~]# pvs
  PV         VG   Fmt  Attr PSize    PFree  
  /dev/vdb1  myvg lvm2 a--  <450.00g 150.00g

[root@sz_cc_cbs_download01:~]# lvextend -L +150GB /dev/myvg/mylv
  Size of logical volume myvg/mylv changed from <300.00 GiB (76799 extents) to <450.00 GiB (115199 extents).
  Logical volume myvg/mylv successfully resized.
[root@sz_cc_cbs_download01:~]# lvs
  LV   VG   Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao---- <450.00g
[root@sz_cc_cbs_download01:~]# resize2fs /dev/myvg/mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /data; on-line resizing required
old_desc_blocks = 300, new_desc_blocks = 450
The filesystem on /dev/myvg/mylv is now 235927552 blocks long.

[root@sz_cc_cbs_download01:~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/vda1             ext4       40G   22G   16G  58% /
devtmpfs              devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                 tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                 tmpfs     3.9G  884K  3.9G   1% /run
tmpfs                 tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/myvg-mylv ext4      443G  229G  195G  55% /data
tmpfs                 tmpfs     783M     0  783M   0% /run/user/0

 

posted @ 2017-01-07 15:08  reblue520  阅读(2062)  评论(0编辑  收藏  举报