New FAMILUG

The PyMiers

Thursday 6 February 2014

Tạo "máy ảo" với LXC

Bài này hướng dẫn dùng LXC để tạo các "máy ảo Linux" (NOTICE: không tạo được các "máy ảo" Windows/BSDs ...) dựa trên các template có sẵn. Container là từ dùng để chỉ "máy ảo" ấy.

Bài viết mặc định rằng bạn đang dùng Linux Kernel ở phiên bản đã hỗ trợ LXC.

Bài viết thực hiện trên
$ lsb_release -a; uname -r
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.3 LTS
Release:        12.04
Codename:       precise
3.8.0-26-generic
Trước hết cần cài đặt package "lxc", package này chứa các script giúp cho việc tạo/ sửa /xóa ... các container.


$ sudo apt-get install -y lxc

Xem danh sách các template có sẵn:


$ find /usr/lib/lxc/templates/
/usr/lib/lxc/templates/
/usr/lib/lxc/templates/lxc-sshd
/usr/lib/lxc/templates/lxc-opensuse
/usr/lib/lxc/templates/lxc-ubuntu-cloud
/usr/lib/lxc/templates/lxc-fedora
/usr/lib/lxc/templates/lxc-busybox
/usr/lib/lxc/templates/lxc-ubuntu
/usr/lib/lxc/templates/lxc-debian

Tạo "máy ảo" debian:

# lxc-create -n hvnlxc3 -t debian

No config file specified, using the default config
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/debian/rootfs-squeeze-amd64 ...
Downloading debian minimal ...
I: Retrieving Release
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.gpg
I: Retrieving Packages
...

Liệt kê các container:

# lxc-list
RUNNING
  hvnlxc (auto)

FROZEN

STOPPED
  foo
  hvnlxc3

Sau khi lệnh lxc-create chạy thành công, start container hvnlxc3

# lxc-start --name hvnlxc3
 sau đó login với user/passwd: root/root

No comments:

Post a Comment