Alpine磁盘扩容

最近花150r搞了个2年的迷你主机,0.5C 0.5G + 20G 硬盘,虽然性能拉胯但1G带宽每月1T流量,倒也还行,装个Alpine还是绰绰有余的

主机装上系统一看,根目录/才1个多G,我就纳闷了,不是20G么,本来想提单但想想应该是软件问题,先用fdisk -l看一下

# fdisk -l
Disk /dev/vda: 20 GB, 21474836480 bytes, 41943040 sectors
41610 cylinders, 16 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/vda1 *  2,0,33      205,3,19          2048     206847     204800  100M 83 Linux
/dev/vda2    205,3,20    1023,15,63      206848    1255423    1048576  512M 82 Linux swap
/dev/vda3    1023,15,63  1023,15,63     1255424    4194303    2938880 1435M 83 Linux

合着还有18G根本没分配,那重新分个区就好了,先把要用的软件安装上

# apk add e2fsprogs-extra 

fdisk进入磁盘管理界面

# fdisk /dev/vda

The number of cylinders for this disk is set to 41610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

输入d选择删掉分区,输入3选择vda3(根目录)

Command (m for help): d
Partition number (1-4): 3

然后输入n新建分区,p选择基本分区,3代表vda3

Command (m for help): n
Partition type
   p   primary partition (1-4)
   e   extended
p
Partition number (1-4): 3

然后输入起始扇区,就是在之前通过fdsik -l看到的vda3起始扇区,也就是StartLBA,这里输入1255424,然后结束扇区默认就是最后一个扇区,也就是全部分配给vda3,当然也可以自定义分配多少

First sector (63-41943039, default 63): 1255424
Last sector or +size{,K,M,G,T} (1255424-41943039, default 41943039): 
Using default value 41943039

这时就分配完毕了,输入p查看现在分区状态

Command (m for help): p
Disk /dev/vda: 20 GB, 21474836480 bytes, 41943040 sectors
41610 cylinders, 16 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/vda1 *  2,0,33      205,3,19          2048     206847     204800  100M 83 Linux
/dev/vda2    205,3,20    1023,15,63      206848    1255423    1048576  512M 82 Linux swap
/dev/vda3    1023,15,63  1023,15,63     1255424   41943039   40687616 19.4G 83 Linux

可以看到vda3已经扩容了,输入w保存

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
fdisk: WARNING: rereading partition table failed, kernel still uses old table: Resource busy

警告直接无视,使用partprobe刷新分区表

# partprobe /dev/vda

再使用resize2fs(针对ext4文件系统)给vda3扩容

# resize2fs /dev/vda3
resize2fs 1.46.6 (1-Feb-2023)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/vda3 is now 5085952 (4k) blocks long.

这下就扩容完毕了,使用df -h看看

# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         10M     0   10M   0% /dev
shm             241M     0  241M   0% /dev/shm
/dev/vda3        20G  188M   19G   2% /
tmpfs            97M  128K   97M   1% /run
/dev/vda1        89M   18M   64M  22% /boot
tmpfs           241M     0  241M   0% /tmp

大功告成

发表回复

电子邮件地址不会被公开。必填项已用 * 标注