Linux6.4硬盘扩容LVM逻辑卷管理操作手册
1. 对新增加的硬盘进行分区、格式化
1.1. 用root用户登录系统
使用SSH客户端登录Linux服务器。
1.2. 查看挂载情况(此步可省略)
(加上-T这个参数,就可以列出所有系统挂载的分区的文件类型信息)
[root@servername ~]# df -lh
文件系统 容量 已用 可用 已用%% 挂载点 /dev/sda3 95G 4.0G 86G 5% /
tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 388M 37M 331M 10% /boot [root@servername ~]#
1.3. 查看磁盘情况(此步不建议省略)
下方红色字为要创建分区的硬盘。 [root@servername ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x000bf627
Device Boot Start End Blocks Id System /dev/sda1 * 1 52 409600 83 Linux Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
-1-
/dev/sda3 574 13055 100252672 83 Linux
Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0x00000000
[root@servername ~]#
1.4. 创建分区
下方红色字为要创建分区的硬盘注意跟上面查看到的要对应。 [root@servername ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x883e515a.
Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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): n 新增加一个分区 Command action e extended
p primary partition (1-4)
p 分区类型我们选择为主分区
Partition number (1-4): 1 分区编号选1,如果被占依此类推 First cylinder (1-130541, default 1): 按回车 默认(起始扇区) Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130541, default 130541): 按回车 默认(结束扇区)也可以使用+100M即创建100M的分区 也可以使用(K,M,G) Using default value 130541
Command (m for help): w 写分区表(可以输入t进行分区格式调整,见1.6调整分区格式)
The partition table has been altered!
-2-
Calling ioctl() to re-read partition table. Syncing disks.
[root@servername ~]#
1.5. 重新查看磁盘情况(此步可省略)
下方红色字为新创建的磁盘分区信息。
[root@servername ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x000bf627
Device Boot Start End Blocks Id System /dev/sda1 * 1 52 409600 83 Linux Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 574 13055 100252672 83 Linux
Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0x883e515a
Device Boot Start End Blocks Id System /dev/sdb1 1 130541 1048570551 83 Linux [root@servername ~]#
1.6. 调整分区格式(可以跟创建分区合并执行)
我们的新建分区,却不是LVM的。所以,接下来使用fdisk将其改成LVM的,使用LVM逻辑卷管理可以方便以后扩容。
-3-
[root@servername ~]# fdisk /dev/sdb
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): t 修改分区类型
Selected partition 1 选分区1(与上面新创建的分区要对应) Hex code (type L to list codes): 8e 修改为LVM类型(8e就是LVM) Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w 写分区表 The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
[root@servername ~]#
1.7. 重启服务器
[root@servername ~]# reboot
Broadcast message from root@servername (/dev/pts/0) at 15:30 ...
The system is going down for reboot NOW! [root@servername ~]#
1.8. 分区格式化
下方红色字为要格式化的分区,要与上面新创建分区的对应。(如果不确定可以执行fdisk -l查看磁盘情况,见1.5重新查看磁盘情况)
[root@servername ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux
块大小=4096 (log=2) 分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks 65536000 inodes, 262142637 blocks
-4-
13107131 blocks (5.00%) reserved for the super user 第一个数据块=0
Maximum filesystem blocks=4294967296 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
正在写入inode表: 完成 Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@servername ~]#
2. 创建LVM卷组分区添加到卷组创建卷实现扩容
2.1. 硬盘分区初始化为物理卷
pvcreate指令用于将物理硬盘分区初始化为物理卷,以便被LVM使用。 下方红色字为要初始化为物理卷的分区,要与上面新创建分区的对应。
[root@servername ~]# lvm lvm> pvcreate /dev/sdb1
Physical volume \lvm>
2.2. 创建逻辑卷组
vgcreate 命令执行几个操作。除了创建 \卷组以外,它还设置
-5-