放弃阿里云的服务器,将wp迁移到家里的工控机之后一直就有个疑问。安装之后的磁盘空间显示的容量只有硬盘大小的一半。导致我一度以为实际磁盘就是100G的。
于是今天搜索了一下才发现是系统磁盘lvm管理导致的问题,默认安装之后只会使用磁盘一般的空间。
What is LVM
LVM stands for Logical Volume Management. It is a system of managing logical volumes, or filesystems, that is much more advanced and flexible than the traditional method of partitioning a disk into one or more segments and formatting that partition with a filesystem.
Why use LVM?
For a long time I wondered why anyone would want to use LVM when you can use gparted to resize and move partitions just fine. The answer is that lvm can do these things better, and some nifty new things that you just can’t do otherwise. I will explain several tasks that lvm can do and why it does so better than other tools, then how to do them. First you should understand the basics of lvm.
obaby@h4ck:~$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 784M 1.6M 783M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 98G 29G 65G 31% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock /dev/sda2 2.0G 268M 1.6G 15% /boot /dev/sda1 1.1G 6.1M 1.1G 1% /boot/efi tmpfs 784M 76K 784M 1% /run/user/131 tmpfs 784M 64K 784M 1% /run/user/1000
df命令可以看到挂载硬盘就是98g。
obaby@h4ck:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 63.4M 1 loop /snap/core20/1950 loop1 7:1 0 63.3M 1 loop loop2 7:2 0 49.8M 1 loop loop3 7:3 0 63.4M 1 loop /snap/core20/1974 loop4 7:4 0 111.9M 1 loop /snap/lxd/24322 loop5 7:5 0 53.3M 1 loop /snap/snapd/19457 loop7 7:7 0 53.3M 1 loop /snap/snapd/19361 sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 1G 0 part /boot/efi ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 235.4G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 100G 0 lvm /
lsblk可以看到磁盘是挂载在sda3下面。
obaby@h4ck:~$ sudo vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 235.42 GiB PE Size 4.00 MiB Total PE 60268 Alloc PE / Size 25600 / 100.00 GiB Free PE / Size 34668 / 135.42 GiB VG UUID xeAkGF-zg8u-iEMN-DNR9-FeTX-hnHi-UVfS6F
vgdisplay可以看到磁盘vg size 为235G。
所以可以扩展系统分区,由于所有的数据目前都在/home目录下,所以也没必要创建新的分区。当然更稳妥的办法是创建一个新分区挂载之后,数据都放到新分区上。
直接扩展系统分区:
obaby@h4ck:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to 235.42 GiB (60268 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
重新计算大小:
obaby@h4ck:~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 30 The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 61714432 (4k) blocks long.
再次查看磁盘空间:
obaby@h4ck:~$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 784M 1.6M 783M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 232G 29G 193G 13% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock /dev/sda2 2.0G 268M 1.6G 15% /boot /dev/sda1 1.1G 6.1M 1.1G 1% /boot/efi tmpfs 784M 76K 784M 1% /run/user/131 tmpfs 784M 64K 784M 1% /run/user/1000
现在系统盘分区大小就对上了。
参考链接:https://www.bilibili.com/read/cv23646901
9 comments
你的博客也是放在工控机的?那我不是,工控机放了其他东西,博客还是老老实实在腾讯云续费。
是的,哈哈哈。胆大吧?那个随机小姐姐图片也是用工控机跑的。目前运行了100多天了还是比较稳定的。
数据库是放在nas上的,工控就跑php+nginx,其余的不放在工控机上。
每日一图
欢迎看图
博主,你的评论通知,是使用的插件吗
是的呢,用的WP MAIL SMTP 你可以尝试一下。
好,我去试试,主题自带的,只通知登录用户,有点难受
这会忙不,去聊天广场帮忙做个测试呗!
去拉,有啥新功能?