linux 根目录容量不足问题
在linux使用过程中发现自己的根目录满了 想要进行扩容 所以留下了这份文档 XD
根目录扩容
- 目前的根目录使用的是Linux filesystem
- 期望下一版镜像可以使用lvm来管理逻辑卷
扩容步骤:
- 先把虚拟机的虚拟磁盘扩容
- 进入虚拟机内 先查看分区
df -h
sudo fdisk /dev/sda
进入fdiskmb@arch-vm:~$ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.39.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. GPT PMBR size mismatch (67108863 != 209715199) will be corrected by write. The backup GPT table is not on the end of the device. This problem will be corrected by write. This disk is currently in use - repartitioning is probably a bad idea. It's recommended to umount all file systems, and swapoff all swap partitions on this disk. Command (m for help): m
输入p 查看当前磁盘柱区的开始结束 记录下开始
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: Virtual Disk 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: gpt Disk identifier: 32D2613E-467C-4E91-A9CF-3E6098DF20F1 Device Start End Sectors Size Type /dev/sda1 2048 1048575 1046528 511M EFI System /dev/sda2 1050624 67106815 66056192 31.5G Linux filesystem
输入d 删除根目录分区
Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted.
输入n 创建新分区
Command (m for help): n Partition number (2-128, default 2): 2 First sector (1048576-209715166, default 1048576): 1050624 Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-209715166, default 209713151): Created a new partition 2 of type 'Linux filesystem' and of size 99.5 GiB. Partition #2 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: n #特别注意需要n
输入w 保存并退出
Command (m for help): w The partition table has been altered. Syncing disks.
sudo blkid
查看新分区的PARTUUIDmb@arch-vm:~$ sudo blkid /dev/sda2: UUID="93f29fe5-1003-4b3f-b041-3ce2f88ec35e" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="74d82d6b-0286-493d-befe-9002ebcfa6c8" /dev/sda1: UUID="96EB-E719" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="primary" PARTUUID="d5d88d9b-a976-4ac9-888c-c6578248b13c" /dev/zram0: LABEL="zram0" UUID="74d90911-39b7-49e8-af81-6e2938f74848" TYPE="swap" mb@arch-vm:~$ sudo resize2fs /dev/sda2 resize2fs 1.47.0 (5-Feb-2023) Filesystem at /dev/sda2 is mounted on /; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 13 The filesystem on /dev/sda2 is now 26082816 (4k) blocks long.
sudo resize2fs /dev/sda2
将磁盘空间从新划分- 找到boot目录下的启动配置文件
cd /boot/loader/entries/
并编辑 sudo nano /boot/loader/entries/2022-07-08_01-33-37_linux.conf
Created by: archinstall # Created on: 2022-07-08_01-33-37 title Arch Linux (linux) linux /vmlinuz-linux initrd /initramfs-linux.img options root=PARTUUID=32224196-b7fb-4a1c-81b7-6cd6e4527990 zswap.enabled=0 rw intel_pstate=no_hwp rootfstype=ext4
- 将PARTUUID更换成更改记录下的新PARTUUID
sudo reboot
重启生效