今天線上磁盤滿了,一開始沒有做lvm,最后還是坑的自己,下面是自己測試過程
1、掛載兩個數據盤
/dev/sdb /dev/sdc
2、創建基於分區的LV
1、 通過fdisk創建分區 可參考如下: #磁盤信息 fdisk /dev/sdb n p 1 t 8e w
3、創建基於分區的物理卷 pvcreate
pvcreate /dev/sdb1
pvcreate /dev/sdb2
root@master-node:~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@master-node:~# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created
4、 創建卷組:
soft 卷組名稱
vgcreate soft /dev/sdb1
[root@master-node ~]# vgcreate soft /dev/sdb1 Volume group "soft" successfully created
4.1 將新的物理卷添加到現有卷組(如果只有一個分區可以不用這一步,擴容的時候是需要的)
vgextend soft /dev/sdb2
root@master-node:~# vgextend soft /dev/sdb2 Volume group "soft" successfully extended
4.2 從卷組中刪除物理卷(一般用不上,誰沒事加上了還刪除)
[root@master-node ~]# vgreduce soft /dev/sdc1 Removed "/dev/sdc1" from volume group "soft"
5、 創建LV
Total PE 5119 == 100%FREE 全部大寫 卷組名稱 lvm命令 lvcreate -l 100%FREE soft -n soft01 -L200M 指定大寫 lvcreate -L200M soft -n soft01
6、創建文件系統
[root@master-node ~]# mkfs.ext4 /dev/soft/soft01 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 5241856 4k blocks and 1310720 inodes Filesystem UUID: bce3312b-5a41-4d12-b4a7-62d440cce327 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
7、掛載文件系統
[root@master-node ~]# mkdir /soft [root@master-node ~]# mount /dev/soft/soft01 /soft/ [root@master-node ~]# df -h Filesystem Size Used Avail Use% Mounted on udev 468M 0 468M 0% /dev tmpfs 98M 4.6M 93M 5% /run /dev/mapper/ubuntu--vg-root 19G 2.4G 15G 14% / tmpfs 488M 0 488M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 488M 0 488M 0% /sys/fs/cgroup /dev/sda1 472M 58M 391M 13% /boot tmpfs 98M 0 98M 0% /run/user/1000 /dev/mapper/soft-soft01 20G 44M 19G 1% /soft [root@master-node ~]#
8、 擴lv(當線上磁盤空間不足的時候,添加一塊新的磁盤,或者直接在分一個區,步驟差不多)
/dev/sdc 當做新掛載的磁盤(分區格式化)
root@master-node:~# fdisk -l /dev/sdc Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: dos Disk identifier: 0x6c62af31 root@master-node:~# fdisk /dev/sdc Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): Created a new partition 1 of type 'Linux' and of size 20 GiB. Command (m for help): t Selected partition 1 Partition type (type L to list all types): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): p Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: dos Disk identifier: 0x6c62af31 Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 41943039 41940992 20G 8e Linux LVM Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
8-1、初始化好了,就開始整吧
pvcreate /dev/sdc1
root@master-node:~# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created
8.1 將新的物理卷添加到現有卷組
vgextend soft /dev/sdc1
vgdisplay soft
root@master-node:~# vgextend soft /dev/sdc1 Volume group "soft" successfully extended
8.3、在現有的空間中添加2G (重要的來了,現在加了磁盤空間還沒有變化,還需要告訴一下磁盤變化了)
lvextend -L+2G /dev/soft/soft01
root@master-node:~# lvextend -L+2G /dev/soft/soft01 Size of logical volume soft/soft01 changed from 19.99 GiB (5118 extents) to 21.99 GiB (5630 extents). Logical volume soft01 successfully resized.
8.4、擴容文件系統
resize2fs /dev/soft/soft01
root@master-node:~# resize2fs /dev/soft/soft01 resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/soft/soft01 is mounted on /soft; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 2 The filesystem on /dev/soft/soft01 is now 5765120 (4k) blocks long.