这篇文章主要聚焦于debian系统,其他的linux发行版的用法应该是一致的。
You start by installing the needed tools, So, on my debian:
sudo apt-get install libvirt-dev virtinst libvirt-daemon libvirt-daemon-system
如果没有找到相应的软件包,你可以尝试一下apt-cache命令。
(If you cant found these softwares, you can try it : apt-cache)
系统提示你缺少什么软件就安装什么软件。
sudo apt-cache search libvirt
你还可以使用通配符进行模糊查找。 (You can fuzzy search with wildcard)
Then you got a libvirtd process running on your machine:
yubo@debian:~/git$ sudo ps u -C libvirtd
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 4470 1.4 0.7 787416 30212 ? Ssl 20:38 0:00 /usr/sbin/libvi
The role of libvirtd is quite important. It takes care of managing the VMSrunning on your host.You can control it with command virsh.
Before anything else, you should know that libvirt and virsh not only allow you to control VMs running on your own system, but can control VMs running on the remote systems or a cluster of physical machines. Every time you use virsh, With qemu,you need type it looks like:
qemu://xxx/system
qemu://xxx/session
I will introduce more details about virsh in another post,now i am focus on the libvirt-vms.
Here, libvirtd is listening the command send to /var/run/libvirt,so you may add a credential user for libvirt, and you have opportunity to write socket, which needs a user to belong to the libvirt group.
If you edit /etc/libvirt/libvirtd.conf, you can configure libvirt to wait for a commands using a variety of different mechanisms, including for example SSL encrypted TCP sockets.
yubo@debian:~/git$ sudo usermod -a -G libvirt yubo
Add my user name into libvirt group.
yubo@debian:~/git$ virsh -c qemu:///system net-list
Name State Autostart Persistent
----------------------------------------------------------
This means that there are no active virtual networks, Try one more time adding --all:
yubo@debian:~/git$ virsh -c qemu:///system net-list --all
Name State Autostart Persistent
----------------------------------------------------------
default inactive no yes
Now your network’s is default.
And notice the default network, If you want to inspect or change the configure file of the network, you can use either net-dumpxml or net-edit
h -c qemu:///system net-dumpxml default
<network>
<name>default</name>
<uuid>e46e2c1b-5263-4428-b8fc-bfa4805a2ebc</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:34:36:d3'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
I guess you could understand what is meaning above.Now your VM bridge name is virbbr0…
You can configure networking in many different ways, with nat, with bridging,with simple gateway fowarding… You can find all parameters on the page.
And you can change the definition by using net-edit.
net-undefine default # forever eliminate the default network
net-define file.xml #to define a new network starting from an .xml file
#you can
virsh ... net-dumpxml default > file.xml
then edit and then
virsh ... net-define file.xml
net-start default, to start the named default network
net-destory default, to stop the named defaultnetwork,with the ability of starting it again in the future.
net-autostart default, to automatically start the default network at boot.
yubo@debian:~/git$ virsh -c qemu:///system net-start default
Network default started
yubo@debian:~/git$ ps aux | grep libvirt
root 4470 0.0 0.7 1377240 30292 ? Ssl 20:38 0:00 /usr/sbi..
nobody 5155 0.0 0.0 52228 408 ? S 21:40 0:00 /usr/sb..
root 5156 0.0 0.0 52200 408 ? S 21:40 0:00 /usr/sbin/dnsmasq
----------------
yubo@debian:~/git$ sudo netstat -nulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 192.168.122.1:53 0.0.0.0:* 5155/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 5155/dnsmasq
-----------------
yubo@debian:~/git$ sudo netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 5155/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 546/sshd
libvirt started dnsmasq, which is a simple dhcp server with ability to also provide DNS.So you can try:
yubo@debian:~/git$ ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 94:c6:91:04:e6:91 brd ff:ff:ff:ff:ff:ff
inet 222.195.244.235/24 brd 222.195.244.255 scope global dynamic
enp1s0
valid_lft 2670sec preferred_lft 2670sec
inet6 fe80::96c6:91ff:fe04:e691/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue
state DOWN group default qlen 1000
link/ether 52:54:00:34:36:d3 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master
virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:34:36:d3 brd ff:ff:ff:ff:ff:ff
you can use iptables to see what happened:
sudo iptables -nvL
&&
sudo iptables -t nat -nvL
Now we have a network running for our VMs,we need to worry about storage.This is similar to lvm, On this post, i just dedicated a directory to storing images and volums.
But, you should mdkir needed dir with
sudo mkdir -p /opt/kvms/pools/devel
and try it:
yubo@debian:~$ virsh -c qemu:///system \
> pool-define-as devel \
> dir --target /opt/kvms/pools/devel
Pool devel defined
Here, we create a pool called devel in a directory , we can see this pool with:
yubo@debian:~$ virsh -c qemu:///system pool-list --all
Name State Autostart
-------------------------------------------
devel inactive no
--all as before, now we need to start it automatically with command:
yubo@debian:~$ virsh -c qemu:///system pool-autostart devel
Pool devel marked as autostarted
and start it with(must):
yubo@debian:~$ virsh -c qemu:///system pool-start devel
And you can see it again:
yubo@debian:~$ virsh -c qemu:///system pool-list --all
Name State Autostart
-------------------------------------------
devel active yes
To create and manage volumes, you can use vol-create,vol-delete,vol-resize,all the vol-* can be used.
For examole:
yubo@debian:~$ virsh -c qemu:///system vol-list devel
Name Path
------------------------------------------------------
With virt-install
yubo@debian:~$ virt-install -n debian-9 --ram 2048 --vcpus=2 \
--cpu=host -c ~/software/debian-9.1.0-amd64-xfce-CD-1.iso \
--os-type=linux --os-variant=debian \
--disk=pool=devel,size=10,format=qcow2 \
-w network=default --graphics=vnc
You must use sudo command to execute the command,next, you will enter into linux’s installing procession.
-n just a name.
-c is your debian-iso where it is located. Remember here, you just define a pool named devel, however, you not have ‘create it’
--disk=pool=devel,size=10,format=qcow2 means it have 10GB space disk to support your VMs.
virt-install version 1.5.1报错debian没有在它的安装字典中,可以尝试着使用debian9.
sudo virt-install destroy domain
sudo virt-install undefine domain
This is my first wrong step to try it.I missed it.
After installing VMs, you would better to use virt-viewer to start it.
Frist,you can start it with virsh:
virsh start my-vms #my vms-name is debian-9 or:
virsh autostart my-vms # debian-9.
So, you type virsh into virsh’s world.
yubo@debian:~$ sudo virsh
[sudo] yubo 的密码:
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh # list
Id Name State
----------------------------------------------------
8 debian-9 running
Remember, you use it with sudo.Here, you can see your vms’s id is 8,
Again, your vm-id is 8,so next:
sudo virt-viewer --connect qemu:///system 8
Congratulations! Enjoy it:)
这篇简单的介绍下了Makefile文件,但是如果你自己独自写一个完整的Makefile,这多少有些不现实。在类unix下,有个automake的工具,这个就可以好好利用.
在我的linux上,使用autoconf –version就可以知道有没有安装这个软件了。
利用同样的测试方法。
先后建立三个文件:hello.c -> configure.in -> Makefile.am 然后依次执行
aclocal && autoconf && automake --add-missing \
&& ./configure && make && ./hello
如果是安装软件的话,在上面的make后面添加 *make imstall *即可。
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("hello,world\n");
return 0;
}
root@yubo-2:/home/yubo/test/makefile# autoscan
root@yubo-2:/home/yubo/test/makefile# ls
autoscan.log configure.scan hello.c
看到上面的命令中生成了一个configure.scan文件,这个就是configure.in的模板(但是,我怎么记得现在推荐为configure.ac)
首先将configure.scan文件命名为configure.in(现在好像推荐使用configure.ac)
然后修改几个内容:
mv configure.scan configure.in
root@yubo-2:/home/yubo/test/makefile# cat configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(hello.c) # 修改
#AC_CONFIG_SRCDIR([hello.c]) #修改
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(hello.c, 1.0) # 修改
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT(Makefile) #修改
上面的文件中,以AC开头的宏来自autoconf, 以AM开头的automake,这些宏都是用M4语言写成的。
autoconf是用来生成自动配置软件源代码脚本(configure)的工具,它是非常独立地,不需要用户的干预。
autoconf命令来处理configure.ac/configure.in文件,生成一个configure文件,生成的configure文件是一个可以移植的shell脚本,来决定哪些库是可以用的、所用的平台有哪些特征、哪些头文件和库已经找到等等,然后将收集到的这些信息,编译成标记,生成一个Makefile,同时生成一个包含已定义的预处理符号的config.h。
要生成configure文件, 你必须告诉autoconf如何找到你所用的宏,方式是使用aclocal程序来生成你的aclocal.m4
aclocal文件根据configure.in文件的内容,自动生成aclocal.m4文件, aclocal根据configure.in文件的内容,自动生成aclocal.m4文件。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”。
root@yubo-2:/home/yubo/test/makefile# aclocal
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'
root@yubo-2:/home/yubo/test/makefile# ls
aclocal.m4 autom4te.cache autoscan.log configure.in hello.c
root@yubo-2:/home/yubo/test/makefile# autoconf
root@yubo-2:/home/yubo/test/makefile# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c
m4是一个宏处理器。将输入拷贝到输出,同时将宏展开。宏可以是内嵌的,也可以是用户定义的。除了可以展开宏,m4还有一些内建的函数,用来引用文件,执行命令,整数运算,文本操作,循环等。m4既可以作为编译器的前端,也可以单独作为一个宏处理器。
接下来就是新建Makefile.am文件了。automake会根据你写的Makefile.am自动生成Makefile.in文件的。
root@yubo-2:/home/yubo/test/makefile# cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
这个命令的主要功能就是从Makefile.am文件产生Makefile.in文件,
一个典型的automake输入文件只是一系列变量的定义,从而产生Makefile.in文件。
接下来运行命令:
automake --add-missing
下面是我的显示台上的输出:
root@yubo-2:/home/yubo/test/makefile# automake -add-missing
automake: error: unrecognized option '-dd-missing'.
automake: Try '/usr/bin/automake --help' for more information.
root@yubo-2:/home/yubo/test/makefile# automake --add-missing
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
configure.in:7: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.in:7:
http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.in:10: installing './compile'
configure.in:7: installing './install-sh'
configure.in:7: installing './missing'
configure.in:6: error: required file 'config.h.in' not found
Makefile.am: installing './depcomp'
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
再次声明,我在这篇教程里,不止一次提醒我有警告产生,而且意思非常明确,你可以试一试。我这里为了结果一致,暂时没有改正过来,需要大家的注意。
基本上这篇文章就够了。
下载busybox源码,进行安装。最好使用git,这样可以进行最新的跟踪。
https://busybox.net/source.html
配置busybox,你可以使用 make menuconfig命令。这里,有几点是需要我们注意的。
因为Linux运行环境当中是不带动态库的,所以必须以静态方式来编译BusyBox。修改
Busybox Settings —> Build Options —> [*] Build BusyBox as a static binary(no shared libs)
CONFIG_DESKTOP=n
不需要配置DESKTOP。
make
make install
这样安装完成后,在busybox目录下有个_install目录,这里面就是创造root fs的源代码。
lspci
lspci | grep -i wireless
lspci | egrep -i --color 'wifi|wlan|wireless'
我的输出是
09:00.0 Network controller: Intel Corporation Centrino Wireless-N 105
(rev c4)
请记住 09:00.0利用他你可以找到设备名或者驱动名。
我的机子上的信息是:

