您好,登錄后才能下訂單哦!
這篇文章主要介紹“Ubuntu下如何擴展LVM根目錄”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Ubuntu下如何擴展LVM根目錄”文章能幫助大家解決問題。
調大物理磁盤
虛擬機關機,然后直接在虛擬機管理里面操作。
現在把磁盤從 100g 調整到了 300g
確定要操作的磁盤
先看下磁盤使用情況,運行命令
root@vm003:~# df -h filesystem size used avail use% mounted on udev 3.9g 0 3.9g 0% /dev tmpfs 798m 8.6m 789m 2% /run /dev/mapper/ubuntu-root 94g 88g 1.9g 98% / tmpfs 3.9g 0 3.9g 0% /dev/shm tmpfs 5.0m 0 5.0m 0% /run/lock tmpfs 3.9g 0 3.9g 0% /sys/fs/cgroup /dev/sda1 472m 382m 66m 86% /boot tmpfs 100k 0 100k 0% /run/lxcfs/controllers tmpfs 798m 0 798m 0% /run/user/0
雖然我們已經把物理磁盤調整到了 300g,但是根目錄還是100g的樣子,已用 98%
運行命令
root@vm003:~# fdisk -l disk /dev/sda: 300 gib, 322122547200 bytes, 629145600 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes disklabel type: dos disk identifier: 0xa88f1366 device boot start end sectors size id type /dev/sda1 * 2048 999423 997376 487m 83 linux /dev/sda2 1001470 209713151 208711682 99.5g 5 extended /dev/sda5 1001472 209713151 208711680 99.5g 8e linux lvm partition 2 does not start on physical sector boundary. disk /dev/mapper/ubuntu-root: 95.5 gib, 102563315712 bytes, 200318976 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes disk /dev/mapper/ubuntu-swap_1: 4 gib, 4294967296 bytes, 8388608 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes
可以看到 /dev/sda 已經確實被調整到了300gib,只是系統還沒用到。
也知道了我們要操作 /dev/sda
擴大 lvm 邏輯分區所在的物理分區
運行命令
root@vm003:~# parted /dev/sda gnu parted 3.2 using /dev/sda welcome to gnu parted! type 'help' to view a list of commands. (parted) print # 查看分區 model: msft virtual disk (scsi) disk /dev/sda: 322gb sector size (logical/physical): 512b/4096b partition table: msdos disk flags: number start end size type file system flags 1 1049kb 512mb 511mb primary ext2 boot 2 513mb 107gb 107gb extended 5 513mb 107gb 107gb logical lvm (parted) resizepart 2 # 調整 sda2 分區大小 end? [107gb]? -0 # 直接充滿 (parted) print # 再次查看 model: msft virtual disk (scsi) disk /dev/sda: 322gb sector size (logical/physical): 512b/4096b partition table: msdos disk flags: number start end size type file system flags 1 1049kb 512mb 511mb primary ext2 boot 2 513mb 322gb 322gb extended 5 513mb 107gb 107gb logical lvm (parted) q # 完成退出 information: you may need to update /etc/fstab.
現在我們已經把 /dev/sda2 給拓展出來了
新增 lvm 邏輯分區
運行命令
root@vm003:~# fdisk /dev/sda 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): p # 查看現在的分區情況 disk /dev/sda: 300 gib, 322122547200 bytes, 629145600 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes disklabel type: dos disk identifier: 0xa88f1366 device boot start end sectors size id type /dev/sda1 * 2048 999423 997376 487m 83 linux /dev/sda2 1001470 629145599 628144130 299.5g 5 extended /dev/sda5 1001472 209713151 208711680 99.5g 8e linux lvm partition 2 does not start on physical sector boundary. command (m for help): n # 新增分區,選擇邏輯分區,起止點看情況輸入,默認值是填充滿整個磁盤 all space for primary partitions is in use. adding logical partition 6 first sector (209715200-629145599, default 209715200): last sector, +sectors or +size{k,m,g,t,p} (209715200-629145599, default 629145599): created a new partition 6 of type 'linux' and of size 200 gib. command (m for help): p # 查看新增的分區 disk /dev/sda: 300 gib, 322122547200 bytes, 629145600 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes disklabel type: dos disk identifier: 0xa88f1366 device boot start end sectors size id type /dev/sda1 * 2048 999423 997376 487m 83 linux /dev/sda2 1001470 629145599 628144130 299.5g 5 extended /dev/sda5 1001472 209713151 208711680 99.5g 8e linux lvm /dev/sda6 209715200 629145599 419430400 200g 83 linux partition 2 does not start on physical sector boundary. command (m for help): t # 改變分區類型為 linux lvm partition number (1,2,5,6, default 6): 6 # sda6 partition type (type l to list all types): 8e # lvm 類型的 id 代碼 changed type of partition 'linux' to 'linux lvm'. command (m for help): p # 再次查看分區情況 disk /dev/sda: 300 gib, 322122547200 bytes, 629145600 sectors units: sectors of 1 * 512 = 512 bytes sector size (logical/physical): 512 bytes / 4096 bytes i/o size (minimum/optimal): 4096 bytes / 4096 bytes disklabel type: dos disk identifier: 0xa88f1366 device boot start end sectors size id type /dev/sda1 * 2048 999423 997376 487m 83 linux /dev/sda2 1001470 629145599 628144130 299.5g 5 extended /dev/sda5 1001472 209713151 208711680 99.5g 8e linux lvm /dev/sda6 209715200 629145599 419430400 200g 8e linux lvm partition 2 does not start on physical sector boundary. command (m for help): wq # 確認沒有問題,保存退出 the partition table has been altered. calling ioctl() to re-read partition table. re-reading the partition table failed.: 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).
新分區合并到相應 volumn group
運行命令
root@vm003:~# vgdisplay --- volume group --- vg name ubuntu system id format lvm2
可以看出我們要操作的vg name 為 ubuntu,記錄下來。
接著運行命令
root@vm003:~# vgextend ubuntu /dev/sda6 # /dev/sda6 是剛剛增加的 lvm 分區 device /dev/sda6 not found (or ignored by filtering). unable to add physical volume '/dev/sda6' to volume group 'ubuntu'.
呃,,,提示沒有找到 /dev/sda6 這個設備,還是重啟一下好了。
root@vm003:~# reboot
重啟后再次執行
root@vm003:~# vgextend ubuntu /dev/sda6 # /dev/sda6 是剛剛增加的 lvm 分區 physical volume "/dev/sda6" successfully created volume group "ubuntu" successfully extended
再查看一下 volumn group 的狀態,運行命令
root@vm003:~# vgs vg #pv #lv #sn attr vsize vfree ubuntu 2 2 0 wz--n- 299.52g 200.00g
確實加進去了。
然后運行
root@vm003:~# lvdisplay --- logical volume --- lv path /dev/ubuntu/root lv name root vg name ubuntu
我們知道了 ubuntu vg 的 lv path 是 /dev/ubuntu/root,記錄下來。
然后運行
root@vm003:~# lvresize -l +100%free /dev/ubuntu/root # /dev/ubuntu/root 是 lv path size of logical volume ubuntu/root changed from 95.52 gib (24453 extents) to 295.52 gib (75652 extents). logical volume root successfully resized.
這就成功啦。
警告: 如果操作時出現下面這樣的 warning,就說明現在 logic volumn 的總大小還不對,resize 不但不增加空間,反而在縮小空間,如果繼續操作下去,必將丟失數據。應立即停止!按 n 取消。
warning: reducing active and open logical volume to 32.00 mib
this may destroy your data (filesystem etc.)
do you really want to reduce root? [y/n]*
更新文件系統
最后一步,運行命令
root@vm003:~# resize2fs -p /dev/mapper/ubuntu-root # /dev/mapper/ubuntu-root 是從 df 命令看到的文件系統信息 resize2fs 1.42.13 (17-may-2015) filesystem at /dev/mapper/ubuntu-root is mounted on /; on-line resizing required old_desc_blocks = 6, new_desc_blocks = 19 the filesystem on /dev/mapper/ubuntu-root is now 77467648 (4k) blocks long.
這個過程可能會花幾分鐘時間,耐心等待就好了。
然后運行 df 命令查看磁盤使用
root@vm003:~# df -h filesystem size used avail use% mounted on udev 3.9g 0 3.9g 0% /dev tmpfs 798m 8.6m 789m 2% /run /dev/mapper/ubuntu-root 291g 88g 191g 32% / tmpfs 3.9g 0 3.9g 0% /dev/shm tmpfs 5.0m 0 5.0m 0% /run/lock tmpfs 3.9g 0 3.9g 0% /sys/fs/cgroup /dev/sda1 472m 382m 66m 86% /boot tmpfs 100k 0 100k 0% /run/lxcfs/controllers tmpfs 798m 0 798m 0% /run/user/0
關于“Ubuntu下如何擴展LVM根目錄”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。