一:分区扩容:
1、查看当前的磁盘情况:
[email protected]:~# df -h # 查看文件系统情况 文件系统 容量 已用 可用 已用% 挂载点 udev 970M 0 970M 0% /dev tmpfs 198M 9.0M 189M 5% /run /dev/mapper/kali--vg-root 96G 13G 78G 15% / tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 988M 0 988M 0% /sys/fs/cgroup /dev/sda1 236M 85M 139M 38% /boot tmpfs 198M 12K 198M 1% /run/user/131 tmpfs 198M 40K 198M 1% /run/user/0 /dev/sr0 2.7G 2.7G 0 100% /media/cdrom0 [email protected]:~# fdisk -l # 查看磁盘分区情况 Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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: 0x7b9fe360 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux # 可引导主分区,用做/boot /dev/sda2 501758 209713151 209211394 99.8G 5 Extended # 扩展分区 /dev/sda5 501760 209713151 209211392 99.8G 8e Linux LVM # LVM卷,所有扩展分区都用做LVM卷 Disk /dev/mapper/kali--vg-root: 97.8 GiB, 104966651904 bytes, 205012992 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 /dev/mapper/kali--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 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 [email protected]:~# lvs # 查看当前逻辑卷(LV) LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root kali-vg -wi-ao---- <97.76g swap_1 kali-vg -wi-ao---- 2.00g [email protected]:~# vgs # 查看卷组(VG) VG #PV #LV #SN Attr VSize VFree kali-vg 1 2 0 wz--n- <99.76g 0 # 有一个卷组(VG),名字为kali-vg,该卷组有包含一个物理卷(PV),分配了两个逻辑卷(LV) [email protected]:~# pvs # 查看当前物理卷(PV) PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 # 有一个物理卷,是用/dev/sda5做的,隶属于kali-vg卷组
2、添加一块新磁盘:
[email protected]:~# fdisk -l Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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: 0x7b9fe360 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux /dev/sda2 501758 209713151 209211394 99.8G 5 Extended /dev/sda5 501760 209713151 209211392 99.8G 8e Linux LVM Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors # 这里为新加的硬盘20G 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 /dev/mapper/kali--vg-root: 97.8 GiB, 104966651904 bytes, 205012992 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 /dev/mapper/kali--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 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
3、将新磁盘初始化为物理卷:
[email protected]:~# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. [email protected]:~# pvs PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 /dev/sdb lvm2 --- 20.00g 20.00g # 已经有了
4、将新的物理卷扩展到kali-vg卷组:
[email protected]:~# vgextend kali-vg /dev/sdb Volume group "kali-vg" successfully extended [email protected]:~# vgs VG #PV #LV #SN Attr VSize VFree kali-vg 2 2 0 wz--n- 119.75g <20.00g # 卷组容量已经增大
5、扩展逻辑卷root:
[email protected]:~# lvextend -L +19G /dev/kali-vg/root # -L +19G表示扩展19G,也可以用-L 119G,表示扩展到119G Size of logical volume kali-vg/root changed from <97.76 GiB (25026 extents) to <116.76 GiB (29890 extents). Logical volume kali-vg/root successfully resized. [email protected]:~# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root kali-vg -wi-ao---- <116.76g # 逻辑卷容量已经增大 swap_1 kali-vg -wi-ao---- 2.00g
6、文件系统和逻辑卷同步扩容:
此时再查看下文件系统情况:
[email protected]:~# df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 970M 0 970M 0% /dev tmpfs 198M 9.0M 189M 5% /run /dev/mapper/kali--vg-root 96G 15G 77G 16% / # 发现容量并没有改变 tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 988M 0 988M 0% /sys/fs/cgroup /dev/sda1 236M 85M 139M 38% /boot tmpfs 198M 12K 198M 1% /run/user/131 tmpfs 198M 40K 198M 1% /run/user/0 /dev/sr0 2.7G 2.7G 0 100% /media/cdrom0
文件系统的容量还没有增大,需要同步一下:
[email protected]:~# resize2fs /dev/kali-vg/root resize2fs 1.43.9 (8-Feb-2018) /dev/kali-vg/root 上的文件系统已被挂载于 /;需要进行在线调整大小 old_desc_blocks = 13, new_desc_blocks = 15 /dev/kali-vg/root 上的文件系统现在为 30607360 个块(每块 4k)。 [email protected]:~# df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 970M 0 970M 0% /dev tmpfs 198M 9.0M 189M 5% /run /dev/mapper/kali--vg-root 115G 15G 95G 14% / # 容量已经增加了 tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 988M 0 988M 0% /sys/fs/cgroup /dev/sda1 236M 85M 139M 38% /boot tmpfs 198M 12K 198M 1% /run/user/131 tmpfs 198M 40K 198M 1% /run/user/0 /dev/sr0 2.7G 2.7G 0 100% /media/cdrom0
二:创建LVM逻辑卷分区:
1、查看当前的磁盘情况:
[email protected]:~# fdisk -l Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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: 0x7b9fe360 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 499711 497664 243M 83 Linux /dev/sda2 501758 209713151 209211394 99.8G 5 Extended /dev/sda5 501760 209713151 209211392 99.8G 8e Linux LVM Disk /dev/sdb: 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 Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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 /dev/mapper/kali--vg-root: 116.8 GiB, 125367746560 bytes, 244858880 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 /dev/mapper/kali--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 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 [email protected]:~# df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 970M 0 970M 0% /dev tmpfs 198M 6.2M 192M 4% /run /dev/mapper/kali--vg-root 115G 15G 95G 14% / tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 988M 0 988M 0% /sys/fs/cgroup /dev/sda1 236M 85M 139M 39% /boot tmpfs 198M 16K 198M 1% /run/user/131 tmpfs 198M 4.0K 198M 1% /run/user/0 [email protected]:~# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root kali-vg -wi-ao---- <116.76g swap_1 kali-vg -wi-ao---- 2.00g [email protected]:~# vgs VG #PV #LV #SN Attr VSize VFree kali-vg 2 2 0 wz--n- 119.75g 1020.00m [email protected]:~# pvs PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 /dev/sdb kali-vg lvm2 a-- <20.00g 1020.00m 2、将新硬盘创建(初始化为)物理卷: [email protected]:~# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created. [email protected]:~# pvs PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 /dev/sdb kali-vg lvm2 a-- <20.00g 1020.00m /dev/sdc lvm2 --- 10.00g 10.00g
3、创建一个新卷组:
[email protected]:~# vgcreate lee-vg /dev/sdc # 卷组名为lee-vg,同时将/dev/sdc加入该卷组 Volume group "lee-vg" successfully created [email protected]:~# pvs PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 /dev/sdb kali-vg lvm2 a-- <20.00g 1020.00m /dev/sdc lee-vg lvm2 a-- <10.00g <10.00g [email protected]:~# vgs VG #PV #LV #SN Attr VSize VFree kali-vg 2 2 0 wz--n- 119.75g 1020.00m lee-vg 1 0 0 wz--n- <10.00g <10.00g
4、创建逻辑卷:
[email protected]:~# lvcreate -L 9G -n lee lee-vg # -L指定容量大小,-n指定卷名,后面接在哪个卷组上创建 Logical volume "lee" created. [email protected]:~# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root kali-vg -wi-ao---- <116.76g swap_1 kali-vg -wi-ao---- 2.00g lee lee-vg -wi-a----- 9.00g
5、格式化创建文件系统:
[email protected]:~# mkfs.ext4 /dev/mapper/lee--vg-lee # Ubuntu系统只能用mkfs.ext4,Centos可以用mkfs -ext4,而且Centos的/dev下直接有卷组名,Ubuntu系统卷组名在/dev/mapper/ 下。 mke2fs 1.43.9 (8-Feb-2018) 创建含有 2359296 个块(每块 4k)和 589824 个inode的文件系统 文件系统UUID:3bcb54b3-b5e4-4a45-8c61-8a6e2fdebefc 超级块的备份存储于下列块: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 正在分配组表: 完成 正在写入inode表: 完成 创建日志(16384 个块)完成 写入超级块和文件系统账户统计信息: 已完成 mke2fs 1.43.9 (8-Feb-2018) 创建含有 2359296 个块(每块 4k)和 589824 个inode的文件系统 文件系统UUID:3bcb54b3-b5e4-4a45-8c61-8a6e2fdebefc 超级块的备份存储于下列块: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 正在分配组表: 完成 正在写入inode表: 完成 创建日志(16384 个块)完成 写入超级块和文件系统账户统计信息: 已完成
6、挂载分区:
[email protected]:~# mkdir /mydata [email protected]:~# mount /dev/mapper/lee--vg-lee /mydata/ [email protected]:~# df -h 文件系统 容量 已用 可用 已用% 挂载点 udev 970M 0 970M 0% /dev tmpfs 198M 6.2M 192M 4% /run /dev/mapper/kali--vg-root 115G 15G 95G 14% / tmpfs 988M 0 988M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 988M 0 988M 0% /sys/fs/cgroup /dev/sda1 236M 85M 139M 39% /boot tmpfs 198M 16K 198M 1% /run/user/131 tmpfs 198M 4.0K 198M 1% /run/user/0 /dev/mapper/lee--vg-lee 8.8G 37M 8.3G 1% /mydata # 这里已经OK了
原文地址:http://blog.51cto.com/lidongfeng/2084152
时间: 2024-10-28 20:22:41