iwconfig 命令是一个类似于ifconfig命令的无线命令,顾名思义,就是管理网络的。它维护了基本的无线信息,比如ssid, mode,channel,bit rates, power或者更多其他的东西。下面是展示wlan0接口:

上面的图片展示了这些内容:
MAC 网络协议
ssid
The NWID
频率
接入点
比特率
电源管理 …
yubo@debian:~$ sudo iwconfig wlan0 | grep -i --color quality
Link Quality=64/70 Signal level=-46 dBm
cat /proc/net/wireless

可惜的是,在debian的系统上,这个方法貌似不太好用,倒是在Ubuntu上使用的非常好,你可以直接新建一个(Shared)wifi热点。
算是一个神器了,字符图形界面的,可以试一试。安装完成后就可以直接运行
wavemon
命令即可。
还有几个命令,暂时先写在这里,后来总结的记在这里。
做一次文章的搬运工吧!
configure.ac和configure.in是Autoconf工具(由autoconf命令产生configure 脚本)的两个主要的源文件。区别在于configure.in是一个比较旧的文件名,目前仍可 以使用。configure.ac是适用于新的软件包。.in的后缀文件名现在被推荐仅仅用于运行configure脚本后产生config.status.
Makefile.am是Automake的源文件,Automake处理它产生Makefile.in,这个文件后来被config.status处理,这样才会产生最终的Makefile.
当运行完毕./configure命令后,会产生以下文件
«穷爸爸,富爸爸»这本书很早就看过,现在结合视频重新回味一下。
不要让债务的增长速度超过收入
不要让收入的增长速度超过生产率
尽一切努力提高生产力