Linux-Lvm磁盤擴容

Linux 磁盤擴容

注意:針對kvm,vnware架構的雲服務器,不要輕易動系統盤,如果系統盤空間不足,可以擴容數據盤,掛在到相應的系統盤目錄下(做好數據備份),對於數據盤最好做成邏輯卷掛在使用,避免後期業務需求在線擴容。
一,對數據盤分區
#fdisk /dev/vdb
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-75497471, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-75497471, default 75497471): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/vdb: 38.7 GB, 38654705664 bytes, 75497472 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: 0x0d1d7a83

Device Boot Start End Blocks Id System
/dev/vdb1 2048 20973567 10485760 83 Linux
記得w保存
二,1,物理卷

pvcreate /dev/vdb1

Physical volume “/dev/vdb1” successfully created.
2,卷組

vgcreate vg01 /dev/vdb1

Volume group “vg01” successfully created
3邏輯卷

lvcreate -n lv01 -L 9.8G vg01

4、格式化文件系統

mkfs -t ext4 /dev/vg01/lv01

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
643376 inodes, 2569216 blocks
128460 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
79 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

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

5,創建掛載點

mkdir /u01

[root@hexian ~]# mount /dev/vg01/lv01 /u01 臨時掛在,永久掛載的話寫到/etc/fstab
[root@hexian ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
devtmpfs 912M 32K 912M 1% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 320K 920M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg01-lv01 9.6G 37M 9.0G 1% /u01

當空間不足時,可以擴容數據盤,在分區創建物理卷,擴容上述卷組,再而擴容邏輯卷,滿足業務需求。(不能之間,避免造成文件系統的損壞),如果有損壞,可以用fsck修復,不一定能修好,所以輕易不要在用的服務器上直接操作,測試沒問題方可操作。
root@hexian ~]# 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.

Command (m for help): p

Disk /dev/vdb: 38.7 GB, 38654705664 bytes, 75497472 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: 0x0d1d7a83

Device Boot Start End Blocks Id System
/dev/vdb1 2048 20973567 10485760 83 Linux

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (20973568-75497471, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-75497471, default 75497471):
Using default value 75497471
Partition 2 of type Linux and of size 26 GiB is set

Command (m for help): p

Disk /dev/vdb: 38.7 GB, 38654705664 bytes, 75497472 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: 0x0d1d7a83

Device Boot Start End Blocks Id System
/dev/vdb1 2048 20973567 10485760 83 Linux
/dev/vdb2 20973568 75497471 27261952 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.

三1,做物理卷
pvcreate /dev/vdb2
2,擴容卷組
#vgextend vg01 /dev/vdb2
Volume group “vg01” successfully extended
3,擴容邏輯卷
[root@hexian ~]# lvextend -L +10G /dev/mapper/vg01-lv01
Size of logical volume vg01/lv01 changed from 9.80 GiB (2509 extents) to 19.80 GiB (5069 extents).
Logical volume vg01/lv01 successfully resized.
4,同步文件系統
[root@hexian ~]# lvextend -L +10G /dev/mapper/vg01-lv01
Size of logical volume vg01/lv01 changed from 9.80 GiB (2509 extents) to 19.80 GiB (5069 extents).
Logical volume vg01/lv01 successfully resized.
[root@hexian ~]# resize2fs /dev/vg01/lv01
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg01/lv01 is mounted on /u01; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/vg01/lv01 is now 5190656 blocks long.
[root@hexian ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
devtmpfs 912M 32K 912M 1% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 380K 920M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
/dev/mapper/vg01-lv01 20G 44M 19G 1% /u01
/u01增加到了20G

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章