记 阿里云自定义alpine镜像 和 在线扩容系统盘

本文共有3284个字,关键词:alpine阿里云扩容

现在服务器宿主机不需要安装第三方程序,只要有docker就足够了。
自从给学校服务器尝试安装alpine运行docker后,没有发现和centos中运行docker有多大不同。
而且alpine精简,小巧,功能强大,为啥不能在阿里ecs上使用?
说干就干。

阿里云上传镜像不支持iso,也就是说不能用常规的方法iso启动安装系统。
我们这里选择使用VHD格式,制作这个格式也简单,在virtualBox中就可以建立,安装完系统后上传到阿里云镜像生成就OK。

我们这里遇到几个问题,VHD的容量是生成VHD文件的时候就确定的,我们没法知道阿里云ecs的容量。所以需要安装镜像后在线扩容。

我们需要使用到 resize2fs 运行 apk add e2fsprogs-extra 安装

我们需要使用到 growpart 运行 apk add cloud-utils 安装
直接安装是找不到的,需要把 /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/edge/testinghttp://dl-cdn.alpinelinux.org/alpine/v3.11/community
解除注释后 apk update

扩容前

localhost:~# fdisk -l
Disk /dev/vda: 40 GB, 42949672960 bytes, 83886080 sectors
83220 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 *  0,32,33     12,223,19         2048     206847     204800  100M 83 Linux
/dev/vda2    12,223,20   45,130,21       206848     731135     524288  256M 82 Linux swap
/dev/vda3    45,130,22   130,138,8       731136    2097151    1366016  667M 83 Linux

localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     495.2M         0    495.2M   0% /dev/shm
/dev/vda3               640.5M     92.9M    500.9M  16% /
tmpfs                    99.1M    108.0K     98.9M   0% /run
/dev/vda1                92.8M     14.8M     71.0M  17% /boot

开始扩容

运行 growpart /dev/vda 3 后把分区表中剩余空间给第三分区,这时我们看一下情况,分区确实变大了,但是挂载依然不变。

localhost:~# growpart /dev/vda 3
CHANGED: partition=3 start=731136 old: size=1366016 end=2097152 new: size=83154911,end=83886047

localhost:~# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3ba1884a

Device     Boot  Start      End  Sectors  Size Id Type
/dev/vda1  *      2048   206847   204800  100M 83 Linux
/dev/vda2       206848   731135   524288  256M 82 Linux swap / Solaris
/dev/vda3       731136 83886046 83154911 39.7G 83 Linux

localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     495.2M         0    495.2M   0% /dev/shm
/dev/vda3               640.5M     92.9M    500.9M  16% /
tmpfs                    99.1M    108.0K     98.9M   0% /run
/dev/vda1                92.8M     14.8M     71.0M  17% /boot

这时再运行 resize2fs /dev/vda3 可以看到挂载尺寸也变大了。

localhost:~# resize2fs /dev/vda3
resize2fs 1.45.4 (23-Sep-2019)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 5
The filesystem on /dev/vda3 is now 10394363 (4k) blocks long.

localhost:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         10M     0   10M   0% /dev
shm             496M     0  496M   0% /dev/shm
/dev/vda3        40G  200M   38G   1% /
tmpfs           100M  108K   99M   1% /run
/dev/vda1        93M   15M   71M  18% /boot

「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」

pch18

(๑>ڡ<)☆谢谢老板~

使用微信扫描二维码完成支付

版权声明:如无特别说明,本文为作者原创,转载请在首行注明来源:https://pch18.cn/archives/318.html
添加新评论
暂无评论