参考文档:
《MAAS CLI》
《Creating a custom Ubuntu image (snap/2.9/UI)》
首先: 登陆(必须)maas cli
在之前生成maas账户时,生成过api key。
sudo maas-region apikey --username=$PROFILE > $API_KEY_FILE
实际命令写法为:
sudo maas apikey --username admin > ~ubuntu/admin-api-key
可以点击右上角的账户,看到当前用户的api key。
然后,使用用maas账户名登陆maas cli。
例:下面使用admin账户登陆
maas login admin http://localhost:5240/MAAS/api/2.0
然后会提醒输入api key。
或者像下面这样写一个方便的shell脚本,例如名字为maas-login.sh:其中的“API_KEY_FILE=”之后的路径要根据实际路径更改。
#!/bin/sh
# Change these 3 values as required
PROFILE=admin
API_KEY_FILE=/home/ubuntu/tmp/api_key
API_SERVER=localhost
MAAS_URL=http://$API_SERVER/MAAS/api/2.0
maas login $PROFILE $MAAS_URL - < $API_KEY_FILE
如何生生一个用于MAAS的自定义的ubuntu镜像
注意:在提取rootfs时,LXD可能会阻止创建设备文件,建议在金属或VM上执行以下操作:
1 从images.maas.io下载rootfs
wget http://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-root.tar.xz
2 生成工作路径
mkdir /tmp/work
3 解压rootfs
cd /tmp/work
sudo tar xf ../focal-server-cloudimg-amd64-root.tar.xz
或者
unsquashfs ../focal-server-cloudimg-amd64-root.squash
4 配置chroot(变更根目录位置)
sudo mount -o bind /proc /tmp/work/proc
sudo mount -o bind /dev /tmp/work/dev
sudo mount -o bind /sys /tmp/work/sys
sudo mv /tmp/work/etc/resolv.conf /tmp/work/etc/resolv.conf.bak
sudo cp /etc/resolv.conf /tmp/work/etc/
5 进入chroot
sudo chroot /tmp/work /bin/bash
6 自定义镜像
apt update
apt dist-upgrade
apt install emacs-nox jq tree
apt autoremove
7 退出chroot并卸载绑定
exit
sudo umount /tmp/work/proc
sudo umount /tmp/work/dev
sudo umount /tmp/work/sys
sudo mv /tmp/work/etc/resolv.conf.bak /tmp/work/etc/resolv.conf
8 生成TGZ
sudo tar -czf /tmp/focal-custom.tgz -C /tmp/work .
9 上载tgz到maas
Note: Ubuntu release names and versions are reserved
maas $PROFILE boot-resources create name=‘custom/focal-custom’ title=‘Ubuntu 20.04 Custom Image’ architecture=‘amd64/generic’ filetype=‘tgz’ content@=focal-custom.tgz
实际为:
maas admin boot-resources create name=‘custom/focal-custom’ title=‘Ubuntu 20.04 Custom Image’ architecture=‘amd64/generic’ filetype=‘tgz’ content@=focal-custom.tgz
10 像平常时那样配置和部署
Configure and deploy as normal