LVM邏輯卷創建和擴容:node
一:分區擴容:bash
一、查看當前的磁盤狀況:app
root@kali:~# 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 root@kali:~# 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 root@kali:~# 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 root@kali:~# vgs # 查看卷組(VG) VG #PV #LV #SN Attr VSize VFree kali-vg 1 2 0 wz--n- <99.76g 0 # 有一個卷組(VG),名字爲kali-vg,該卷組有包含一個物理卷(PV),分配了兩個邏輯卷(LV) root@kali:~# pvs # 查看當前物理卷(PV) PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 # 有一個物理卷,是用/dev/sda5作的,隸屬於kali-vg卷組
二、添加一塊新磁盤:ide
root@kali:~# 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
三、將新磁盤初始化爲物理卷:日誌
root@kali:~# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. root@kali:~# pvs PV VG Fmt Attr PSize PFree /dev/sda5 kali-vg lvm2 a-- <99.76g 0 /dev/sdb lvm2 --- 20.00g 20.00g # 已經有了
四、將新的物理卷擴展到kali-vg卷組:同步
root@kali:~# vgextend kali-vg /dev/sdb Volume group "kali-vg" successfully extended root@kali:~# vgs VG #PV #LV #SN Attr VSize VFree kali-vg 2 2 0 wz--n- 119.75g <20.00g # 卷組容量已經增大
五、擴展邏輯卷root:it
root@kali:~# 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. root@kali:~# 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
六、文件系統和邏輯卷同步擴容:class
此時再查看下文件系統狀況:擴展
root@kali:~# 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
文件系統的容量尚未增大,須要同步一下:map
root@kali:~# 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)。 root@kali:~# 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邏輯卷分區:
一、查看當前的磁盤狀況:
root@kali:~# 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 root@kali:~# 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 root@kali:~# 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 root@kali:~# vgs VG #PV #LV #SN Attr VSize VFree kali-vg 2 2 0 wz--n- 119.75g 1020.00m root@kali:~# 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 二、將新硬盤建立(初始化爲)物理卷: root@kali:~# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created. root@kali:~# 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
三、建立一個新卷組:
root@kali:~# vgcreate lee-vg /dev/sdc # 卷組名爲lee-vg,同時將/dev/sdc加入該卷組 Volume group "lee-vg" successfully created root@kali:~# 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 root@kali:~# 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
四、建立邏輯卷:
root@kali:~# lvcreate -L 9G -n lee lee-vg # -L指定容量大小,-n指定卷名,後面接在哪一個卷組上建立 Logical volume "lee" created. root@kali:~# 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
五、格式化建立文件系統:
root@kali:~# 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 個塊)完成 寫入超級塊和文件系統帳戶統計信息: 已完成
六、掛載分區:
root@kali:~# mkdir /mydata root@kali:~# mount /dev/mapper/lee--vg-lee /mydata/ root@kali:~# 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了