我看过一些教程,他们说 -
步骤1)运行df -h
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.7G 6.1G 1.7G 79% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 787M 832K 787M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop0 25M 25M 0 100% /snap/amazon-ssm-agent/6312
/dev/loop1 25M 25M 0 100% /snap/amazon-ssm-agent/6563
/dev/loop3 56M 56M 0 100% /snap/core18/2566
/dev/loop2 64M 64M 0 100% /snap/core20/1623
/dev/loop5 64M 64M 0 100% /snap/core20/1634
/dev/loop4 56M 56M 0 100% /snap/core18/2620
/dev/loop7 48M 48M 0 100% /snap/snapd/17029
/dev/loop6 68M 68M 0 100% /snap/lxd/22753
/dev/loop8 68M 68M 0 100% /snap/lxd/21835
/dev/loop9 48M 48M 0 100% /snap/snapd/17336
tmpfs 787M 0 787M 0% /run/user/1000
步骤2)运行lsblk
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 24.4M 1 loop /snap/amazon-ssm-agent/6312
loop1 7:1 0 24.8M 1 loop /snap/amazon-ssm-agent/6563
loop2 7:2 0 63.2M 1 loop /snap/core20/1623
loop3 7:3 0 55.6M 1 loop /snap/core18/2566
loop4 7:4 0 55.6M 1 loop /snap/core18/2620
loop5 7:5 0 63.2M 1 loop /snap/core20/1634
loop6 7:6 0 67.8M 1 loop /snap/lxd/22753
loop7 7:7 0 48M 1 loop /snap/snapd/17029
loop8 7:8 0 67.2M 1 loop /snap/lxd/21835
loop9 7:9 0 48M 1 loop /snap/snapd/17336
nvme0n1 259:0 0 30G 0 disk
└─nvme0n1p1 259:1 0 8G 0 part /
步骤3)运行blkid
$ blkid
/dev/nvme0n1p1: LABEL="cloudimg-rootfs" UUID="436cf32d-5e3d-46ca-b557-f870c8a25794" TYPE="ext4" PARTUUID="24ca9e81-01"
从这里开始,网上的每个例子似乎都很老了,每个例子都有sudo resize2fs /dev/xvda1
这个例子,我记得在过去几年里我也这样做过,当时我也把 xvda1 作为文件系统,但在 2022 年的新机器上不再是这样了
如果我尝试运行,sudo resize2fs /dev/nvme0n1p1
我会收到一条错误消息,提示“无事可做”
$ sudo resize2fs /dev/nvme0n1p1
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 2096891 (4k) blocks long. Nothing to do!
我可以看到我将音量增加到 30G,nvme0n1
但是现在如何让我的操作系统识别额外的空间?
答案1
找到了这个教程 https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html
运行以下命令
$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=2048 old: size=16775135 end=16777183 new: size=62912479 end=62914527
能够扩大规模
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 24.4M 1 loop /snap/amazon-ssm-agent/6312
loop1 7:1 0 24.8M 1 loop /snap/amazon-ssm-agent/6563
loop2 7:2 0 63.2M 1 loop /snap/core20/1623
loop3 7:3 0 55.6M 1 loop /snap/core18/2566
loop4 7:4 0 55.6M 1 loop /snap/core18/2620
loop5 7:5 0 63.2M 1 loop /snap/core20/1634
loop6 7:6 0 67.8M 1 loop /snap/lxd/22753
loop7 7:7 0 48M 1 loop /snap/snapd/17029
loop8 7:8 0 67.2M 1 loop /snap/lxd/21835
loop9 7:9 0 48M 1 loop /snap/snapd/17336
nvme0n1 259:0 0 30G 0 disk
└─nvme0n1p1 259:1 0 30G 0 part /
确定系统类型为 ext4
$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/root ext4 7.7G 6.1G 1.7G 79% /
...
然后能够使用给定的命令调整分区大小
$ sudo resize2fs /dev/nvme0n1p1
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/nvme0n1p1 is now 7864059 (4k) blocks long.
答案2
我希望你很好。
关于这个在 EC2 Linux 实例中调整文件系统大小的练习,我有一些疑问。
运行时df -hT
,它会显示文件系统dev/root
,输入ext4
然后使用该lsblk
命令,nvme0n1p1
将显示大小等于卷大小的分区。
我的问题是:执行命令是否正确sudo resize2fs /dev/root代替sudo resize2fs /dev/nvme0n1p1,在什么情况下执行它们每一个?
提前感谢您的回答。
亲切的问候。