CentOS下LVM逻辑卷的创建及使用实例记录
最近,发现一批老机器拥有超过2块硬盘,居然还有SSD,那么剩下的2*2TB硬盘如何高效利用呢?这里就不啰嗦了,只是一个工作记录吧...
1,删除之前的挂载,至于为什么,因为后续会报错,所以先编辑掉再umount
vi /etc/fstab
umount -l /home/html
2,删除分区
fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): d
Selected partition 1
Command (m for help): p
Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 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: 0x00056041
Device Boot Start End Blocks Id System
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.
3,先将 /dev/sda、 /dev/sdb 两块硬盘格式化成PV
pvcreate /dev/sda /dev/sdb
Physical volume "/dev/sda" successfully created
Physical volume "/dev/sdb" successfully created
创建完PV以后,我们可以使用pvdisplay(显示详细信息)、pvs命令来查看当前pv的信息.
4,创建卷组(VG),并将PV加入到卷组中 通过 vgcreate 命令
在创建完PV以后,这时候我们需要创建一个VG,然后将我们的PV都加入到这个卷组当中,在创建卷组时要给该卷组起一个名字
vgcreate shujv /dev/sda /dev/sdb
Volume group "shujv" successfully created
同样,在创建好VG以后,我们也可以使用 vgdisplay 或者 vgs 命来来查看VG的信息
5,基于卷组(VG)创建逻辑卷(LV) 通过 lvcreate 命令
因为创建好的PV、VG都是底层的东西,我们上层使用的是逻辑卷,所以我们要基于VG创建我们的逻辑卷才行
lvcreate -n dy -L 3.63t shujv
Rounding up size to full physical extent 3.63 TiB
Logical volume "dy" created.
用 lvdisplay 或者 lvs 命令来查看创建好的逻辑卷的信息
6,格式化并使用我们的逻辑卷
我们已经创建好了我们的PV、VG以及LV,这时候我们如果要使用逻辑卷,就必须将其格式化成我们需要用的文件系统,并将其挂载起来,然后就可以像使用分区一样去使用逻辑卷了
mkfs.ext4 /dev/shujv/dy
7,格式化我们的逻辑卷以后,就可以使用 mount 命令将其进行挂载,我们将其挂载到 /home/html 目录下
mount /dev/shujv/dy /home/html
开机自动载硬盘: 在/etc/fstab下加入下面这句
/dev/shujv/dy /home/html ext4 defaults 0 0
好了,搞定...不懂google或者留言!