IOS>> mm>> 返回
项目作者: badrelmers

项目描述 :
machinectl/systemd-nspawn manager (wrapper), and container builder
高级语言: Shell
项目地址: git://github.com/badrelmers/mm.git
创建时间: 2021-02-24T09:15:50Z
项目社区:https://github.com/badrelmers/mm

开源协议:GNU General Public License v3.0

下载


mm is a machinectl/systemd-nspawn manager

mmbuild is a container creator for nspawn using debootstrap (tested with debian and ubuntu, others may work too)

install

install mm and mmbuild to /usr/local/bin

  1. git clone https://github.com/badrelmers/mm
  2. bash ./mm/install.sh

How it works

all containers need to be saved somewhere, so I choosed to create a config file /etc/_mm.conf where we will save the path to the folders we want to use as a repository for the containers, I could have used the default machinectl folder /var/lib/machines but I prefer my method because like this I can format any time without problems, because mm will create a symlink from my defined repository to /var/lib/machines, like this you do not have to take care of moving the containers before formating the disks. another benefit is that we can use diferent disks to save the containers.
that is why I created the command mm register ContainerName which will create a symlink of the container inside /var/lib/machines

by default the created container will run with full privileges using the host networking. to run the container unprivileged or with more privileges or with a different network mode, then you have to read the content of mm edit ContainerName , understand it and edit it as needed. you can choose between priviliged (default), unprivileged or super privileged mode, and between bridged, NAT or host network (default).

TODO: add commands to change between privileged/unprivilged, and to change between host/nat/bridge network

example 1:

  1. # create a folder which will be used as the repository for nspawn containers and
  2. # add it to /etc/_mm.conf so it can be controlled by mm (you can create multiple
  3. # folders in diferent disks to be as repository)
  4. repository=/media/ssd2/_MyNspawnStore
  5. grep -Fq "${repository}" /etc/_mm.conf || { echo "${repository}" | sudo tee -a /etc/_mm.conf ; }
  6. # build an nspawn container
  7. mmbuild buster20210225124857 buster20210225124857 debian buster bbbbbbnn
  8. # run the container and open a shell inside it
  9. mm run buster20210225124857
  10. # to exit do
  11. ctrl-c
  12. # list running containers
  13. mm
  14. # list registred containers with machinectl
  15. mm ls
  16. # list all containers (registred and not registred with machinectl)
  17. mm lsa

example 2:

  1. # clone, rename, register a container, then delete it
  2. mm clone buster20210225124857
  3. mm rename buster20210225124857-clone... mybustercontainer
  4. mm register mybustercontainer
  5. mm run mybustercontainer
  6. # delete it
  7. mm stop mybustercontainer
  8. mm delete mybustercontainer

help

  1. mm help
  2. mmbuild help

mm help

  1. run NAME Start container as a service and connect to it
  2. start NAMEs... Start container as a service (start)
  3. sh NAME Invoke a shell in a container (shell)
  4. exec NAME "command" Run a command inside container
  5. reboot NAMEs... Reboot one or more containers (reboot)
  6. stop NAMEs... Power off one or more containers (poweroff)
  7. kill NAMEs... Terminate one or more VMs/containers (terminate)
  8. status NAMEs... Show VM/container details (status)
  9. info [NAMEs...] Show properties of one or more VMs/containers (show)
  10. edit NAME Edit my container service override file
  11. editrepo Edit /etc/_mm.conf repositories
  12. enable NAMEs... Enable automatic container start at boot (enable)
  13. disable NAMEs... Disable automatic container start at boot (disable)
  14. listautorun List all autorun services of containers
  15. Image Commands:
  16. ls List registred containers in /var/lib/machines (list-images)
  17. lsa list all containers in all repositories of /etc/_mm.conf
  18. lsaq list all containers in all repositories of /etc/_mm.conf (quicker, no dir space is showen)
  19. register NAMEs... Create a symlink of the container in /var/lib/machines & a clean service override
  20. unregister NAMEs... delete symlink of the container in /var/lib/machines & DELETE its service override/autorun too
  21. iinfo [NAMEs...] Show properties of image (show-image)
  22. istatus [NAMEs...] Show image details (image-status)
  23. clone NAME Clone a CT (CT dir & symlink, service override if they exist , but not autorun file; & hostname)
  24. rename NAME NewName Rename a CT (CT dir & symlink, service override and autorun files if they exist; & hostname)
  25. delete NAME Delete CT completly (CT dir, symlink, service override and autorun files)
  26. getpath NAME print container path
  27. correct NAME Correct effect of -U (uses --private-users=0 --private-users-chown)
  28. help,h Show help

mmbuild help

  1. mmbuild imagename Hostname(aZ09-) OS OS release pass [optional debootstrap args]
  2. examples:
  3. mmbuild buster20210225175246 buster20210225175246 debian buster bbbbbbnn
  4. mmbuild bullseye20210225175246 bullseye20210225175246 debian bullseye bbbbbbnn
  5. mmbuild testing20210225175246 testing20210225175246 debian testing bbbbbbnn
  6. mmbuild unstable20210225175246 unstable20210225175246 debian unstable bbbbbbnn
  7. mmbuild xenial20210225175246 xenial20210225175246 ubuntu xenial bbbbbbnn
  8. mmbuild bionic20210225175246 bionic20210225175246 ubuntu bionic bbbbbbnn
  9. mmbuild focal20210225175246 focal20210225175246 ubuntu focal bbbbbbnn

note:

it works fine and I use it for my daily use, but need some cleaning. for example comments inside code are a mix of spanish english.