https://wiki.archlinux.org/api.php?action=feedcontributions&user=Athurg&feedformat=atomArchWiki - User contributions [en]2024-03-29T06:48:36ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468929Go package guidelines (简体中文)2017-02-24T01:55:39Z<p>Athurg: </p>
<hr />
<div>[[Category:Package development (简体中文)]]<br />
[[en:Go package guidelines]]<br />
[[zh-hans:Go package guidelines]]<br />
[[ja:Go パッケージガイドライン]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 通用准则 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* 对于使用"go"工具下载的软件包,只有当它不是从tar包或者tagged提交(而是从trunk/HEAD)下载源码时,软件包名才添加"-git"后缀。<br />
** 类似的,对于mercurial 版本控制系统,只有当软件包未从release-revision下载源码时,才添加"-hg"后缀。<br />
** 其他版本控制系统,请一并参考该准则。<br />
** "go"工具下载那个分支或者Tag通常有他自己的一套逻辑。请参考 {{Ic|go get --help}}.<br />
* 如果有多个同名的软件包,可考虑将作者的名字添加到软件包名之中,例如:{{AUR|dcpu16-kballard}}。<br />
** 当然,通常情况下,最流行的软件包会使用最短或者"最佳"的软件包名。<br />
* 如果软件开发者本身并没有正式的官方发布,那么这种后缀名 (例如 {{Ic|-hg}}, {{Ic|-git}} 或 {{Ic|-svn}}) 只是可选的。 一方面,这种软件包通常都是直接通过源码版本库下载使用的。另一方面, 大多数 Go 语言项目从不发布任何tarball,而只发布源码版本库。并将版本库的master分支、HEAD提交以外的分支、Tag作为官方发布的方式。另一方面,Go语言官方的模块安装方式 {{Ic|go get}} 也往往直接使用源码版本库。所以请根据情况作出最佳选择。<br />
<br />
=== 打包 ===<br />
* Go 语言项目通常只包含软件库、可执行文件或者两者俱有。请以合适的方式打包他们。后续有几个例子以供参考。<br />
* 有些 Go 语言项目并不支持最新版本的Go编译。这种情况下<br />
** 直接执行 {{Ic|go build -fix}} 一般就可以搞定了。如果仍有问题,请上报给上游开发者,并且他们修复。<br />
* 有些Go语言项目并没有版本号或者授权协议文件。这种情况下:<br />
** 使用 license=('unknown') 并向上游开发者提交授权协议缺失的报告。<br />
** 如果没有版本号,请使用 "0.1", "1" 或者Git库的revision ( 其他版本控制系统类似)。<br />
** 作为备选,可以用当前日期作为版本号,格式形如 {{Ic|YYYYMMDD}}。<br />
* 由于Go语言应用常常都是静态编译后发布可执行文件,因此通常都会直接打包Go语言应用而不是他的库。<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
这是推荐的使用"go get"的方式,请优先选用这种方式,后文介绍的那种仅供参考。<br />
<br />
这种方式将依赖于"go get"。<br />
<br />
通常情况下你无需修改 build() 或 package() 函数,只需要修改前面定义的变量 (pkgname 等)即可。<br />
<br />
如果打包失败,请先确保手动执行"go get"能成功。<br />
<br />
{{提示| 如果打包失败,尝试去掉 {{Ic|/...}}再试试!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
感谢 Rémy Oudompheng 提供该范例。<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
另外一种依靠 {{Ic|go get}}的方式如下。<br />
<br />
你一般不需要修改 build() 或 package() 函数,只需要修改前面的变量 (pkgname 等)即可。<br />
<br />
如果打包有问题,请先确保手动执行 {{Ic|go get}} 没问题。<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468928Go package guidelines (简体中文)2017-02-24T01:51:44Z<p>Athurg: /* 命名 */</p>
<hr />
<div>[[Category:Package development (简体中文)]]<br />
[[en:Go package guidelines]]<br />
[[ja:Go パッケージガイドライン]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 通用准则 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* 对于使用"go"工具下载的软件包,只有当它不是从tar包或者tagged提交(而是从trunk/HEAD)下载源码时,软件包名才添加"-git"后缀。<br />
** 类似的,对于mercurial 版本控制系统,只有当软件包未从release-revision下载源码时,才添加"-hg"后缀。<br />
** 其他版本控制系统,请一并参考该准则。<br />
** "go"工具下载那个分支或者Tag通常有他自己的一套逻辑。请参考 {{Ic|go get --help}}.<br />
* 如果有多个同名的软件包,可考虑将作者的名字添加到软件包名之中,例如:{{AUR|dcpu16-kballard}}。<br />
** 当然,通常情况下,最流行的软件包会使用最短或者"最佳"的软件包名。<br />
* 如果软件开发者本身并没有正式的官方发布,那么这种后缀名 (例如 {{Ic|-hg}}, {{Ic|-git}} 或 {{Ic|-svn}}) 只是可选的。 一方面,这种软件包通常都是直接通过源码版本库下载使用的。另一方面, 大多数 Go 语言项目从不发布任何tarball,而只发布源码版本库。并将版本库的master分支、HEAD提交以外的分支、Tag作为官方发布的方式。另一方面,Go语言官方的模块安装方式 {{Ic|go get}} 也往往直接使用源码版本库。所以请根据情况作出最佳选择。<br />
<br />
=== 打包 ===<br />
* Go 语言项目通常只包含软件库、可执行文件或者两者俱有。请以合适的方式打包他们。后续有几个例子以供参考。<br />
* 有些 Go 语言项目并不支持最新版本的Go编译。这种情况下<br />
** 直接执行 {{Ic|go build -fix}} 一般就可以搞定了。如果仍有问题,请上报给上游开发者,并且他们修复。<br />
* 有些Go语言项目并没有版本号或者授权协议文件。这种情况下:<br />
** 使用 license=('unknown') 并向上游开发者提交授权协议缺失的报告。<br />
** 如果没有版本号,请使用 "0.1", "1" 或者Git库的revision ( 其他版本控制系统类似)。<br />
** 作为备选,可以用当前日期作为版本号,格式形如 {{Ic|YYYYMMDD}}。<br />
* 由于Go语言应用常常都是静态编译后发布可执行文件,因此通常都会直接打包Go语言应用而不是他的库。<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
这是推荐的使用"go get"的方式,请优先选用这种方式,后文介绍的那种仅供参考。<br />
<br />
这种方式将依赖于"go get"。<br />
<br />
通常情况下你无需修改 build() 或 package() 函数,只需要修改前面定义的变量 (pkgname 等)即可。<br />
<br />
如果打包失败,请先确保手动执行"go get"能成功。<br />
<br />
{{提示| 如果打包失败,尝试去掉 {{Ic|/...}}再试试!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
感谢 Rémy Oudompheng 提供该范例。<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
另外一种依靠 {{Ic|go get}}的方式如下。<br />
<br />
你一般不需要修改 build() 或 package() 函数,只需要修改前面的变量 (pkgname 等)即可。<br />
<br />
如果打包有问题,请先确保手动执行 {{Ic|go get}} 没问题。<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468926Go package guidelines (简体中文)2017-02-24T01:38:05Z<p>Athurg: /* 使用 go get */</p>
<hr />
<div>[[Category:Package development (简体中文)]]<br />
[[en:Go package guidelines]]<br />
[[ja:Go パッケージガイドライン]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 通用准则 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== 打包 ===<br />
* Go 语言项目通常只包含软件库、可执行文件或者两者俱有。请以合适的方式打包他们。后续有几个例子以供参考。<br />
* 有些 Go 语言项目并不支持最新版本的Go编译。这种情况下<br />
** 直接执行 {{Ic|go build -fix}} 一般就可以搞定了。如果仍有问题,请上报给上游开发者,并且他们修复。<br />
* 有些Go语言项目并没有版本号或者授权协议文件。这种情况下:<br />
** 使用 license=('unknown') 并向上游开发者提交授权协议缺失的报告。<br />
** 如果没有版本号,请使用 "0.1", "1" 或者Git库的revision ( 其他版本控制系统类似)。<br />
** 作为备选,可以用当前日期作为版本号,格式形如 {{Ic|YYYYMMDD}}。<br />
* 由于Go语言应用常常都是静态编译后发布可执行文件,因此通常都会直接打包Go语言应用而不是他的库。<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
这是推荐的使用"go get"的方式,请优先选用这种方式,后文介绍的那种仅供参考。<br />
<br />
这种方式将依赖于"go get"。<br />
<br />
通常情况下你无需修改 build() 或 package() 函数,只需要修改前面定义的变量 (pkgname 等)即可。<br />
<br />
如果打包失败,请先确保手动执行"go get"能成功。<br />
<br />
{{提示| 如果打包失败,尝试去掉 {{Ic|/...}}再试试!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
感谢 Rémy Oudompheng 提供该范例。<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
另外一种依靠 {{Ic|go get}}的方式如下。<br />
<br />
你一般不需要修改 build() 或 package() 函数,只需要修改前面的变量 (pkgname 等)即可。<br />
<br />
如果打包有问题,请先确保手动执行 {{Ic|go get}} 没问题。<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468925Go package guidelines (简体中文)2017-02-24T01:34:34Z<p>Athurg: /* 使用 go get */</p>
<hr />
<div>[[Category:Package development (简体中文)]]<br />
[[en:Go package guidelines]]<br />
[[ja:Go パッケージガイドライン]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 通用准则 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== 打包 ===<br />
* Go 语言项目通常只包含软件库、可执行文件或者两者俱有。请以合适的方式打包他们。后续有几个例子以供参考。<br />
* 有些 Go 语言项目并不支持最新版本的Go编译。这种情况下<br />
** 直接执行 {{Ic|go build -fix}} 一般就可以搞定了。如果仍有问题,请上报给上游开发者,并且他们修复。<br />
* 有些Go语言项目并没有版本号或者授权协议文件。这种情况下:<br />
** 使用 license=('unknown') 并向上游开发者提交授权协议缺失的报告。<br />
** 如果没有版本号,请使用 "0.1", "1" 或者Git库的revision ( 其他版本控制系统类似)。<br />
** 作为备选,可以用当前日期作为版本号,格式形如 {{Ic|YYYYMMDD}}。<br />
* 由于Go语言应用常常都是静态编译后发布可执行文件,因此通常都会直接打包Go语言应用而不是他的库。<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
This is the recommended way, instead of the method below.<br />
<br />
Here is a way that relies on go get.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with go get first.<br />
<br />
{{Note| Remove {{Ic|/...}} if the PKGBUILD fails!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
Thanks to Rémy Oudompheng for this one.<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
另外一种依靠 {{Ic|go get}}的方式如下。<br />
<br />
你一般不需要修改 build() 或 package() 函数,只需要修改前面的变量 (pkgname 等)即可。<br />
<br />
如果打包有问题,请先确保手动执行 {{Ic|go get}} 没问题。<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468924Go package guidelines (简体中文)2017-02-24T01:32:17Z<p>Athurg: /* 常规规范 */</p>
<hr />
<div>[[Category:Package development (简体中文)]]<br />
[[en:Go package guidelines]]<br />
[[ja:Go パッケージガイドライン]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 通用准则 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== 打包 ===<br />
* Go 语言项目通常只包含软件库、可执行文件或者两者俱有。请以合适的方式打包他们。后续有几个例子以供参考。<br />
* 有些 Go 语言项目并不支持最新版本的Go编译。这种情况下<br />
** 直接执行 {{Ic|go build -fix}} 一般就可以搞定了。如果仍有问题,请上报给上游开发者,并且他们修复。<br />
* 有些Go语言项目并没有版本号或者授权协议文件。这种情况下:<br />
** 使用 license=('unknown') 并向上游开发者提交授权协议缺失的报告。<br />
** 如果没有版本号,请使用 "0.1", "1" 或者Git库的revision ( 其他版本控制系统类似)。<br />
** 作为备选,可以用当前日期作为版本号,格式形如 {{Ic|YYYYMMDD}}。<br />
* 由于Go语言应用常常都是静态编译后发布可执行文件,因此通常都会直接打包Go语言应用而不是他的库。<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
This is the recommended way, instead of the method below.<br />
<br />
Here is a way that relies on go get.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with go get first.<br />
<br />
{{Note| Remove {{Ic|/...}} if the PKGBUILD fails!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
Thanks to Rémy Oudompheng for this one.<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
Here is another way that relies on {{Ic|go get}}.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with {{Ic|go get}} first.<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=468869Go package guidelines (简体中文)2017-02-23T10:33:05Z<p>Athurg: 初步翻译</p>
<hr />
<div>[[Category:Package development]]<br />
[[ja:Go パッケージガイドライン]]<br />
[[zh-hans:Go package guidelines]]<br />
{{Package guidelines}}<br />
<br />
Arch Linux 对 [[Wikipedia:Go (programming language)|Go]] 的支持非常完善。<br />
<br />
软件包 {{Pkg|go}} 中包含了 '''go''' 工具 (用于运行 {{Ic|go fix}}, {{Ic|go build}} 等)。 另外还有个提供 {{Ic|gccgo}} 的 {{Pkg|gcc-go}} 软件包。<br />
<br />
你可以用 [https://github.com/seletskiy/go-makepkg go-makepkg] 工具来协助你简单的打包Go程序,而不用从头到尾手动编写 PKGBUILD 。<br />
<br />
== 常规规范 ==<br />
<br />
=== 命名 ===<br />
* 对于使用Go语言编写的独立应用,使用小写字母的应用名作为软件包名。<br />
** 如果软件包名已被占用,请另选一个合适的。<br />
* 对于使用Go语言编写的软件库,请使用小写字母的 {{Ic|go-''库名''}} 作为软件包名。<br />
** 如果软件库名本身就是以 {{Ic|go-}} 开头的,请不要使用 {{Ic|go-''go-模块名''}} 这样的名字,而改用 {{Ic|go-''模块名''}}。<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== 打包 ===<br />
* Go projects are either just library files, just executables or both. Choose the appropriate way of packaging them. There are several examples below.<br />
* Some Go applications or libraries have not been updated to the latest version of Go yet.<br />
** Running {{Ic|go build -fix}} may often work, but it may have to be fixed by the developer. Report an issue upstream if this is the case.<br />
* Several Go projects do not have a version number or a license file.<br />
** Use license=('unknown') and report an issue to the developer if a license file is missing.<br />
** Use version "0.1", "1" or the git-revision (or equivalent for other version control systems) if the version number is missing.<br />
** Alternatively, use the current date as the version number, in this form {{Ic|YYYYMMDD}}.<br />
* Since Go applications are usually statically compiled, it is hard to envision reasons for packaging Go libraries instead of just Go applications.<br />
<br />
== PKGBUILD 范例 ==<br />
<br />
=== Go 语言开发的独立程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== 仅包含单个Go文件的程序 PKGBUILD ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== 参考示例包 ====<br />
* {{AUR|gorun}}<br />
<br />
=== 包含可执行文件的Go语言库 PKGBUILD ===<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
This is the recommended way, instead of the method below.<br />
<br />
Here is a way that relies on go get.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with go get first.<br />
<br />
{{Note| Remove {{Ic|/...}} if the PKGBUILD fails!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
Thanks to Rémy Oudompheng for this one.<br />
<br />
==== 使用 ''go get'' ====<br />
<br />
Here is another way that relies on {{Ic|go get}}.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with {{Ic|go get}} first.<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines&diff=468868Go package guidelines2017-02-23T10:21:14Z<p>Athurg: </p>
<hr />
<div>[[Category:Package development]]<br />
[[ja:Go パッケージガイドライン]]<br />
[[zh-hans:Go package guidelines]]<br />
{{Package guidelines}}<br />
<br />
[[Wikipedia:Go (programming language)|Go]] is well supported on Arch Linux.<br />
<br />
The {{Pkg|go}} package contains the '''go''' tool (for running {{Ic|go fix}}, {{Ic|go build}} etc). There is also {{Pkg|gcc-go}} which provides {{Ic|gccgo}}.<br />
<br />
[https://github.com/seletskiy/go-makepkg go-makepkg] tool provides easy way of packaging Go programs without need of crafting PKGBUILD files manually.<br />
<br />
== General guidelines ==<br />
<br />
=== Naming ===<br />
* For applications written in Go, use the name of the application as the package name, in lowercase.<br />
** Be creative if the name is already taken.<br />
* For libraries written in Go, use {{Ic|go-''modulename''}}, in lowercase.<br />
** If the name already starts with {{Ic|go-}}, do not call the package {{Ic|go-''go-modulename''}}, but just {{Ic|go-''modulename''}}.<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== Packaging ===<br />
* Go projects are either just library files, just executables or both. Choose the appropriate way of packaging them. There are several examples below.<br />
* Some Go applications or libraries have not been updated to the latest version of Go yet.<br />
** Running {{Ic|go build -fix}} may often work, but it may have to be fixed by the developer. Report an issue upstream if this is the case.<br />
* Several Go projects do not have a version number or a license file.<br />
** Use license=('unknown') and report an issue to the developer if a license file is missing.<br />
** Use version "0.1", "1" or the git-revision (or equivalent for other version control systems) if the version number is missing.<br />
** Alternatively, use the current date as the version number, in this form {{Ic|YYYYMMDD}}.<br />
* Since Go applications are usually statically compiled, it is hard to envision reasons for packaging Go libraries instead of just Go applications.<br />
<br />
== Sample PKGBUILDs ==<br />
<br />
=== Sample PKGBUILD for an application written in Go ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== Sample packages ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== Sample PKGBUILD for when only a single source file is available ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== Sample packages ====<br />
* {{AUR|gorun}}<br />
<br />
=== Sample PKGBUILDs for Go libraries that also includes executables ===<br />
<br />
==== Using ''go get'' ====<br />
<br />
This is the recommended way, instead of the method below.<br />
<br />
Here is a way that relies on go get.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with go get first.<br />
<br />
{{Note| Remove {{Ic|/...}} if the PKGBUILD fails!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
Thanks to Rémy Oudompheng for this one.<br />
<br />
==== Using ''go get'' ====<br />
<br />
Here is another way that relies on {{Ic|go get}}.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with {{Ic|go get}} first.<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=Go_package_guidelines&diff=468867Go package guidelines2017-02-23T10:19:23Z<p>Athurg: Add link to zh-hans</p>
<hr />
<div>[[Category:Package development]]<br />
[[ja:Go パッケージガイドライン]]<br />
[[zh-hans:VCS package guidelines]]<br />
{{Package guidelines}}<br />
<br />
[[Wikipedia:Go (programming language)|Go]] is well supported on Arch Linux.<br />
<br />
The {{Pkg|go}} package contains the '''go''' tool (for running {{Ic|go fix}}, {{Ic|go build}} etc). There is also {{Pkg|gcc-go}} which provides {{Ic|gccgo}}.<br />
<br />
[https://github.com/seletskiy/go-makepkg go-makepkg] tool provides easy way of packaging Go programs without need of crafting PKGBUILD files manually.<br />
<br />
== General guidelines ==<br />
<br />
=== Naming ===<br />
* For applications written in Go, use the name of the application as the package name, in lowercase.<br />
** Be creative if the name is already taken.<br />
* For libraries written in Go, use {{Ic|go-''modulename''}}, in lowercase.<br />
** If the name already starts with {{Ic|go-}}, do not call the package {{Ic|go-''go-modulename''}}, but just {{Ic|go-''modulename''}}.<br />
* For PKGBUILDS that uses the "go" tool to download the package, only add "-git" to the package name if it is not built from a tarball or a from a tagged release (but from trunk/HEAD).<br />
** Similarly for mercurial packages, only add "-hg" to the package name if it is not a release-revision.<br />
** Extend this pattern for other version control systems.<br />
** The go tool has its own logic for which branch or tag it should use. See {{Ic|go get --help}}.<br />
* Consider adding the name of the author to the package name if there are several applications that are named the same, like {{AUR|dcpu16-kballard}}.<br />
** In general, the most popular packages should be allowed to use the shortest or "best" name.<br />
* Postfixes to the package names (like {{Ic|-hg}}, {{Ic|-git}} or {{Ic|-svn}}) are optional if there are no official releases from the project in question. On one hand, it is common to use them when the package downloads from a VCS. On the other hand, most Go projects do not have any release-tarballs, only the repo which is used for branching/tagging the official release, if it is not ''trunk''. Also, {{Ic|go get}}, which is the "official" way to install Go modules, uses the repositories directly. Use your better judgement.<br />
<br />
=== Packaging ===<br />
* Go projects are either just library files, just executables or both. Choose the appropriate way of packaging them. There are several examples below.<br />
* Some Go applications or libraries have not been updated to the latest version of Go yet.<br />
** Running {{Ic|go build -fix}} may often work, but it may have to be fixed by the developer. Report an issue upstream if this is the case.<br />
* Several Go projects do not have a version number or a license file.<br />
** Use license=('unknown') and report an issue to the developer if a license file is missing.<br />
** Use version "0.1", "1" or the git-revision (or equivalent for other version control systems) if the version number is missing.<br />
** Alternatively, use the current date as the version number, in this form {{Ic|YYYYMMDD}}.<br />
* Since Go applications are usually statically compiled, it is hard to envision reasons for packaging Go libraries instead of just Go applications.<br />
<br />
== Sample PKGBUILDs ==<br />
<br />
=== Sample PKGBUILD for an application written in Go ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
cd "$pkgname-$pkgver"<br />
<br />
go build<br />
}<br />
<br />
package() {<br />
cd "$pkgname-$pkgver"<br />
<br />
install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"<br />
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== Sample packages ====<br />
* {{Pkg|gendesk}}<br />
* {{AUR|dcpu16}}<br />
<br />
=== Sample PKGBUILD for when only a single source file is available ===<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('GPL3')<br />
makedepends=('go')<br />
options=('!strip' '!emptydirs')<br />
source=("http://SERVER/$pkgname/$pkgname.go")<br />
sha256sums=('00112233445566778899aabbccddeeff')<br />
<br />
build() {<br />
go build -o "$pkgname"<br />
}<br />
<br />
package() {<br />
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
==== Sample packages ====<br />
* {{AUR|gorun}}<br />
<br />
=== Sample PKGBUILDs for Go libraries that also includes executables ===<br />
<br />
==== Using ''go get'' ====<br />
<br />
This is the recommended way, instead of the method below.<br />
<br />
Here is a way that relies on go get.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with go get first.<br />
<br />
{{Note| Remove {{Ic|/...}} if the PKGBUILD fails!}}<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=codesearch<br />
pkgver=20120515<br />
pkgrel=1<br />
pkgdesc="Code indexing and search written in Go"<br />
arch=('x86_64' 'i686')<br />
url="https://github.com/google/codesearch"<br />
license=('BSD')<br />
depends=('go')<br />
makedepends=('mercurial')<br />
options=('!strip' '!emptydirs')<br />
_gourl=github.com/google/codesearch<br />
<br />
build() {<br />
GOPATH="$srcdir" go get -fix -v -x ${_gourl}/...<br />
}<br />
<br />
check() {<br />
GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}/...<br />
}<br />
<br />
package() {<br />
mkdir -p "$pkgdir/usr/bin"<br />
install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"<br />
<br />
mkdir -p "$pkgdir/$GOPATH"<br />
cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING LICENSE.* COPYING.*; do<br />
if [ -e "$srcdir/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}<br />
<br />
Thanks to Rémy Oudompheng for this one.<br />
<br />
==== Using ''go get'' ====<br />
<br />
Here is another way that relies on {{Ic|go get}}.<br />
<br />
You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).<br />
<br />
If this does not work, test with {{Ic|go get}} first.<br />
<br />
{{bc|<nowiki># Maintainer: NAME <EMAIL><br />
<br />
pkgname=PACKAGE NAME<br />
pkgver=1.2.3<br />
pkgrel=1<br />
pkgdesc="PACKAGE DESCRIPTION"<br />
arch=('x86_64' 'i686')<br />
url="http://SERVER/$pkgname/"<br />
license=('MIT')<br />
makedepends=('go' 'git')<br />
options=('!strip' '!emptydirs')<br />
_gourl=SERVER.NET/PATH/MODULENAME<br />
<br />
build() {<br />
export GOROOT=/usr/lib/go<br />
<br />
rm -rf build<br />
mkdir -p build/go<br />
cd build/go<br />
<br />
for f in "$GOROOT/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
rm pkg<br />
mkdir pkg<br />
cd pkg<br />
<br />
for f in "$GOROOT/pkg/"*; do<br />
ln -s "$f"<br />
done<br />
<br />
platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`<br />
<br />
rm "$platform"<br />
mkdir "$platform"<br />
cd "$platform"<br />
<br />
for f in "$GOROOT/pkg/$platform/"*.h; do<br />
ln -s "$f"<br />
done<br />
<br />
export GOROOT="$srcdir/build/go"<br />
export GOPATH="$srcdir/build"<br />
<br />
go get -fix "$_gourl"<br />
<br />
# Prepare executable<br />
if [ -d "$srcdir/build/src" ]; then<br />
cd "$srcdir/build/src/$_gourl"<br />
go build -o "$srcdir/build/$pkgname"<br />
else<br />
echo 'Old sources for a previous version of this package are already present!'<br />
echo 'Build in a chroot or uninstall the previous version.'<br />
return 1<br />
fi<br />
}<br />
<br />
package() {<br />
export GOROOT="$GOPATH"<br />
<br />
# Package go package files<br />
for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do<br />
# If it's a directory<br />
if [ -d "$f" ]; then<br />
cd "$f"<br />
mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
for z in *; do<br />
# Check if the directory name matches<br />
if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then<br />
cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"<br />
fi<br />
done<br />
cd ..<br />
fi<br />
done<br />
<br />
# Package source files<br />
if [ -d "$srcdir/build/src" ]; then<br />
mkdir -p "$pkgdir/$GOROOT/src/pkg"<br />
cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"<br />
find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;<br />
fi<br />
<br />
# Package license (if available)<br />
for f in LICENSE COPYING; do<br />
if [ -e "$srcdir/build/src/$_gourl/$f" ]; then<br />
install -Dm644 "$srcdir/build/src/$_gourl/$f" \<br />
"$pkgdir/usr/share/licenses/$pkgname/$f"<br />
fi<br />
done<br />
<br />
# Package executables<br />
if [ -e "$srcdir/build/$pkgname" ]; then<br />
install -Dm755 "$srcdir/build/$pkgname" \<br />
"$pkgdir/usr/bin/$pkgname"<br />
fi<br />
}<br />
<br />
# vim:set ts=2 sw=2 et:</nowiki>}}</div>Athurghttps://wiki.archlinux.org/index.php?title=User:Athurg&diff=453563User:Athurg2016-10-11T08:58:58Z<p>Athurg: </p>
<hr />
<div>翻译的文章不多,如果大家在看我的文章的时候发现翻译错误或者文章过期需要更新,请联系我。<br />
<br />
<br />
联系方式:<br />
<br />
archlinux.wiki在gooth.org(用@替代“在”)</div>Athurghttps://wiki.archlinux.org/index.php?title=Mac_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=170369Mac (简体中文)2011-11-17T13:11:58Z<p>Athurg: /* rEFIt问题 */</p>
<hr />
<div>[[Category:Apple (简体中文)]]<br />
{{i18n|MacBook}}<br />
{{Article summary start|摘要}}<br />
{{Article summary text|一份详尽的在MacBook上安装Arch Linux指南教程(第一次在Arch Wiki上翻译,不当之处还请指正)}}<br />
{{Article summary heading|相关文章}}<br />
{{Article summary wiki|Official Arch Linux Install Guide}}<br />
{{Article summary wiki|Beginners Guide}}<br />
{{Article summary wiki|General Recommendations}}<br />
{{Article summary end}}<br />
<br />
在MacBook上安装Arch Linux与在其他电脑上安装Arch Linux非常相似。然而,由于MacBook的特殊硬件配置,需要一些特殊的考虑,因此建立MacBook专页。更多背景信息,可以从[https://wiki.archlinux.org/index.php/Official_Arch_Linux_Install_Guide 官方安装指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide 新手指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide_Appendix 新手指南扩展]以及[https://wiki.archlinux.org/index.php/Post_Installation_Tips 安装后小贴士]上获取。本文同样适用于MacBook Pro系列机型,也支持32位及64位版本。如果您正在使用MacBook 5,2并且有其他疑问,请猛击[https://wiki.archlinux.org/index.php/Macbook5,2 MacBook5,2]获取帮助。<br />
<br />
==概述==<br />
<br />
在MacBook上安装Arch Linux可以分为一下几个步骤<br />
#'''[[#安装 Mac OS X 以及固件更新|安装Mac OS X]]''':忽略安装过程最后的配置,此处将从一个新安装的OS X开始。<br />
#'''[[#安装 Mac OS X 以及固件更新|固件更新]]''':这将有助于减少错误以及提供硬件的新特性。<br />
#'''[[#分区|分区]]''':这步中可以调整OS X分区大小货删除分区并为Arch Linux建立分区。<br />
#'''[[#安装|安装Arch Linux]]''':真正安装Arch Linux的过程。<br />
#'''[[#安装后配置|安装后配置]]''':针对MacBook的特殊配置。<br />
<br />
{{Tip|rEFIt是EFI固件电脑上很流行的一个启动器,包括了Mac电脑。它能够在系统安装过程中的任何时候安装,更多信息请猛击[[MacBook#rEFIt|rEFIt]]}}<br />
<br />
==安装 Mac OS X 以及固件更新==<br />
[http://www.apple.com/ Apple]已经提供了详尽的安装Mac OS X的教程。按照此教程安装好OS X后,点击菜单:<br />
<br />
苹果图标 --> 软件升级<br />
<br />
来更新所有软件。更新完成之后,您需要重启电脑。重启后请再次检查软件升级以确保所有软件都更新到了最新版。<br />
<br />
{{Note|有时软件更新不会对您电脑的所有固件惊醒更新,然而,您可以在苹果支持网站中自己搜索这些升级。}}<br />
<br />
如果您不打算安装Mac OS X,请为这些文件做好备份:<br />
<br />
/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport<br />
<br />
这个文件将在后期调试iSight时用到。同样的,请备份色彩配置<br />
<br />
/Library/ColorSync/Profiles/Displays/<此处的文件><br />
<br />
在调试[[#色彩配置 | 色彩配置]]时会用到。<br />
<br />
==分区==<br />
<br />
下一步就是将硬盘重新分区。如果Mac OS X按照一般流程安装,那么您的硬盘将是GPT格式分区表,会有以下两个分区:<br />
<br />
*'''EFI分区''':一个大小有200MB的分区,在磁盘开始部分。有些分区工具会将其读作FAT分区,通常标为''#1''<br />
*'''Mac OS X分区''':这个分区''(HFS+)''一般是占用了硬盘的所有其他空间。通常标为''#2''<br />
<br />
分区策略依据您想安装多少操作系统而定,有如下两个选项:<br />
<br />
*[[仅安装Arch Linux|仅安装Arch Linux]]单系统。<br />
*[[Mac OS X与Arch Linux共存|Mac OS X与Arch Linux共存]]双系统。<br />
<br />
如果您不知道改选哪种方式,我们建议您选择双系统,这样您可以在任何时候回到Mac OS X。<br />
<br />
===仅安装Arch Linux===<br />
<br />
这种情况最好办。大多数情况下,分区操作与将Arch Linux安装在其他硬件上没两样。 唯一的不同点在于MacBook的启动响铃。为了确保启动响铃是关闭的,请提前在Mac OS X系统中就将音量调至静音。MacBook固件依赖于Mac OS X的配置。请注意,如果你选择去掉Mac OS X的分区,除了用另外一块硬盘来加载OS X进行设置固件外没有其他任何办法。<br />
<br />
这之后可以使用parted来进行分区操作。最简单的办法是将分区表转为msdos格式,然后和平常一样来进行分区。GRUB不能认出GPT格式的分区表。<br />
<br />
{{Note|用parted对硬盘分区只需要用从Arch Linux core install disk启动,然后以root权限打开parted程序。此操作可在安装前完成。}}<br />
<br />
完成这一步骤之后,可以查看[[#安装|安装]]部分。<br />
<br />
===Mac OS X与Arch Linux共存===<br />
<br />
让Mac OS X与Arch Linux共存的最简单的分区方法是用Mac OS X的分区工具后用Arch Linux的工具完善。<br />
<br />
{{Warning|这种方法最好只在新安装的OS X中尝试,在一个预安装的OS X中可能发生不可预料的结果。}}<br />
<br />
过程:<br />
<br />
*在Mac OS X中,运行磁盘工具<br />
<br />
*在左侧栏,选择硬盘,请注意,是选择硬盘,而不是分区。点击右侧的分区标签。<br />
<br />
*选择要重置大小的分区。<br />
<br />
*确定你要给你的Mac OS X分区留多少空间,以及留多少空间给Arch Linux。记住一个Mac OS X大约需要15至20GB的空间,请留足空间以方便日后安装软件。<br />
<br />
*最后,设置Mac OS X分区的大小,然后在空白区域创建一个分区。<br />
<br />
{{Note|如果你希望在Mac OS X与Arch Linux之间共享一个分区,那么需要做些额外的操作,具体操作可以参照此处[[#HFS分区共享|分区共享]]}}<br />
<br />
*上述操作顺利完成后就可以进入下一步了,否则,请一定在Mac OS X上解决这些问题。<br />
<br />
*按住ALT键来从Arch Linux启动光盘启动。<br />
<br />
*现在,运行parted来完成后续操作。<br />
<br />
# parted<br />
<br />
*删除空分区。你可以随意按照你的想法设置这个分区。请注意MBR是必须装在4个主分区上的,包括了EFI预留分区。也就是留下了2个主分区给Arch Linux。一种分区策略是分配一个根分区和一个Home分区,然后swap可以使用文件。要不然就是分配一个分区用于共享。下面会有详细说明。<br />
<br />
*此时,如果你需要多系统启动,你需要重启电脑,用rEFIt来修复磁盘上的分区表。如果你这样干,那您会需要重装GRUB来是Mac系统认出Linux分区。当你进入rEFIt菜单后,选择更新分区表,然后按Y<br />
<br />
# reboot<br />
<br />
*完成了,可以继续安装过程了。<br />
<br />
==从GRUB直接启动==<br />
<br />
在efi上直接启动GRUB2而不用rEFIt是可以的。一下的操作在MacBook7,1上是可行的。建议将GRUB安装在fat32或者HFS+分区上,ext2或者ext3应该也行。GRUB的苹果加载命令在7,1上还暂时不能使用,但可以用过下面的补丁实现[https://savannah.gnu.org/bugs/index.php?33185 补丁地址]。<br />
<br />
GRUB装上硬盘分区后,固件需要知道从哪儿启动它。这步操作可以在OS X或者OS X安装光盘。下面的命令指明了GRUB是安装在OS X系统的/efi/grub中<br />
<br />
sudo bless --folder /efi/grub --file /efi/grub/grub.efi<br />
<br />
===编译===<br />
<br />
有些型号可能需要将EFI_ARCH设置成i386。<br />
<br />
bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub<br />
cd grub<br />
./autogen.sh<br />
patch -p1 < appleloader_macbook_7_1.patch<br />
export EFI_ARCH=x86_64<br />
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""<br />
make<br />
cd grub-core<br />
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot<br />
cp grub.efi *.mod *.lst yourinstalllocation<br />
<br />
===grub.cfg示例===<br />
<br />
此处应该有更好的方法来加载Windows系统。<br />
<br />
<pre><br />
set debug=video<br />
insmod efi_gop<br />
<br />
menuentry "Arch Linux EFI" {<br />
set root=(hd0,3)<br />
#search --set -f /boot/vmlinuz26-efi-physical<br />
#loadbios /boot/vbtrace_bios.bin /boot/int10.bin<br />
linux /boot/vmlinuz26-efi-physical root=/dev/sda3 reboot=pci resume=/dev/sda3 resume_offset=151552<br />
initrd /boot/kernel26-efi-physical.img<br />
}<br />
<br />
menuentry "MacOSX" {<br />
set root=(hd0,2)<br />
# Search the root device for Mac OS X's loader.<br />
#search --set -f /usr/standalone/i386/boot.efi<br />
# Load the loader.<br />
chainloader /usr/standalone/i386/boot.efi<br />
}<br />
<br />
menuentry "Windows 7" {<br />
appleloader HD<br />
}<br />
<br />
menuentry "Boot from CD" {<br />
appleloader CD<br />
}<br />
<br />
menuentry "Boot from USB" {<br />
appleloader USB<br />
}<br />
</pre><br />
<br />
==安装==<br />
<br />
{{Note|本部分安装过程只是用于Mac OS X与Arch Linux共存的情况,如果你只想单独使用Arch Linux,可以按照官方安装指南,然后跳到[[#安装后配置|安装后配置]]}}<br />
<br />
*从Arch Linux安装光盘启动<br />
<br />
{{Note|有些MacBook用户反映键盘不能正确响应,那就按照下面的参数来启动光盘。}}<br />
<br />
{{Note|截止2011年4月30日,MacBook7,1不能从普通的iso镜像启动,但最新的[https://wiki.archlinux.org/index.php/Archboot archboot]应该有用。}}<br />
<br />
boot: arch noapic irqpoll acpi=force<br />
<br />
*以root登陆<br />
<br />
*打开Arch Linux安装程序<br />
<br />
/arch/setup<br />
<br />
*按照[[官方安装文档]]中说明的过程来做,但是在下面几个部分中请留意:<br />
**在[[Official Arch Linux Install Guide#Prepare Hard Drive | 准备磁盘]]部分,只要做设置磁盘挂在这步,注意要设对磁盘挂载点。<br />
**在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,编辑menu.lst文件,添加'''reboot=pci'''到'''kernel'''行的末尾,例如下面这行:<pre style="margin: .5em 0; padding: .5em 1em">kernel /vmlinuz26 root=/dev/sda5 ro reboot=pci</pre>这样你的MacBook才能从Arch Linux正常重启<br />
**还是在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,将GRUB安装至{{Codeline|/boot}}所在的分区。{{Warning|别把GRUB安装到''/dev/sda''这样的地方!!!这样做会造成系统不稳定。}}<br />
**在[[Official Arch Linux Install Guide#Configure System | 配置系统]]部分,编辑 /etc/mkinitcpio.conf,添加'''usbinput'''到'''HOOKS'''行的'''autodetect'''之后。这样才能在Arch Linux启动之前加载键盘驱动<br />
<br />
*安装完成之后就可以重启系统了。<br />
<br />
# reboot<br />
<br />
*把Arch Linux安装光盘从光驱中退出。<br />
<br />
==安装后配置==<br />
<br />
===Xorg===<br />
<br />
按照[[Xorg]]来安装Xorg。<br />
<br />
====视频====<br />
<br />
不同的MacBook有不同型号的显卡,可以通过下面命令来查看显卡种类<br />
<br />
$ lspci | grep VGA<br />
<br />
*如果返回的字符串中包含'''intel''',那你只需要安装'''xf86-video-intel'''驱动,用如下命令:<br />
<br />
# pacman -S xf86-video-intel<br />
<br />
*如果返回的是nVidia,可以参看[[NVIDIA]]<br />
<br />
*如果返回ATI或者AMD,参见[[ATI]]<br />
<br />
=====NVIDIA注意=====<br />
<br />
{{ Tip|MacBookPro 6,2 - 使用合适的[[NVIDIA]]驱动,在使用[https://wiki.archlinux.org/index.php/NVIDIA#Enabling_Pure_Video_HD_.28VDPAU.2FVAAPI.29 Pure Video HD]之后支持硬件视频解码。}}<br />
<br />
对于使用NVIDIA显卡的MacBook,背景亮度可以通过[[AUR]]中的[http://aur.archlinux.org/packages.php?ID=25467 nvidia-bl]包解决。<br />
<br />
=====MacBook 6,2+-EFI=====<br />
<br />
截至2011年4月30日,nvidia驱动在此类EFI型号的机子下不能正常工作。可以了解一下[http://aur.archlinux.org/packages/mesa-git/PKGBUILD mesa-git]这个包。<br />
<br />
====触摸板====<br />
<br />
触摸板应该已经有了基本的功能。可以安装AUR中的[http://aur.archlinux.org/packages.php?ID=46339 xf86-input-multitouch-git]包来达到和Mac OS X类似的多点触控效果,最多支持三点触控,包含了三指水平与垂直滑动。可以从[http://bitmath.org/code/multitouch/ 项目主页]<br />
获取更多消息。<br />
<br />
xf86-input-multitouch-git除了编辑源代码外不支持配置。一些用户也正面临这从palm上得到错误的点击。现在有个可定制度更高的包[http://aur.archlinux.org/packages.php?ID=48505 xf86-input-mtrack-git]。在其[https://github.com/BlueDragonX/xf86-input-mtrack readme]中能得到更多配置信息。<br />
<br />
下面的配置在MacBook 7,1中正常工作<br />
<br />
Option "Thumbsize" "50"<br />
Option "ScrollDistance" "100"<br />
<br />
可能你还需要添加下面的内容<br />
<br />
MatchDevicePath "/dev/input/event10"<br />
<br />
在更旧的MacBook机型上,比如MacBook 2,1中,可能需要安装xf86-input-synaptics包才能正常工作。可以查看[[Touchpad Synaptics]]获取更多信息。<br />
<br />
====键盘====<br />
<br />
MacBook的键盘默认是能正常工作的。如果想切换fn键,可以查看[[Apple Keyboard]]。<br />
<br />
可以通过'''xbindkeys'''来重新设置键,或者通过DE配置。有另一种很好的方法,安装[http://aur.archlinux.org/packages.php?ID=14833 pommed]<br />
<br />
根据你MacBook的硬件来配置'''/etc/pommed.conf''',可以以'''/etc/pommed.conf.mac'''或者'''/etc/pommed.conf.ppc'''为模板来建立这个配置。<br />
<br />
=====NVIDIA配置=====<br />
===无线配置===<br />
===电源管理===<br />
====笔记本模式工具====<br />
====睡眠(内核挂起)====<br />
====休眠====<br />
===声音配置===<br />
===蓝牙===<br />
===iSight配置===<br />
===温度感应===<br />
===色彩配置===<br />
===苹果远程控制===<br />
===HFS分区共享===<br />
===HFS+ 分区===<br />
===Home目录共享===<br />
====在OS X中====<br />
=====第一步:改变UID与GID=====<br />
=====第二步:改变Home目录权限=====<br />
====在Arch中====<br />
===避免GRUB启动前EFI长时间执行===<br />
===关闭启动响铃===<br />
==rEFIt==<br />
<br />
{{Note | rEFIt只是在开机是给你提供OS X和Linux的启动菜单而已。如果没有这个需求的话,rEFIt不是必须的。}}<br />
<br />
详情参考[http://refit.sourceforge.net/myths/ refit myths].<br />
<br />
在OS X下,从[http://refit.sourceforge.net/ Refit主页]下载".dmg"格式的安装包,并像其他苹果软件一样安装。<br />
<br />
{{Note | 如果你此前已经对磁盘分过区的话(比如准备安装ArchLinux之前的准备),那rEFIt默认是不启用的。你需要手动执行安装到系统路径/efi/refit/的"enable.sh"脚本}}<br />
<br />
手动启用rEFIt的方法:<br />
* 打开'''终端''':<br />
* 执行'''cd /efi/refit; ./enable.sh'''命令<br />
<br />
<br />
<br />
===rEFIt可能会遇到的问题===<br />
<br />
如果你在安装Arch或者rEFIt后遇到了问题,特别是启动时在启动菜单中看不到启动项,或者出现下面的GRUB提示时:<br />
<pre><br />
GRUB>_<br />
</pre><br />
<br />
请您参考下 http://mac.linux.be/content/problems-refit-and-grub-after-installation<br />
<br />
该页面将会教你如何启动的Arch系统,将有问题的Arch系统挂载上去,然后chroot进入该系统,通过gptsyc重新安装GRUB。文中提到的那些用于debian系统的命令基本上都可以在Arch上工作。不过注意不要将GRUB安装错地方了(wrong spot怎么翻译?)<br />
<br />
你可从 http://packages.debian.org/sid/gptsync 获取到gptsync。<br />
或者通过下面两个命令之一分别下载32/64位版本的:<br />
<pre><br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_i386.deb<br />
wget http://ftp.us.debian.org/debian/pool/main/r/refit/gptsync_0.14-2_amd64.deb<br />
</pre><br />
<br />
由于是.deb包,所以你可能需要先安装deb2targz<br />
<br />
pacman -S deb2targz<br />
<br />
== 参考资料 ==<br />
<br />
* http://www.netsoc.tcd.ie/~theorie/interblag/2010/01/30/installing-arch-linux-on-a-mac-pro/<br />
* http://allanmcrae.com/2010/04/installing-arch-on-a-macbook-pro-5-5/<br />
* http://linux-junky.blogspot.com/2011/08/triple-boot-archlinux-windows-7-and-mac.html<br />
<br />
== MacBook Air (4,2) 内核补丁 ==<br />
<br />
Linus的内核树中的当前版本(Linux 3.0.7)中,包含几个问题。我(telmich)已经搜集了下面几个问题的修复补丁:<br />
<br />
* 分辨率是1280x800而非正确的1440x900<br />
* 触摸板不能正常工作或被检测为Synaptics<br />
* FN + F1~F12组合键不工作(例如:fn啥都干不了)<br />
* FN+F5~F12等多媒体键映射错误<br />
* 网络处理的驱动/brcmsmac驱动(Hanging network applications / brcmsmac driver)<br />
<br />
您可以从 http://git.schottelius.org/?p=foreign/linux-macbook-air;a=summary 获取到打好补丁的内核,其中包括如下分支:<br />
<br />
# keith-jiri: Keith Packard提供的显卡驱动补丁、Jiri Kosina提供的FN功能键补丁<br />
# keith-jiri-brcmsmac: 上面提到的补丁加上网络处理的驱动<br />
# jiri-kbdmapping: FN功能键和映射关系修复补丁<br />
# keith-jiri-kbdmapping: 第一个分支加上多媒体键补丁<br />
# keith-jiri-kbdmapping-brcmsmac: 以上所有的集合 ('''不确定的情况下,推荐使用这个分支''')<br />
<br />
你可以很简单的用当前ArchLinux的配置文件来编译内核:<br />
<br />
<pre><br />
# 请先通过git检出对应分支的源代码!<br />
cd linux-macbook-air<br />
<br />
# 使用当前的配置作为基础<br />
zcat /proc/config.gz > .config<br />
<br />
# 编译内核时,可能会询问几个未配置的选项<br />
make -j5<br />
</pre></div>Athurghttps://wiki.archlinux.org/index.php?title=Mac_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=170368Mac (简体中文)2011-11-17T13:03:28Z<p>Athurg: /* rEFIt */</p>
<hr />
<div>[[Category:Apple (简体中文)]]<br />
{{i18n|MacBook}}<br />
{{Article summary start|摘要}}<br />
{{Article summary text|一份详尽的在MacBook上安装Arch Linux指南教程(第一次在Arch Wiki上翻译,不当之处还请指正)}}<br />
{{Article summary heading|相关文章}}<br />
{{Article summary wiki|Official Arch Linux Install Guide}}<br />
{{Article summary wiki|Beginners Guide}}<br />
{{Article summary wiki|General Recommendations}}<br />
{{Article summary end}}<br />
<br />
在MacBook上安装Arch Linux与在其他电脑上安装Arch Linux非常相似。然而,由于MacBook的特殊硬件配置,需要一些特殊的考虑,因此建立MacBook专页。更多背景信息,可以从[https://wiki.archlinux.org/index.php/Official_Arch_Linux_Install_Guide 官方安装指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide 新手指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide_Appendix 新手指南扩展]以及[https://wiki.archlinux.org/index.php/Post_Installation_Tips 安装后小贴士]上获取。本文同样适用于MacBook Pro系列机型,也支持32位及64位版本。如果您正在使用MacBook 5,2并且有其他疑问,请猛击[https://wiki.archlinux.org/index.php/Macbook5,2 MacBook5,2]获取帮助。<br />
<br />
==概述==<br />
<br />
在MacBook上安装Arch Linux可以分为一下几个步骤<br />
#'''[[#安装 Mac OS X 以及固件更新|安装Mac OS X]]''':忽略安装过程最后的配置,此处将从一个新安装的OS X开始。<br />
#'''[[#安装 Mac OS X 以及固件更新|固件更新]]''':这将有助于减少错误以及提供硬件的新特性。<br />
#'''[[#分区|分区]]''':这步中可以调整OS X分区大小货删除分区并为Arch Linux建立分区。<br />
#'''[[#安装|安装Arch Linux]]''':真正安装Arch Linux的过程。<br />
#'''[[#安装后配置|安装后配置]]''':针对MacBook的特殊配置。<br />
<br />
{{Tip|rEFIt是EFI固件电脑上很流行的一个启动器,包括了Mac电脑。它能够在系统安装过程中的任何时候安装,更多信息请猛击[[MacBook#rEFIt|rEFIt]]}}<br />
<br />
==安装 Mac OS X 以及固件更新==<br />
[http://www.apple.com/ Apple]已经提供了详尽的安装Mac OS X的教程。按照此教程安装好OS X后,点击菜单:<br />
<br />
苹果图标 --> 软件升级<br />
<br />
来更新所有软件。更新完成之后,您需要重启电脑。重启后请再次检查软件升级以确保所有软件都更新到了最新版。<br />
<br />
{{Note|有时软件更新不会对您电脑的所有固件惊醒更新,然而,您可以在苹果支持网站中自己搜索这些升级。}}<br />
<br />
如果您不打算安装Mac OS X,请为这些文件做好备份:<br />
<br />
/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport<br />
<br />
这个文件将在后期调试iSight时用到。同样的,请备份色彩配置<br />
<br />
/Library/ColorSync/Profiles/Displays/<此处的文件><br />
<br />
在调试[[#色彩配置 | 色彩配置]]时会用到。<br />
<br />
==分区==<br />
<br />
下一步就是将硬盘重新分区。如果Mac OS X按照一般流程安装,那么您的硬盘将是GPT格式分区表,会有以下两个分区:<br />
<br />
*'''EFI分区''':一个大小有200MB的分区,在磁盘开始部分。有些分区工具会将其读作FAT分区,通常标为''#1''<br />
*'''Mac OS X分区''':这个分区''(HFS+)''一般是占用了硬盘的所有其他空间。通常标为''#2''<br />
<br />
分区策略依据您想安装多少操作系统而定,有如下两个选项:<br />
<br />
*[[仅安装Arch Linux|仅安装Arch Linux]]单系统。<br />
*[[Mac OS X与Arch Linux共存|Mac OS X与Arch Linux共存]]双系统。<br />
<br />
如果您不知道改选哪种方式,我们建议您选择双系统,这样您可以在任何时候回到Mac OS X。<br />
<br />
===仅安装Arch Linux===<br />
<br />
这种情况最好办。大多数情况下,分区操作与将Arch Linux安装在其他硬件上没两样。 唯一的不同点在于MacBook的启动响铃。为了确保启动响铃是关闭的,请提前在Mac OS X系统中就将音量调至静音。MacBook固件依赖于Mac OS X的配置。请注意,如果你选择去掉Mac OS X的分区,除了用另外一块硬盘来加载OS X进行设置固件外没有其他任何办法。<br />
<br />
这之后可以使用parted来进行分区操作。最简单的办法是将分区表转为msdos格式,然后和平常一样来进行分区。GRUB不能认出GPT格式的分区表。<br />
<br />
{{Note|用parted对硬盘分区只需要用从Arch Linux core install disk启动,然后以root权限打开parted程序。此操作可在安装前完成。}}<br />
<br />
完成这一步骤之后,可以查看[[#安装|安装]]部分。<br />
<br />
===Mac OS X与Arch Linux共存===<br />
<br />
让Mac OS X与Arch Linux共存的最简单的分区方法是用Mac OS X的分区工具后用Arch Linux的工具完善。<br />
<br />
{{Warning|这种方法最好只在新安装的OS X中尝试,在一个预安装的OS X中可能发生不可预料的结果。}}<br />
<br />
过程:<br />
<br />
*在Mac OS X中,运行磁盘工具<br />
<br />
*在左侧栏,选择硬盘,请注意,是选择硬盘,而不是分区。点击右侧的分区标签。<br />
<br />
*选择要重置大小的分区。<br />
<br />
*确定你要给你的Mac OS X分区留多少空间,以及留多少空间给Arch Linux。记住一个Mac OS X大约需要15至20GB的空间,请留足空间以方便日后安装软件。<br />
<br />
*最后,设置Mac OS X分区的大小,然后在空白区域创建一个分区。<br />
<br />
{{Note|如果你希望在Mac OS X与Arch Linux之间共享一个分区,那么需要做些额外的操作,具体操作可以参照此处[[#HFS分区共享|分区共享]]}}<br />
<br />
*上述操作顺利完成后就可以进入下一步了,否则,请一定在Mac OS X上解决这些问题。<br />
<br />
*按住ALT键来从Arch Linux启动光盘启动。<br />
<br />
*现在,运行parted来完成后续操作。<br />
<br />
# parted<br />
<br />
*删除空分区。你可以随意按照你的想法设置这个分区。请注意MBR是必须装在4个主分区上的,包括了EFI预留分区。也就是留下了2个主分区给Arch Linux。一种分区策略是分配一个根分区和一个Home分区,然后swap可以使用文件。要不然就是分配一个分区用于共享。下面会有详细说明。<br />
<br />
*此时,如果你需要多系统启动,你需要重启电脑,用rEFIt来修复磁盘上的分区表。如果你这样干,那您会需要重装GRUB来是Mac系统认出Linux分区。当你进入rEFIt菜单后,选择更新分区表,然后按Y<br />
<br />
# reboot<br />
<br />
*完成了,可以继续安装过程了。<br />
<br />
==从GRUB直接启动==<br />
<br />
在efi上直接启动GRUB2而不用rEFIt是可以的。一下的操作在MacBook7,1上是可行的。建议将GRUB安装在fat32或者HFS+分区上,ext2或者ext3应该也行。GRUB的苹果加载命令在7,1上还暂时不能使用,但可以用过下面的补丁实现[https://savannah.gnu.org/bugs/index.php?33185 补丁地址]。<br />
<br />
GRUB装上硬盘分区后,固件需要知道从哪儿启动它。这步操作可以在OS X或者OS X安装光盘。下面的命令指明了GRUB是安装在OS X系统的/efi/grub中<br />
<br />
sudo bless --folder /efi/grub --file /efi/grub/grub.efi<br />
<br />
===编译===<br />
<br />
有些型号可能需要将EFI_ARCH设置成i386。<br />
<br />
bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub<br />
cd grub<br />
./autogen.sh<br />
patch -p1 < appleloader_macbook_7_1.patch<br />
export EFI_ARCH=x86_64<br />
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""<br />
make<br />
cd grub-core<br />
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot<br />
cp grub.efi *.mod *.lst yourinstalllocation<br />
<br />
===grub.cfg示例===<br />
<br />
此处应该有更好的方法来加载Windows系统。<br />
<br />
<pre><br />
set debug=video<br />
insmod efi_gop<br />
<br />
menuentry "Arch Linux EFI" {<br />
set root=(hd0,3)<br />
#search --set -f /boot/vmlinuz26-efi-physical<br />
#loadbios /boot/vbtrace_bios.bin /boot/int10.bin<br />
linux /boot/vmlinuz26-efi-physical root=/dev/sda3 reboot=pci resume=/dev/sda3 resume_offset=151552<br />
initrd /boot/kernel26-efi-physical.img<br />
}<br />
<br />
menuentry "MacOSX" {<br />
set root=(hd0,2)<br />
# Search the root device for Mac OS X's loader.<br />
#search --set -f /usr/standalone/i386/boot.efi<br />
# Load the loader.<br />
chainloader /usr/standalone/i386/boot.efi<br />
}<br />
<br />
menuentry "Windows 7" {<br />
appleloader HD<br />
}<br />
<br />
menuentry "Boot from CD" {<br />
appleloader CD<br />
}<br />
<br />
menuentry "Boot from USB" {<br />
appleloader USB<br />
}<br />
</pre><br />
<br />
==安装==<br />
<br />
{{Note|本部分安装过程只是用于Mac OS X与Arch Linux共存的情况,如果你只想单独使用Arch Linux,可以按照官方安装指南,然后跳到[[#安装后配置|安装后配置]]}}<br />
<br />
*从Arch Linux安装光盘启动<br />
<br />
{{Note|有些MacBook用户反映键盘不能正确响应,那就按照下面的参数来启动光盘。}}<br />
<br />
{{Note|截止2011年4月30日,MacBook7,1不能从普通的iso镜像启动,但最新的[https://wiki.archlinux.org/index.php/Archboot archboot]应该有用。}}<br />
<br />
boot: arch noapic irqpoll acpi=force<br />
<br />
*以root登陆<br />
<br />
*打开Arch Linux安装程序<br />
<br />
/arch/setup<br />
<br />
*按照[[官方安装文档]]中说明的过程来做,但是在下面几个部分中请留意:<br />
**在[[Official Arch Linux Install Guide#Prepare Hard Drive | 准备磁盘]]部分,只要做设置磁盘挂在这步,注意要设对磁盘挂载点。<br />
**在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,编辑menu.lst文件,添加'''reboot=pci'''到'''kernel'''行的末尾,例如下面这行:<pre style="margin: .5em 0; padding: .5em 1em">kernel /vmlinuz26 root=/dev/sda5 ro reboot=pci</pre>这样你的MacBook才能从Arch Linux正常重启<br />
**还是在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,将GRUB安装至{{Codeline|/boot}}所在的分区。{{Warning|别把GRUB安装到''/dev/sda''这样的地方!!!这样做会造成系统不稳定。}}<br />
**在[[Official Arch Linux Install Guide#Configure System | 配置系统]]部分,编辑 /etc/mkinitcpio.conf,添加'''usbinput'''到'''HOOKS'''行的'''autodetect'''之后。这样才能在Arch Linux启动之前加载键盘驱动<br />
<br />
*安装完成之后就可以重启系统了。<br />
<br />
# reboot<br />
<br />
*把Arch Linux安装光盘从光驱中退出。<br />
<br />
==安装后配置==<br />
<br />
===Xorg===<br />
<br />
按照[[Xorg]]来安装Xorg。<br />
<br />
====视频====<br />
<br />
不同的MacBook有不同型号的显卡,可以通过下面命令来查看显卡种类<br />
<br />
$ lspci | grep VGA<br />
<br />
*如果返回的字符串中包含'''intel''',那你只需要安装'''xf86-video-intel'''驱动,用如下命令:<br />
<br />
# pacman -S xf86-video-intel<br />
<br />
*如果返回的是nVidia,可以参看[[NVIDIA]]<br />
<br />
*如果返回ATI或者AMD,参见[[ATI]]<br />
<br />
=====NVIDIA注意=====<br />
<br />
{{ Tip|MacBookPro 6,2 - 使用合适的[[NVIDIA]]驱动,在使用[https://wiki.archlinux.org/index.php/NVIDIA#Enabling_Pure_Video_HD_.28VDPAU.2FVAAPI.29 Pure Video HD]之后支持硬件视频解码。}}<br />
<br />
对于使用NVIDIA显卡的MacBook,背景亮度可以通过[[AUR]]中的[http://aur.archlinux.org/packages.php?ID=25467 nvidia-bl]包解决。<br />
<br />
=====MacBook 6,2+-EFI=====<br />
<br />
截至2011年4月30日,nvidia驱动在此类EFI型号的机子下不能正常工作。可以了解一下[http://aur.archlinux.org/packages/mesa-git/PKGBUILD mesa-git]这个包。<br />
<br />
====触摸板====<br />
<br />
触摸板应该已经有了基本的功能。可以安装AUR中的[http://aur.archlinux.org/packages.php?ID=46339 xf86-input-multitouch-git]包来达到和Mac OS X类似的多点触控效果,最多支持三点触控,包含了三指水平与垂直滑动。可以从[http://bitmath.org/code/multitouch/ 项目主页]<br />
获取更多消息。<br />
<br />
xf86-input-multitouch-git除了编辑源代码外不支持配置。一些用户也正面临这从palm上得到错误的点击。现在有个可定制度更高的包[http://aur.archlinux.org/packages.php?ID=48505 xf86-input-mtrack-git]。在其[https://github.com/BlueDragonX/xf86-input-mtrack readme]中能得到更多配置信息。<br />
<br />
下面的配置在MacBook 7,1中正常工作<br />
<br />
Option "Thumbsize" "50"<br />
Option "ScrollDistance" "100"<br />
<br />
可能你还需要添加下面的内容<br />
<br />
MatchDevicePath "/dev/input/event10"<br />
<br />
在更旧的MacBook机型上,比如MacBook 2,1中,可能需要安装xf86-input-synaptics包才能正常工作。可以查看[[Touchpad Synaptics]]获取更多信息。<br />
<br />
====键盘====<br />
<br />
MacBook的键盘默认是能正常工作的。如果想切换fn键,可以查看[[Apple Keyboard]]。<br />
<br />
可以通过'''xbindkeys'''来重新设置键,或者通过DE配置。有另一种很好的方法,安装[http://aur.archlinux.org/packages.php?ID=14833 pommed]<br />
<br />
根据你MacBook的硬件来配置'''/etc/pommed.conf''',可以以'''/etc/pommed.conf.mac'''或者'''/etc/pommed.conf.ppc'''为模板来建立这个配置。<br />
<br />
=====NVIDIA配置=====<br />
===无线配置===<br />
===电源管理===<br />
====笔记本模式工具====<br />
====睡眠(内核挂起)====<br />
====休眠====<br />
===声音配置===<br />
===蓝牙===<br />
===iSight配置===<br />
===温度感应===<br />
===色彩配置===<br />
===苹果远程控制===<br />
===HFS分区共享===<br />
===HFS+ 分区===<br />
===Home目录共享===<br />
====在OS X中====<br />
=====第一步:改变UID与GID=====<br />
=====第二步:改变Home目录权限=====<br />
====在Arch中====<br />
===避免GRUB启动前EFI长时间执行===<br />
===关闭启动响铃===<br />
==rEFIt==<br />
<br />
{{Note | rEFIt只是在开机是给你提供OS X和Linux的启动菜单而已。如果没有这个需求的话,rEFIt不是必须的。}}<br />
<br />
详情参考[http://refit.sourceforge.net/myths/ refit myths].<br />
<br />
在OS X下,从[http://refit.sourceforge.net/ Refit主页]下载".dmg"格式的安装包,并像其他苹果软件一样安装。<br />
<br />
{{Note | 如果你此前已经对磁盘分过区的话(比如准备安装ArchLinux之前的准备),那rEFIt默认是不启用的。你需要手动执行安装到系统路径/efi/refit/的"enable.sh"脚本}}<br />
<br />
手动启用rEFIt的方法:<br />
* 打开'''终端''':<br />
* 执行'''cd /efi/refit; ./enable.sh'''命令<br />
<br />
<br />
<br />
===rEFIt问题===<br />
<br />
== 参考资料 ==<br />
<br />
* http://www.netsoc.tcd.ie/~theorie/interblag/2010/01/30/installing-arch-linux-on-a-mac-pro/<br />
* http://allanmcrae.com/2010/04/installing-arch-on-a-macbook-pro-5-5/<br />
* http://linux-junky.blogspot.com/2011/08/triple-boot-archlinux-windows-7-and-mac.html<br />
<br />
== MacBook Air (4,2) 内核补丁 ==<br />
<br />
Linus的内核树中的当前版本(Linux 3.0.7)中,包含几个问题。我(telmich)已经搜集了下面几个问题的修复补丁:<br />
<br />
* 分辨率是1280x800而非正确的1440x900<br />
* 触摸板不能正常工作或被检测为Synaptics<br />
* FN + F1~F12组合键不工作(例如:fn啥都干不了)<br />
* FN+F5~F12等多媒体键映射错误<br />
* 网络处理的驱动/brcmsmac驱动(Hanging network applications / brcmsmac driver)<br />
<br />
您可以从 http://git.schottelius.org/?p=foreign/linux-macbook-air;a=summary 获取到打好补丁的内核,其中包括如下分支:<br />
<br />
# keith-jiri: Keith Packard提供的显卡驱动补丁、Jiri Kosina提供的FN功能键补丁<br />
# keith-jiri-brcmsmac: 上面提到的补丁加上网络处理的驱动<br />
# jiri-kbdmapping: FN功能键和映射关系修复补丁<br />
# keith-jiri-kbdmapping: 第一个分支加上多媒体键补丁<br />
# keith-jiri-kbdmapping-brcmsmac: 以上所有的集合 ('''不确定的情况下,推荐使用这个分支''')<br />
<br />
你可以很简单的用当前ArchLinux的配置文件来编译内核:<br />
<br />
<pre><br />
# 请先通过git检出对应分支的源代码!<br />
cd linux-macbook-air<br />
<br />
# 使用当前的配置作为基础<br />
zcat /proc/config.gz > .config<br />
<br />
# 编译内核时,可能会询问几个未配置的选项<br />
make -j5<br />
</pre></div>Athurghttps://wiki.archlinux.org/index.php?title=Mac_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=170367Mac (简体中文)2011-11-17T12:54:37Z<p>Athurg: /* 相关信息 */</p>
<hr />
<div>[[Category:Apple (简体中文)]]<br />
{{i18n|MacBook}}<br />
{{Article summary start|摘要}}<br />
{{Article summary text|一份详尽的在MacBook上安装Arch Linux指南教程(第一次在Arch Wiki上翻译,不当之处还请指正)}}<br />
{{Article summary heading|相关文章}}<br />
{{Article summary wiki|Official Arch Linux Install Guide}}<br />
{{Article summary wiki|Beginners Guide}}<br />
{{Article summary wiki|General Recommendations}}<br />
{{Article summary end}}<br />
<br />
在MacBook上安装Arch Linux与在其他电脑上安装Arch Linux非常相似。然而,由于MacBook的特殊硬件配置,需要一些特殊的考虑,因此建立MacBook专页。更多背景信息,可以从[https://wiki.archlinux.org/index.php/Official_Arch_Linux_Install_Guide 官方安装指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide 新手指南]、[https://wiki.archlinux.org/index.php/Beginners_Guide_Appendix 新手指南扩展]以及[https://wiki.archlinux.org/index.php/Post_Installation_Tips 安装后小贴士]上获取。本文同样适用于MacBook Pro系列机型,也支持32位及64位版本。如果您正在使用MacBook 5,2并且有其他疑问,请猛击[https://wiki.archlinux.org/index.php/Macbook5,2 MacBook5,2]获取帮助。<br />
<br />
==概述==<br />
<br />
在MacBook上安装Arch Linux可以分为一下几个步骤<br />
#'''[[#安装 Mac OS X 以及固件更新|安装Mac OS X]]''':忽略安装过程最后的配置,此处将从一个新安装的OS X开始。<br />
#'''[[#安装 Mac OS X 以及固件更新|固件更新]]''':这将有助于减少错误以及提供硬件的新特性。<br />
#'''[[#分区|分区]]''':这步中可以调整OS X分区大小货删除分区并为Arch Linux建立分区。<br />
#'''[[#安装|安装Arch Linux]]''':真正安装Arch Linux的过程。<br />
#'''[[#安装后配置|安装后配置]]''':针对MacBook的特殊配置。<br />
<br />
{{Tip|rEFIt是EFI固件电脑上很流行的一个启动器,包括了Mac电脑。它能够在系统安装过程中的任何时候安装,更多信息请猛击[[MacBook#rEFIt|rEFIt]]}}<br />
<br />
==安装 Mac OS X 以及固件更新==<br />
[http://www.apple.com/ Apple]已经提供了详尽的安装Mac OS X的教程。按照此教程安装好OS X后,点击菜单:<br />
<br />
苹果图标 --> 软件升级<br />
<br />
来更新所有软件。更新完成之后,您需要重启电脑。重启后请再次检查软件升级以确保所有软件都更新到了最新版。<br />
<br />
{{Note|有时软件更新不会对您电脑的所有固件惊醒更新,然而,您可以在苹果支持网站中自己搜索这些升级。}}<br />
<br />
如果您不打算安装Mac OS X,请为这些文件做好备份:<br />
<br />
/System/Library/Extensions/IOUSBFamily.kext/Contents/PlugIns/AppleUSBVideoSupport.kext/Contents/MacOS/AppleUSBVideoSupport<br />
<br />
这个文件将在后期调试iSight时用到。同样的,请备份色彩配置<br />
<br />
/Library/ColorSync/Profiles/Displays/<此处的文件><br />
<br />
在调试[[#色彩配置 | 色彩配置]]时会用到。<br />
<br />
==分区==<br />
<br />
下一步就是将硬盘重新分区。如果Mac OS X按照一般流程安装,那么您的硬盘将是GPT格式分区表,会有以下两个分区:<br />
<br />
*'''EFI分区''':一个大小有200MB的分区,在磁盘开始部分。有些分区工具会将其读作FAT分区,通常标为''#1''<br />
*'''Mac OS X分区''':这个分区''(HFS+)''一般是占用了硬盘的所有其他空间。通常标为''#2''<br />
<br />
分区策略依据您想安装多少操作系统而定,有如下两个选项:<br />
<br />
*[[仅安装Arch Linux|仅安装Arch Linux]]单系统。<br />
*[[Mac OS X与Arch Linux共存|Mac OS X与Arch Linux共存]]双系统。<br />
<br />
如果您不知道改选哪种方式,我们建议您选择双系统,这样您可以在任何时候回到Mac OS X。<br />
<br />
===仅安装Arch Linux===<br />
<br />
这种情况最好办。大多数情况下,分区操作与将Arch Linux安装在其他硬件上没两样。 唯一的不同点在于MacBook的启动响铃。为了确保启动响铃是关闭的,请提前在Mac OS X系统中就将音量调至静音。MacBook固件依赖于Mac OS X的配置。请注意,如果你选择去掉Mac OS X的分区,除了用另外一块硬盘来加载OS X进行设置固件外没有其他任何办法。<br />
<br />
这之后可以使用parted来进行分区操作。最简单的办法是将分区表转为msdos格式,然后和平常一样来进行分区。GRUB不能认出GPT格式的分区表。<br />
<br />
{{Note|用parted对硬盘分区只需要用从Arch Linux core install disk启动,然后以root权限打开parted程序。此操作可在安装前完成。}}<br />
<br />
完成这一步骤之后,可以查看[[#安装|安装]]部分。<br />
<br />
===Mac OS X与Arch Linux共存===<br />
<br />
让Mac OS X与Arch Linux共存的最简单的分区方法是用Mac OS X的分区工具后用Arch Linux的工具完善。<br />
<br />
{{Warning|这种方法最好只在新安装的OS X中尝试,在一个预安装的OS X中可能发生不可预料的结果。}}<br />
<br />
过程:<br />
<br />
*在Mac OS X中,运行磁盘工具<br />
<br />
*在左侧栏,选择硬盘,请注意,是选择硬盘,而不是分区。点击右侧的分区标签。<br />
<br />
*选择要重置大小的分区。<br />
<br />
*确定你要给你的Mac OS X分区留多少空间,以及留多少空间给Arch Linux。记住一个Mac OS X大约需要15至20GB的空间,请留足空间以方便日后安装软件。<br />
<br />
*最后,设置Mac OS X分区的大小,然后在空白区域创建一个分区。<br />
<br />
{{Note|如果你希望在Mac OS X与Arch Linux之间共享一个分区,那么需要做些额外的操作,具体操作可以参照此处[[#HFS分区共享|分区共享]]}}<br />
<br />
*上述操作顺利完成后就可以进入下一步了,否则,请一定在Mac OS X上解决这些问题。<br />
<br />
*按住ALT键来从Arch Linux启动光盘启动。<br />
<br />
*现在,运行parted来完成后续操作。<br />
<br />
# parted<br />
<br />
*删除空分区。你可以随意按照你的想法设置这个分区。请注意MBR是必须装在4个主分区上的,包括了EFI预留分区。也就是留下了2个主分区给Arch Linux。一种分区策略是分配一个根分区和一个Home分区,然后swap可以使用文件。要不然就是分配一个分区用于共享。下面会有详细说明。<br />
<br />
*此时,如果你需要多系统启动,你需要重启电脑,用rEFIt来修复磁盘上的分区表。如果你这样干,那您会需要重装GRUB来是Mac系统认出Linux分区。当你进入rEFIt菜单后,选择更新分区表,然后按Y<br />
<br />
# reboot<br />
<br />
*完成了,可以继续安装过程了。<br />
<br />
==从GRUB直接启动==<br />
<br />
在efi上直接启动GRUB2而不用rEFIt是可以的。一下的操作在MacBook7,1上是可行的。建议将GRUB安装在fat32或者HFS+分区上,ext2或者ext3应该也行。GRUB的苹果加载命令在7,1上还暂时不能使用,但可以用过下面的补丁实现[https://savannah.gnu.org/bugs/index.php?33185 补丁地址]。<br />
<br />
GRUB装上硬盘分区后,固件需要知道从哪儿启动它。这步操作可以在OS X或者OS X安装光盘。下面的命令指明了GRUB是安装在OS X系统的/efi/grub中<br />
<br />
sudo bless --folder /efi/grub --file /efi/grub/grub.efi<br />
<br />
===编译===<br />
<br />
有些型号可能需要将EFI_ARCH设置成i386。<br />
<br />
bzr branch --revision -2 bzr://bzr.savannah.gnu.org/grub/trunk/grub grub<br />
cd grub<br />
./autogen.sh<br />
patch -p1 < appleloader_macbook_7_1.patch<br />
export EFI_ARCH=x86_64<br />
./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix=""<br />
make<br />
cd grub-core<br />
../grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot<br />
cp grub.efi *.mod *.lst yourinstalllocation<br />
<br />
===grub.cfg示例===<br />
<br />
此处应该有更好的方法来加载Windows系统。<br />
<br />
<pre><br />
set debug=video<br />
insmod efi_gop<br />
<br />
menuentry "Arch Linux EFI" {<br />
set root=(hd0,3)<br />
#search --set -f /boot/vmlinuz26-efi-physical<br />
#loadbios /boot/vbtrace_bios.bin /boot/int10.bin<br />
linux /boot/vmlinuz26-efi-physical root=/dev/sda3 reboot=pci resume=/dev/sda3 resume_offset=151552<br />
initrd /boot/kernel26-efi-physical.img<br />
}<br />
<br />
menuentry "MacOSX" {<br />
set root=(hd0,2)<br />
# Search the root device for Mac OS X's loader.<br />
#search --set -f /usr/standalone/i386/boot.efi<br />
# Load the loader.<br />
chainloader /usr/standalone/i386/boot.efi<br />
}<br />
<br />
menuentry "Windows 7" {<br />
appleloader HD<br />
}<br />
<br />
menuentry "Boot from CD" {<br />
appleloader CD<br />
}<br />
<br />
menuentry "Boot from USB" {<br />
appleloader USB<br />
}<br />
</pre><br />
<br />
==安装==<br />
<br />
{{Note|本部分安装过程只是用于Mac OS X与Arch Linux共存的情况,如果你只想单独使用Arch Linux,可以按照官方安装指南,然后跳到[[#安装后配置|安装后配置]]}}<br />
<br />
*从Arch Linux安装光盘启动<br />
<br />
{{Note|有些MacBook用户反映键盘不能正确响应,那就按照下面的参数来启动光盘。}}<br />
<br />
{{Note|截止2011年4月30日,MacBook7,1不能从普通的iso镜像启动,但最新的[https://wiki.archlinux.org/index.php/Archboot archboot]应该有用。}}<br />
<br />
boot: arch noapic irqpoll acpi=force<br />
<br />
*以root登陆<br />
<br />
*打开Arch Linux安装程序<br />
<br />
/arch/setup<br />
<br />
*按照[[官方安装文档]]中说明的过程来做,但是在下面几个部分中请留意:<br />
**在[[Official Arch Linux Install Guide#Prepare Hard Drive | 准备磁盘]]部分,只要做设置磁盘挂在这步,注意要设对磁盘挂载点。<br />
**在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,编辑menu.lst文件,添加'''reboot=pci'''到'''kernel'''行的末尾,例如下面这行:<pre style="margin: .5em 0; padding: .5em 1em">kernel /vmlinuz26 root=/dev/sda5 ro reboot=pci</pre>这样你的MacBook才能从Arch Linux正常重启<br />
**还是在[[Official Arch Linux Install Guide#Install Bootloader | 安装启动器]]部分,将GRUB安装至{{Codeline|/boot}}所在的分区。{{Warning|别把GRUB安装到''/dev/sda''这样的地方!!!这样做会造成系统不稳定。}}<br />
**在[[Official Arch Linux Install Guide#Configure System | 配置系统]]部分,编辑 /etc/mkinitcpio.conf,添加'''usbinput'''到'''HOOKS'''行的'''autodetect'''之后。这样才能在Arch Linux启动之前加载键盘驱动<br />
<br />
*安装完成之后就可以重启系统了。<br />
<br />
# reboot<br />
<br />
*把Arch Linux安装光盘从光驱中退出。<br />
<br />
==安装后配置==<br />
<br />
===Xorg===<br />
<br />
按照[[Xorg]]来安装Xorg。<br />
<br />
====视频====<br />
<br />
不同的MacBook有不同型号的显卡,可以通过下面命令来查看显卡种类<br />
<br />
$ lspci | grep VGA<br />
<br />
*如果返回的字符串中包含'''intel''',那你只需要安装'''xf86-video-intel'''驱动,用如下命令:<br />
<br />
# pacman -S xf86-video-intel<br />
<br />
*如果返回的是nVidia,可以参看[[NVIDIA]]<br />
<br />
*如果返回ATI或者AMD,参见[[ATI]]<br />
<br />
=====NVIDIA注意=====<br />
<br />
{{ Tip|MacBookPro 6,2 - 使用合适的[[NVIDIA]]驱动,在使用[https://wiki.archlinux.org/index.php/NVIDIA#Enabling_Pure_Video_HD_.28VDPAU.2FVAAPI.29 Pure Video HD]之后支持硬件视频解码。}}<br />
<br />
对于使用NVIDIA显卡的MacBook,背景亮度可以通过[[AUR]]中的[http://aur.archlinux.org/packages.php?ID=25467 nvidia-bl]包解决。<br />
<br />
=====MacBook 6,2+-EFI=====<br />
<br />
截至2011年4月30日,nvidia驱动在此类EFI型号的机子下不能正常工作。可以了解一下[http://aur.archlinux.org/packages/mesa-git/PKGBUILD mesa-git]这个包。<br />
<br />
====触摸板====<br />
<br />
触摸板应该已经有了基本的功能。可以安装AUR中的[http://aur.archlinux.org/packages.php?ID=46339 xf86-input-multitouch-git]包来达到和Mac OS X类似的多点触控效果,最多支持三点触控,包含了三指水平与垂直滑动。可以从[http://bitmath.org/code/multitouch/ 项目主页]<br />
获取更多消息。<br />
<br />
xf86-input-multitouch-git除了编辑源代码外不支持配置。一些用户也正面临这从palm上得到错误的点击。现在有个可定制度更高的包[http://aur.archlinux.org/packages.php?ID=48505 xf86-input-mtrack-git]。在其[https://github.com/BlueDragonX/xf86-input-mtrack readme]中能得到更多配置信息。<br />
<br />
下面的配置在MacBook 7,1中正常工作<br />
<br />
Option "Thumbsize" "50"<br />
Option "ScrollDistance" "100"<br />
<br />
可能你还需要添加下面的内容<br />
<br />
MatchDevicePath "/dev/input/event10"<br />
<br />
在更旧的MacBook机型上,比如MacBook 2,1中,可能需要安装xf86-input-synaptics包才能正常工作。可以查看[[Touchpad Synaptics]]获取更多信息。<br />
<br />
====键盘====<br />
<br />
MacBook的键盘默认是能正常工作的。如果想切换fn键,可以查看[[Apple Keyboard]]。<br />
<br />
可以通过'''xbindkeys'''来重新设置键,或者通过DE配置。有另一种很好的方法,安装[http://aur.archlinux.org/packages.php?ID=14833 pommed]<br />
<br />
根据你MacBook的硬件来配置'''/etc/pommed.conf''',可以以'''/etc/pommed.conf.mac'''或者'''/etc/pommed.conf.ppc'''为模板来建立这个配置。<br />
<br />
=====NVIDIA配置=====<br />
===无线配置===<br />
===电源管理===<br />
====笔记本模式工具====<br />
====睡眠(内核挂起)====<br />
====休眠====<br />
===声音配置===<br />
===蓝牙===<br />
===iSight配置===<br />
===温度感应===<br />
===色彩配置===<br />
===苹果远程控制===<br />
===HFS分区共享===<br />
===HFS+ 分区===<br />
===Home目录共享===<br />
====在OS X中====<br />
=====第一步:改变UID与GID=====<br />
=====第二步:改变Home目录权限=====<br />
====在Arch中====<br />
===避免GRUB启动前EFI长时间执行===<br />
===关闭启动响铃===<br />
==rEFIt==<br />
===rEFIt问题===<br />
== 参考资料 ==<br />
<br />
* http://www.netsoc.tcd.ie/~theorie/interblag/2010/01/30/installing-arch-linux-on-a-mac-pro/<br />
* http://allanmcrae.com/2010/04/installing-arch-on-a-macbook-pro-5-5/<br />
* http://linux-junky.blogspot.com/2011/08/triple-boot-archlinux-windows-7-and-mac.html<br />
<br />
== MacBook Air (4,2) 内核补丁 ==<br />
<br />
Linus的内核树中的当前版本(Linux 3.0.7)中,包含几个问题。我(telmich)已经搜集了下面几个问题的修复补丁:<br />
<br />
* 分辨率是1280x800而非正确的1440x900<br />
* 触摸板不能正常工作或被检测为Synaptics<br />
* FN + F1~F12组合键不工作(例如:fn啥都干不了)<br />
* FN+F5~F12等多媒体键映射错误<br />
* 网络处理的驱动/brcmsmac驱动(Hanging network applications / brcmsmac driver)<br />
<br />
您可以从 http://git.schottelius.org/?p=foreign/linux-macbook-air;a=summary 获取到打好补丁的内核,其中包括如下分支:<br />
<br />
# keith-jiri: Keith Packard提供的显卡驱动补丁、Jiri Kosina提供的FN功能键补丁<br />
# keith-jiri-brcmsmac: 上面提到的补丁加上网络处理的驱动<br />
# jiri-kbdmapping: FN功能键和映射关系修复补丁<br />
# keith-jiri-kbdmapping: 第一个分支加上多媒体键补丁<br />
# keith-jiri-kbdmapping-brcmsmac: 以上所有的集合 ('''不确定的情况下,推荐使用这个分支''')<br />
<br />
你可以很简单的用当前ArchLinux的配置文件来编译内核:<br />
<br />
<pre><br />
# 请先通过git检出对应分支的源代码!<br />
cd linux-macbook-air<br />
<br />
# 使用当前的配置作为基础<br />
zcat /proc/config.gz > .config<br />
<br />
# 编译内核时,可能会询问几个未配置的选项<br />
make -j5<br />
</pre></div>Athurghttps://wiki.archlinux.org/index.php?title=VirtualBox_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=149865VirtualBox (简体中文)2011-07-24T15:15:27Z<p>Athurg: 增加“USB子系统无法访问”问题的解决方法</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[fr:VirtualBox]]<br />
{{i18n|VirtualBox}}<br />
<br />
这篇文章是关于在Arch上运行VirtualBox的,你可能会对[[Arch Linux VirtualBox Guest|Arch Linux VirtualBox客户端]]感兴趣。<br />
<br />
[http://www.virtualbox.org VirtualBox]是一个像[[vmware]]的虚拟PC模拟器。它有很多vmware的功能,当然也有自己特有的功能。它处于不断的开发中且总有新的功能引入。例如,2.2版本引入了对Linux和Solaris客户端的OpenGL 3D加速支持。它有一个漂亮的图形用户界面(Qt 和/或 SDL)或者用于关联虚拟机的命令行工具。它也支持Headless操作(一个软件在没有显示器的系统中运行)。在VirtualBox中运行iTunes是目前同步iPod Touch/iPhone固件3.0+的唯一方法。<br />
<br />
==安装==<br />
;{{package Official|virtualbox}}<br />
:这是基本GPL协议下的VirtualBox套件,可以在Community软件仓库中找到。<br />
<br />
;{{package AUR|virtualbox-ext-oracle}}<br />
:这个PUEL协议下的扩展包免费供个人用户使用。你可以从[[AUR]]中下载到,它以RPD服务、USB 2.0支持和对Intel cards的PXE引导为特色。<br />
<br />
安装基础软件包:<br />
# pacman -S virtualbox<br />
为了使用图形用户界面,可以选择安装{{package Official|qt}}:<br />
# pacman -S qt<br />
<br />
==运行 VirtualBox==<br />
现在,将需要运行Virtualbox的用户名添加到''vboxusers''用户组:<br />
# gpasswd -a USERNAME vboxusers<br />
<br />
创建必要的模块:<br />
# rc.d setup vboxdrv<br />
<br />
最后,为了在启动时载入VirtualBox驱动,需要编辑{{Filename!/etc/[[rc.conf]]}}并添加''vboxdrv''到MODULES序列中:<br />
MODULES=(... ''vboxdrv'')<br />
<br />
手动载入模块:<br />
# modprobe vboxdrv<br />
<br />
启动 Virtualbox:<br />
$ virtualbox<br />
<br />
===解决 /etc/rc.d/vboxdrv 无法启动===<br />
<br />
在某些情况下,当VirualBox全新安装时,你无法编译模块并出现一些错误信息,如:<br />
<br />
<pre><br />
# rc.d setup vboxdrv<br />
:: Unloading VirtualBox kernel modules [DONE]<br />
:: Recompiling VirtualBox kernel modules [BUSY]<br />
Look at /var/log/vbox-install.log to find out what went wrong<br />
Look at /var/log/vbox-install.log to find out what went wrong<br />
Look at /var/log/vbox-install.log to find out what went wrong<br />
[DONE]<br />
:: Reloading VirtualBox kernel modules}</pre><br />
<br />
并且唤起(evocated)日志文件写到:<br />
<pre>Makefile:169: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.<br />
cp: cannot stat `/tmp/vboxdrv-Module.symvers': No such file or directory<br />
Makefile:94: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.<br />
cp: cannot stat `/tmp/vboxdrv-Module.symvers': No such file or directory<br />
Makefile:90: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.</pre><br />
<br />
一种解决方法是,为你的内核安装头文件:<br />
<br />
pacman -S kernel26-headers<br />
或者,你已经有一个LTS版本:<br />
pacman -S kernel26-lts-headers<br />
<br />
重启计算机应该是有用的(也许不必要,可以尝试)并按照上述步骤实行,虚拟机应该可以运行了。<br />
<br />
==配置==<br />
===网络===<br />
VirtualBox 客户端可以通过不同的方式连接网络;其中,有[[#NAT]]和[[#桥接]]链接。[[#NAT]]是最简单的且作为一个新虚拟机的默认方式。<br />
<br />
[http://www.virtualbox.org/manual/UserManual.html VirtualBox手册]涵盖了主机模式和内网选项。这些都被忽略了,因为在大多数情况下与操作系统无关。<br />
====NAT====<br />
在VirtualBox中:<br />
* 访问虚拟机的''设置''菜单;<br />
* 点击左边的''网络‘’;最后,<br />
* 在“连接方式”的下拉列表中选择''NAT''。<br />
<br />
与VirtualBox捆绑的DHCP服务使得客户端系统能够与DHCP一起配置,第一张卡的NAT IP地址是 10.0.2.0,第二张是10.0.3.0,往后以此类推。<br />
<br />
====桥接====<br />
桥接网络可能被以多种方式启动;其中,有要求以较少控制为代价进行最小启动的原生方式。对于其他方式,参见[[Advanced VirtualBox Networking|高级VirtualBox网络连接]]。对于较新版本,VirtualBox可以在没有第三方工具的帮助下,在客户端和无线主机接口间进行桥接。<br />
<br />
在继续之前,加载必要模块:<br />
# modprobe vboxnetflt<br />
<br />
在VirtualBox中:<br />
* 访问虚拟机的''设置''菜单;<br />
* 点击左边列表中的''网络''<br />
* 在''链接方式''的下拉列表中选择''Bridged Adapter(桥接适配器)'';最后,<br />
* 在''界面名称''下拉列表中,选择客户端操作系统被包含在内,主机用于连接网络的接口。<br />
<br />
Start the virtual machine and configure its network as usual; e.g., DHCP or static.<br />
打开虚拟机,像往常一样配置其网络;例如 DHCP 或 static(静态网络)。<br />
<br />
===客户端增强包===<br />
客户端增强包(The Guest Additions)能够激活共享文件夹功能,改善显卡加速支持和在主机端及客户端之间启用双向剪贴板。鼠标集成是另一项功能,用于减少在客户端中使用鼠标后将其释放的需要。<br />
<br />
====Arch Linux 客户端====<br />
<br />
参阅[[Arch Linux VirtualBox Guest|Arch Linux VirtualBox客户端]]<br />
<br />
====Windows 客户端====<br />
在你的虚拟机中安装Windows(XP 等等)后,只需选择''设备 &rarr; 安装增强功能''<br />
<br />
这将会挂载ISO镜像,接着Windows应该自动运行客户端增强包安装向导(The guest additions installer)。按照说明进行到底。<br />
<br />
===主机端和客户端之间的键盘和鼠标===<br />
* 为了捕获键盘和鼠标,点击虚拟机内部。<br />
* 想要释放,按下右 {{keypress|Ctrl}}.<br />
<br />
想要获得在主机端和客户端之间的无缝鼠标集成功能,在客户端内安装[[#客户端增强包]]。<br />
<br />
用{{Codeline|X -configure}}生成客户端的{{Filename|xorg.con}}时, InputDevice区段可能会以{{Codeline|mouse}}驱动为特征。安装客户端增强包后,用{{Codeline|vboxmouse}}将{{Codeline|mouser}}替换掉,然后重启X服务或重启客户端。<br />
<br />
此外,将以下内容添加到客户端的{{Filename|xorg.conf}}:<br />
<pre><br />
Section "InputDevice"<br />
Identifier "Mouse0"<br />
Driver "vboxmouse"<br />
Option "Protocol" "auto"<br />
Option "Device" "/dev/input/mice"<br />
Option "ZAxisMapping" "4 5 6 7"<br />
EndSection<br />
<br />
Section "ServerLayout"<br />
Identifier "X.org Configured"<br />
Screen 0 "Screen0" 0 0<br />
InputDevice "Mouse0" "CorePointer"<br />
InputDevice "Keyboard0" "CoreKeyboard"<br />
EndSection<br />
</pre><br />
<br />
===在客户端中使用主机端系统的完全分辨率===<br />
在Grub启动脚本{{Filename|/boot/grub/menu.lst}}中设置客户端的分辨率。例如,添加正确的VGA代码到kernel命令行。对于1280*1024分辨率,应该为:<br />
# kernel /vmlinuz26 root=/dev/disk/by-uuid/7bdc5dee-8fb0-4260-bc43-60ac6e4e4a54 ro vga=795<br />
<br />
将分辨率添加到{{Filename|/etc/X11/xorg.conf}},如:<br />
<pre><br />
Section "Screen"<br />
...<br />
SubSection "Display"<br />
Viewport 0 0<br />
Depth 24<br />
Modes "1280x1024" "1024x768"<br />
EndSubSection<br />
...<br />
EndSection<br />
</pre><br />
如果你遇到这样一个问题,分辨率降到''Modes''设置中的第二个较低的分辨率,只需忽略第二个分辨率。例如:<br />
Modes "1280x1024"<br />
<br />
===主机端和客户端间的共享文件夹===<br />
在虚拟机的设置中,找到数据空间标签,然后加入你想要共享的文件夹。<br />
<br />
*注意:为了使用这个功能你需要安装客户端增强包。<br />
在Linux主机中,''设备 &rarr; 安装增强功能''<br />
确定(被要求下载CD镜像时)<br />
挂载(被要求注册和挂载时)<br />
<br />
In a Linux host, create one or more folders for sharing files, then set the shared folders via the virtualbox menu (guest window).<br />
在Linux主机端中,为共享的文件创建一个或更多的文件夹,然后通过Virtualbox菜单中设置(Windows客户端)<br />
<br />
在Windows客户端中,从VirtualBox 1.5.0开始,共享文件夹是可浏览的,所以在Windows资源管理器中是可视的。打开Windows资源管理器,在''我的网络位置(My Networking Places) &rarr; 整个网络(Entire Network) &rarr; VirtualBox Shared Folders(VirtualBox共享文件夹)''。<br />
<br />
启动Windows资源管理器(运行资源管理器命令),游览 网络位置(network places) -> (+)号展开:<br />
整个网络(entire network)&rarr; VirtualBox Shared Folders(VirtualBox共享文件夹) &rarr;'''\\Vboxsvr''' &rarr; 然后你就可以在此展开所有已配置的文件夹了,并且在客户端文件系统中为Linux文件夹创建快捷方式。你也可以使用“添加网络位置向导(Add network place wizard)”找到“VBoxsvr”。<br />
<br />
此外,在Windows命令行提示符中,你也可以使用以下命令:<br />
net use x: \\VBOXSVR\sharename<br />
<br />
虽然{{Codeline|VBOXSVR}}是一个固定名称,但请用你所想要用于共享的盘符替代{{Codeline|x:}},用VBoxManage指定的共享名替换sharename。<br />
<br />
在Windows客户端中,为了以VirtualBox共享文件夹改善文件的读取与保存(如MS Office),编辑''c:\windows\system32\drivers\etc\hosts''如下:<br />
127.0.0.1 localhost vboxsvr<br />
<br />
在Linux客户端中,实用以下命令:<br />
# mount -t vboxsf [-o OPTIONS] sharename mountpoint<br />
(注意:共享名是任意的,或者和VirtualBox对话框中选定的一样(在主机端文件系统中共享目录的挂载点)。<br />
:自动挂载共享文件夹可以通过Linux客户端 /etc/fstab 文件来实现。你可以指定uid=#,gid=#(# 用实际的数字uid和gid替换),以便以普通用户权限(而不是root权限)来挂载共享文件夹。(这个对于为了在Linux客户端中使用而挂载主机上~/home的一部分是很有用的。为了做到这点,依照以下格式添加一个条目到Linux客户端中的/etc/fstab:<br />
<br />
sharename mountpoint vboxsf uid=#,gid=# 0 0<br />
<br />
用在VBoxManage中指定的共享名替换{{Codeline|sharename}},并用你想要共享的路径替换mountpoint(如 /mnt/share)。通常的挂载申请,就是说,如果还没有的话,先创建这个文件夹。注意,如果你已经让VirtualBox“自动挂载”这个共享文件夹,这一步可能就不必了,而且你的文件夹可以在/media 下找到。<br />
<br />
除了mount命令提供的标准选项外,以下是可选的:<br />
iocharset=CHARSET<br />
设置用于I/O操作的字符集(默认utf8),并且:<br />
convertcp=CHARSET<br />
用于指定用于共享文件夹名称的字符集(默认utf8)<br />
<br />
===在客户端机器中激活声音===<br />
In the machine settings, go to the audio tab and select the correct driver according to your sound system (ALSA, OSS or PulseAudio).<br />
<br />
===为客户端设置内存和显卡内存===<br />
You can change the default values by going to ''Settings &rarr; General''.<br />
<br />
===为客户端设置CD-ROM===<br />
You can change the default values by going to ''Settings &rarr; CD/DVD-ROM''.<br />
<br />
Check mount CD/DVD drive and select one of the following options.<br />
<br />
===在Windows客户端中激活D3D加速===<br />
Recent versions of Virtualbox have support for accelerating OpenGL inside guests. This can be enabled with a simple checkbox in the machine's settings, right below where video ram is set, and installing the Virtualbox guest additions. However, most Windows games use Direct3D (part of DirectX), not OpenGL, and are thus not helped by this method. However, it is possible to gain accelerated Direct3D in your Windows guests by borrowing the d3d libraries from Wine, which translate d3d calls into OpenGL, which is then accelerated. <br />
<br />
After enabling OpenGL acceleration as described above, go to http://www.nongnu.org/wined3d/ in your Windows guest and grab the "Latest version (Installer):". Reboot the guest into safe mode (press F8 before the Windows screen appears but after the Virtualbox screen disappears), and install wined3d, accepting the defaults during the install. (You may check the box for DirectX 10 support if you like, dont touch anything else.) Reboot back to normal mode and you should have accelerated Direct3D. <br />
<br />
{{Note | This hack may or may not work for some games depending on what hardware checks they make and what parts of D3D they use.}}<br />
{{Note | This has only been tried on Windows XP and Windows 7 RC guests AFAIK, and does not work on the Windows 7 guest. If you have experience with this on a different windows version, please add that data here.}}<br />
<br />
==虚拟化系统安装==<br />
Virtualbox needs to be setup to virtualize another operating system.<br />
<br />
===测试LiveCD/DVD===<br />
通过点击 '新建' 按钮创建一个新的虚拟机环境, 给它起一个合适的名字, 然后选择对应的操作系统类型和版本. 选择基础内存大小(注意: 大多数的操作系统至少需要 512MB 内存才能够正常运行 ). 创建一个新的硬盘镜像( 这个操作系统里面的文件系统和文件都保存在你创建的硬盘镜像里,所以要根据你即将安装的那个系统的大小, 选择一个适当的容量, 最好宽裕一点,保证提供足够的空间, 磁盘空间不足会导致系统不能够正常运行, 甚至无法启动 ).<br />
<br />
当新的镜像文件创建完毕, 点击'设置' , 然后选择 CD/DVD-ROM , 再点击 '挂载CD/DVD 驱动器' , 找到你想要运行的 liveCD/DVD 镜像.<br />
{{Note | 注意, 虚拟机可能直接从硬盘启动, 而不是我们希望的启动光驱里面的 live 系统. 解决这个问题可以通过修改 BIOS 默认设备, 最方便的就是重新启动, 当Virtubox的画面出现时,按 F12, 这样子就会进入启动设备的启动列表, 按C就可以从光驱启动. }} <br />
<br />
==维护==<br />
<br />
===重建vboxdrv模块===<br />
注意每次内核版本改变(升级,重编译等),你必须重建VirtualBox内核模块。<br />
<br />
确保''kernel26-headers''已安装并运行以下命令:<br />
# rc.d setup vboxdrv<br />
<br />
这将会对当前运行内核创建VirtualBox内核模块;如果你已经升级了你的内核软件包,在尝试重建之前重启。<br />
<br />
重建模块后,不要忘记载入<br />
# modprobe vboxdrv<br />
<br />
''vboxdrv''和''vboxnetflt''应该在/etc/rc.conf的MODULES=()区段中<br />
<br />
如果你在使用旧virtualbox_bin软件包,从AUR中创建,运行:<br />
# vbox_build_module<br />
<br />
如果你需要在一个Arch Linux的客户端中重建VirtualBox增强包,使用该命令:<br />
# rc.d setup rc.vboxadd<br />
<br />
===压缩磁盘映像===<br />
==== Linux 客户端 ====<br />
启动Linux客户端并移除所有多余的东西(多余软件包,临时文件等)。满意之后,用dd或更好的dcfldd来擦除空闲空间:<br />
<br />
$ dcfldd if=/dev/zero of=fillfile bs=4M<br />
<br />
当填充文件达到了虚拟硬盘的限度,大量的用户空间(非保留块)将会被填满。或者,以Root的身份运行该命令以便填满所有空间。示例信息:"8192 blocks (8192Mb) written.dcfldd:: No space left on device."<br />
<br />
这种情况下,只需移除填充文件并关闭虚拟机:<br />
<br />
$ rm -f fillfile && sudo shutdown -hF now<br />
<br />
{{注意|考虑到经过压缩操作, -F 开关将会在重启前强迫磁盘检查。}}<br />
<br />
现在,压缩磁盘:<br />
<br />
$ VBoxManage modifyhd /path/to/your.vdi --compact<br />
<br />
==== Windows 客户端 ====<br />
<br />
参见 [http://www.mdl4.com/2010/04/virtualbox-compact-a-vdi-in-ubuntu this article].<br />
<br />
===为Windows客户端增加虚拟硬盘大小===<br />
警告:仅在XP下测试过!<br />
<br />
If you find that you are running out of space due to the small hard drive size you selected when created your VM, you can take the following steps:<br />
<br />
Create a new vdi in ~/.VirtualBox/HardDisks by running:<br />
# cd ~/.VirtualBox/HardDisks<br />
# VBoxManage createhd -filename new.vdi --size 10000 --remember<br />
<br />
where size is in mb, in this example 10000MB ~= 10GB, and new.vdi is name of new hard drive to be created.<br />
<br />
Next the old vdi needs to be cloned to the new vdi, this may take some time so wait while it occurs:<br />
# VBoxManage clonehd old.vdi new.vdi --existing<br />
<br />
Detach old harddrive and attach new hard drive, replace VMName with whatever you called your VM:<br />
# VBoxManage modifyvm VMName --hda none<br />
# VBoxManage modifyvm VMName --hda new.vdi<br />
<br />
Boot the VM, run Partition Wizard 5 to resize the partition on the fly, and reboot.<br />
<br />
Remove old vdi from VirtualBox and delete<br />
# VBoxManage closemedium disk old.vdi<br />
# rm old.vdi<br />
<br />
===Windows Xp 和 Nokia 手机===<br />
To get working Windows XP and Nokia phones with Pc Suite mode, Virtualbox needs two simple steps:<br />
<br />
'''1.''' Add a rule to udev with {{Filename|/etc/udev/rules.d/40-permissions.rules}}:<br />
LABEL="usb_serial_start"<br />
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \<br />
GROUP="usbfs", MODE="0660", GROUP="dialout"<br />
LABEL="usb_serial_end"<br />
<br />
'''2.''' Create the group usbfs and add its user to it<br />
$ sudo groupadd usbfs<br />
$ sudo usermod -a -G usbfs $USER<br />
<br />
After a logout, connect a Nokia phone with PC Suite mode and start Windows XP to test new rule.<br />
<br />
==从其他虚拟机中迁移==<br />
<code>qemu-img</code> 程序可以用来将映像从一种格式转换到另一种格式,或为一个映像添加压缩或加密。<br />
<br />
# pacman -S qemu<br />
<br />
===从QEMU映像转换===<br />
To convert a QEMU image for use with VirtualBox, first convert it to ''raw'' format, then use VirtualBox's conversion utility to convert and compact it in its native format.<br />
$ qemu-img convert -O raw test.qcow2 test.raw<br />
$ VBoxManage modifyvdi /full/path/to/test.vdi compact<br />
or <br />
$ qemu-img convert -O raw test.qcow2 test.raw<br />
(of course you must have installed qemu package for that)<br />
$ VBoxManage convertfromraw /full/path/to/test.raw /full/path/to/test.vdi<br />
$ VBoxManage modifyvdi /full/path/to/test.vdi compact<br />
<br />
===从VMware映像转换===<br />
运行 <br />
$ VBoxManage clonehd source.vmdk target.vdi --format VDI<br />
<br />
对于当前VirtualBox版本来说也许是不必要的(有待证实)<br />
<br />
==技巧和窍门==<br />
<br />
===获得可探测的Web-cam和其他USB设备===<br />
Make sure you filter any devices that are not a keyboard or a mouse so they don't start up at boot and this insures that Windows will detect the device at start-up.<br />
<br />
===向客户端发送CTRL+ALT+F1===<br />
如果你的客户端操作系统是Linux发行版,且你又想打开一个新的tty文本shell或者通过键入{{Keypress|Ctrl}}+{{Keypress|Alt}}+{{Keypress|F1}}来退出 X ,你可以简单地敲击你的'Host Key'向客户端操作系统发送这个命令(通常为键盘右边的{{Keypress|Ctrl}}) + {{Keypress|F1}} 或 {{Keypress|F2}},以此类推。<br />
<br />
===在运行于无显示器的服务器上的系统上启动虚拟机===<br />
Add this line to /etc/rc.local<br />
exec /bin/su -c 'VBoxManage startvm --type headless <''UUID|NAME''>' ''PREFERED_USER'' >/dev/null 2>&1<br />
Where <UUID|NAME> is the guest identifier, and PREFERRED_USER is the user profile that contains the VM definitions and .vdi files.<br />
<br />
Since exec replaces the currently running process, you will not be able to start a second VM, or execute any other commands, after the exec. Try the following if this is a problem:<br />
su -c 'VBoxHeadless -s <''UUID|NAME''> &' -s /bin/sh ''PREFERED_USER'' >/dev/null 2>&1<br />
Using fully qualified path to su and VBoxHeadless is recommend. Add additional lines like above to start additional VMs. Commands following these in rc.local will be executed. Based on some rooting around in the VBox documentation, I get the impression this will be a little more robust than 'VBoxManage ... --type headless' in future VBox releases.<br />
<br />
To determine the available VMs for a user:<br />
su -c 'VBoxManage list vms' PREFERED_USER<br />
<br />
To save the state of a running VM:<br />
su -c 'VBoxManage controlvm <UUID|NAME> savestate' PREFERED_USER<br />
rc.local.shutdown would be a good spot for this.<br />
<br />
=== 管理客户端的守护进程 ===<br />
Below is a [[daemon]] for automating guest administration. Guests will be initialized on start, and state-saved on stop, or you will just get a "./vbox_service: line 31: out[${m[1]}]: bad array subscript" message when you run it.<br />
<br />
The configuration file:<br />
{{File|name=/etc/conf.d/vbox_service|content=<nowiki><br />
# Guests to manage:<br />
#VB_GUESTS=('OpenBSD' 'Slackware' 'Windows XP')<br />
#<br />
# Disable a guest by prepending a bang:<br />
#VB_GUESTS=('OpenBSD' 'Slackware' !'Windows XP')<br />
#<br />
# Default value matches none:<br />
VB_GUESTS=()<br />
<br />
# User to run Virtual Box as:<br />
VB_USER='vbox'<br />
</nowiki>}}<br />
<br />
The script:<br />
{{File|name=/etc/rc.d/vbox_service|content=<nowiki><br />
#!/bin/bash<br />
<br />
. /etc/rc.conf<br />
. /etc/rc.d/functions<br />
<br />
unset VB_GUESTS<br />
unset VB_USER<br />
[[ -r /etc/conf.d/vbox_service ]] && . /etc/conf.d/vbox_service<br />
[[ ${VB_GUESTS[@]} ]] || VB_GUESTS=()<br />
[[ ${VB_USER[@]} ]] || VB_USER='vbox'<br />
<br />
<br />
match() {<br />
[[ $REPLY =~ $1 ]] && m=("${BASH_REMATCH[@]}")<br />
}<br />
<br />
<br />
vm_raw() {<br />
local argv=''<br />
printf -v argv ' %q ' "$@"<br />
su -c "/usr/bin/VBoxManage $argv" -s /bin/sh "$VB_USER"<br />
}<br />
<br />
vm_ls() {<br />
local -A out=''<br />
local -i ret=1<br />
<br />
local m=()<br />
while read -r; do<br />
match '^"(.+)" \{(.+)\}$'<br />
out[${m[1]}]=${m[2]}<br />
done < <(vm_raw list vms)<br />
<br />
local i=''<br />
for i in "${VB_GUESTS[@]##!*}"; do<br />
if [[ ${out[$i]} ]]; then<br />
printf ' %q ' "${out[$i]}"<br />
ret=0<br />
fi<br />
done<br />
<br />
return $ret<br />
}<br />
<br />
vm_envinit() {<br />
local m=()<br />
while read -r; do<br />
match '^(.+)="?([^"]+)'<br />
env[$1:${m[1]}]=${m[2]}<br />
done < <(vm_raw showvminfo --machinereadable "$1")<br />
}<br />
<br />
<br />
start() {<br />
if [[ ${env[$1:VMState]} != 'running' ]]; then<br />
vm_raw startvm --type headless "$1"<br />
fi<br />
}<br />
<br />
stop() {<br />
if [[ ${env[$1:VMState]} == 'running' ]]; then<br />
vm_raw controlvm "$1" savestate<br />
fi<br />
}<br />
<br />
restart() {<br />
stop "$1"<br />
sleep 3<br />
start "$1"<br />
}<br />
<br />
usage() {<br />
printf '%s\n' "usage: $0 <start|stop|restart> [name|uuid]..." >&2<br />
}<br />
<br />
<br />
if [[ ! $1 =~ ^(start|stop|restart)$ ]]; then<br />
usage<br />
exit 2<br />
fi<br />
cmd=$1<br />
shift<br />
(($#)) || eval set -- "$(vm_ls)"<br />
<br />
stat_busy "${cmd^}ing VMs:"<br />
trap 'stat_die' ERR<br />
set -Ee<br />
<br />
declare -A env=''<br />
<br />
for i; do<br />
[[ $i ]]<br />
vm_envinit "$i"<br />
stat_append "${env[$i:name]}, "<br />
$cmd "${env[$i:UUID]}" &>/dev/null<br />
done<br />
<br />
stat_done<br />
</nowiki>}}<br />
<br />
===从主机端访问虚拟机上的服务器===<br />
To access apache on a VM from the Host machine ONLY, simply execute the following lines on the Host:<br />
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/HostPort" 8888<br />
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/GuestPort" 80<br />
$ VBoxManage setextradata GuestName "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/Protocol" TCP<br />
Where 8888 is the port the host should listen on and 80 is the port the VM will send Apache's signal on. <br />
To use a port lower than 1024 on the host machine changes need to be made to the firewall on the host machine. This can also be set up to work with SSH, etc.. by changing "Apache" to whatever service and using different ports. <br />
<br />
Note: "pcnet" refers to the network card of the VM. If you use an Intel card in your VM settings change "pcnet" to "e1000"<br />
<br />
*from [http://mydebian.blogdns.org/?p=111 ]<br />
<br />
It might also be necessary to allow connections from the outside to the server in your VM. E.g. if the guest OS is Arch, you may want to add the line <br />
httpd: ALL<br />
to your /etc/hosts.allow file.<br />
<br />
===守护进程工具===<br />
While VirtualBox can mount ISO images without a problem, there are some image formats which cannot reliably be converted to ISO. For instance, ccd2iso ignores .ccd and .sub files, which can give disk images with broken files. cdemu, fuseiso, and MagicISO will do the same. In this case there is no choice but to use Daemon Tools inside VirtualBox.<br />
<br />
Recent Daemon Tools versions won't install, so use this old one: [http://www.disc-tools.com/download/daemon347+hashcalc]<br />
<br />
===在USB key上使用VirtualBox===<br />
When using VirtualBox on a USB key, for example to start an installed machine with an ISO image, you will manually have to create VDMKs from the existing drives. However, once the new VMDKs are saved and you move on to another machine, you may experience problems launching an appropriate machine again. To get rid of this issue, you can use the following script to launch VirtualBox. This script will clean up and unregister old VMDK files and it will create new, proper VMDKs for you:<br />
<pre><br />
#!/bin/bash<br />
<br />
# Erase old VMDK entries<br />
rm ~/.VirtualBox/*.vmdk<br />
<br />
# Clean up VBox-Registry<br />
sed -i '/sd/d' ~/.VirtualBox/VirtualBox.xml<br />
<br />
# Remove old harddisks from existing machines<br />
find ~/.VirtualBox/Machines -name \*.xml | while read file; do<br />
line=`grep -e "type\=\"HardDisk\"" -n $file | cut -d ':' -f 1`<br />
if [ -n "$line" ]; then<br />
sed -i ${line}d $file<br />
sed -i ${line}d $file<br />
sed -i ${line}d $file<br />
fi<br />
sed -i "/rg/d" $file<br />
done<br />
<br />
# Delete prev-files created by VirtualBox<br />
find ~/.VirtualBox/Machines -name \*-prev -exec rm '{}' \;<br />
<br />
# Recreate VMDKs<br />
ls -l /dev/disk/by-uuid | cut -d ' ' -f 9,11 | while read ln; do<br />
if [ -n "$ln" ]; then<br />
uuid=`echo "$ln" | cut -d ' ' -f 1`<br />
device=`echo "$ln" | cut -d ' ' -f 2 | cut -d '/' -f 3 | cut -b 1-3`<br />
<br />
# determine whether drive is mounted already<br />
checkstr1=`mount | grep $uuid`<br />
checkstr2=`mount | grep $device`<br />
checkstr3=`ls ~/.VirtualBox/*.vmdk | grep $device`<br />
if [[ -z "$checkstr1" && -z "$checkstr2" && -z "$checkstr3" ]]; then<br />
VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/$device.vmdk -rawdisk /dev/$device -register<br />
fi<br />
fi<br />
done<br />
<br />
# Start VirtualBox<br />
VirtualBox<br />
</pre><br />
Note that your user has to be added to the "disk" group to create VMDKs out of existing drives.<br />
<br />
===phpVirtualBox===<br />
An open source, AJAX implementation of the VirtualBox user interface written in PHP. As a modern web interface, it allows you to access and control remote VirtualBox instances. Much of its verbage and some of its code is based on the (inactive) vboxweb project. It allows the administrator to remotely, graphically, administer their virtual machines without having to log in to their headless VirtualBox servers.<br />
<br />
This requires the PUEL edition for VirtualBox.<br />
<br />
An installation guide is available here:<br />
http://code.google.com/p/phpvirtualbox/wiki/Installation<br />
<br />
Arch Linux users should uncomment these 2 extensions in ''/etc/php/php.ini''<br />
extension=json.so<br />
extension=soap.so<br />
<br />
See also [[PhpVirtualBox]]<br />
<br />
===USB子系统无法访问===<br />
USB子系统无法访问的问题常常出现,从早期的3.x版本到现在目前最新的4.1.0版本,都有出现。<br />
<br />
要解决这个问题,需要设置两个方面:<br />
<br />
* 将当前用户加入到vboxusers组<br />
* 挂载usbfs,在'''/etc/fstab'''中添加下面这一行,然后执行'''mount -a'''<br />
none /proc/bus/usb usbfs devmode=666 0 0<br />
<br />
==外部链接==<br />
* [http://www.virtualbox.org/manual/UserManual.html VirtualBox User Manual]</div>Athurghttps://wiki.archlinux.org/index.php?title=QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115482QEMU (简体中文)2010-08-26T09:21:41Z<p>Athurg: /* 桥接网络 */</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[Category:HOWTOs (简体中文)]]<br />
{{i18n|QEMU}}<br />
<br />
Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMware and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is open source. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.<br />
<br />
Qemu has the homepage at http://bellard.org/qemu/.<br />
<br />
<br />
=== 选择Windows版本===<br />
Qemu能够运行任何版本的Windows,不过默认的98, Me and XP运行起来很慢,而 Windows 95 和 Windows 2000都很快,尤其是2000(跑得甚至比95快,而win95的速度已经可以让你忘记自己是在使用虚拟机。)<br />
<br />
如果你同时拥有win95和win98/winme,推荐使用98lite(来自 http://www.litepc.com)。因为此版本不再使用默认的ie,而是替之用win95的Explorer。并且此版本还能最小化安装windows(把你通常不想要的都可以不要了),这样可以获得一个最小、最快、并且还稳定的windows系统,看起来不错哦。<br />
<br />
=== 安装 QEMU ===<br />
<br />
QEMU is available as a package in the [extra] repository. To install it, add the extra repo to /etc/pacman.conf, and do<br />
<pre><br />
pacman -S qemu<br />
</pre><br />
You can also install the optional kernel accelerator module KQEMU, which can also be found in the [extra] repository.<br />
<pre><br />
pacman -S kqemu<br />
</pre><br />
<br />
=== 创建硬盘镜像 ===<br />
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.<br />
<br />
Use the command:<br />
<pre><br />
qemu-img create -f qcow2 win.qcow 4G<br />
</pre><br />
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow2 format compresses the image so that the empty space doesn't add up to the size of the file.<br />
<br />
=== Preparing the installation media===<br />
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named "/dev/cdrom", you can dump it to a file with the command:<br />
<pre><br />
dd if=/dev/cdrom of=win98icd.iso<br />
</pre><br />
<br />
Do the same for floppies:<br />
<br />
<pre><br />
dd if=/dev/fd of=win95d1.img<br />
...<br />
</pre><br />
<br />
When you need to replace floppies within qemu, just copy the contents of one floppy over another. For this reason, it is useful to create a special file that will hold the current floppy:<br />
<br />
<pre><br />
touch floppy.img<br />
</pre><br />
<br />
=== Installing the operating system===<br />
<br />
This is the first time you will need to start the emulator.<br />
One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.<br />
<br />
If you need to use a bootable floppy, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
<br />
If your CD-ROM is bootable or you are using iso files, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
Now partition the virtual hard disk, format the partitions and install the OS.<br />
<br />
A few hints:<br />
# If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work<br />
# There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :<br />
<pre><br />
del %windir%\security\*.log<br />
</pre><br />
<br />
NOTE: According to the official QEMU website, "Windows 2000 has a bug which gives a disk full problem during its installation. When installing it, use the `-win2k-hack' QEMU option to enable a specific workaround. After Windows 2000 is installed, you no longer need this option (this option slows down the IDE transfers)."<br />
<br />
=== Running the system===<br />
<br />
To run the system simply type:<br />
<pre><br />
qemu [hd_image]<br />
</pre><br />
<br />
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file.<br />
You get rid of all the instability, because it is so easy to revert to previous system state :)<br />
<br />
To create an overlay image, type:<br />
<pre><br />
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]<br />
</pre>2<br />
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:<br />
<pre><br />
qemu [overlay_image]<br />
</pre><br />
or if you are on a x86_64 system:<br />
<pre><br />
qemu-system-x86_64 [overlay_image]<br />
</pre><br />
and the original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.<br />
<br />
=== 宿主机和虚拟机数据交互 ===<br />
<br />
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:<br />
<br />
==== Samba====<br />
<br />
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.<br />
<br />
First, you need to have a working samba installation. Then add the following section to your smb.conf:<br />
<pre><br />
[qemu]<br />
comment = Temporary file space<br />
path = /tmp<br />
read only = no<br />
public = yes<br />
</pre><br />
<br />
Now start qemu with:<br />
<pre><br />
qemu [hd_image] -smb qemu<br />
</pre><br />
<br />
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add<br />
<pre><br />
10.0.2.2 smbserver<br />
</pre><br />
to c:\windows\lmhosts (Win9x has Lmhosts.sam as a SAMple, rename it!).<br />
<br />
==== 挂载虚拟硬盘镜像 ====<br />
<br />
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:<br />
<pre><br />
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]<br />
</pre><br />
Now you can copy data in both directions. When you are done, umount with:<br />
<pre><br />
umount [hd_image]<br />
</pre><br />
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw harddrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.<br />
<br />
记住:挂载时千万不要启动虚拟机!<br />
<br />
==== Using any real partition as the single primary partition of a hard disk image ====<br />
<br />
Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.<br />
<br />
Suppose you have a plain, unmounted /dev/hdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:<br />
<br />
dd if=/dev/zero of=/path/to/mbr count=32<br />
<br />
Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:<br />
<br />
losetup -f /path/to/mbr<br />
<br />
Let's assume the resulting device is /dev/loop0, because we woudn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/hdaN disk image using software RAID:<br />
<br />
modprobe linear<br />
mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/hdaN<br />
<br />
The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/hdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:<br />
<br />
fdisk /dev/md0<br />
<br />
Press 'x' to enter the expert menu. Set number of 's'ectors per track so that the size of one<br />
cylinder matches the size of your mbr file. For two heads and the sector size is 512, the number of<br />
sectors per track should be 16, so we get cylinders of size 2x16x512=16k. Now, press 'r' to return<br />
to the main menu. Press 'p' and check that now the cylinder size is 16k.<br />
Now, create a single primary partition corresponding to /dev/hdaN. It should start at cylinder 2 and end at the end of the disk (note that the number of cylinders now differs from what it was when you entered fdisk. Finally, 'w'rite the result to the file: you are done. You know have a partition you can mount directly from your host, as well as part of a qemu disk image: <br />
<br />
qemu -hdc /dev/md0 [...]<br />
<br />
You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/hdaN partition contains the necessary tools.<br />
<br />
=== 优化 Windows 9x CPU使用率 ===<br />
<br />
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.<br />
<br />
=== Using the QEmu Accelerator Module===<br />
<br />
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option<br />
major=0<br />
to automate the creation of the required /dev/kqemu device. The following command<br />
echo "options kqemu major=0" >> /etc/modprobe.d/modprobe.conf<br />
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.<br />
<br />
Append kqemu to the list of modules in /etc/rc.conf to have it loaded the next time the your system starts. To load it now without rebooting, do the following as root<br />
modprobe kqemu<br />
<br />
If you are using Linux, Windows 2000 or Windows XP as guest OS, start qemu with the command line option<br />
qemu [...] -kernel-kqemu<br />
or, if you are on a x86_64 system (will not work otherwise):<br />
qemu-system-x86_64 [...] -kernel-kqemu<br />
This enables full virtualization and thus improves speed considerably.<br />
<br />
=== Using the Kernel-based Virtual Machine ===<br />
<br />
[[Kvm]] is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. Using [[Kvm]], one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.<br />
<br />
This technology requires an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions. It is included in the mainline linux kernel since 2.6.20.<br />
<br />
For versions of QEMU prior to 0.10.2-1 use the <code>qemu-kvm</code> executable. For 0.10.2-1 and later, use <code>qemu --enable-kvm</code>.<br />
<br />
To take advantage of [[Kvm]], you simply need a compatible processor (the following command must return something on screen)<br />
<br />
egrep '^flags.*(vmx|svm)' /proc/cpuinfo<br />
<br />
And load the appropriate module from your rc.conf<br />
<br />
* For Intel® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-intel<br />
<br />
* for AMD® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-amd<br />
<br />
Also, you will need to yourself to the group 'kvm'.<br />
<br />
===普通网络配置===<br />
如果虚拟机只是需要简单的联接外网,你只需给他加添简单的网络接口即可。方法就是在启动时加上“-net nic,vlan=1 -net user,vlan=1”选项即可。比如:<br />
qemu -kernel-kqemu -no-acpi -net nic,vlan=1 -net user,vlan=1 -cdrom dsl-4.3rc1.iso<br />
<br />
=== 桥接网络 ===<br />
NOTE:这部分由[[User:athurg]]根据实际体验过程翻译,和原文的流程有比较大的出入。如果有任何问题,请联系[[User:athurg]]。<br />
<br />
==== 简介 ====<br />
<br />
在QEMU中,桥接网络就是将虚拟机注册到主机的一个单独网络接口上,然后将这个接口和主机对外的网络接口一起桥接起来。如果你需要让虚拟机和外部网络完全互联互通时,就需要这么干了!不过需要提醒的是,这样的话客户机就完全暴露在网络中了。<br />
<br />
==== 准备 ====<br />
<br />
首先,请确认下面的软件包已经安装了:<br />
bridge-utils (for brctl, to manipulate bridges)<br />
uml_utilities (for tunctl, to manipulate taps)<br />
sudo (for manipulating bridges and tunnels as root)<br />
<br />
接下来加载桥接模块:<br />
<br />
# modprobe bridge<br />
<br />
==== 配置 ====<br />
<br />
首先,修改你的网络配置。增加一个桥接网络接口<code>br0</code>,用它来取代原来主机上的本地链接。打开<code>/etc/rc.conf</code>,将网络配置部分修改如下:<br />
<br />
eth0="eth0 up"<br />
br0="dhcp" #如果你原来的本地链接是DHCP方式获取配置的话<br />
#br0="br0 192.168.0.2 netmask 255.255.255.0 up" #如果你原来的本地链接是静态设置的话<br />
INTERFACES=(eth0 br0)<br />
<br />
然后,将原来的网络接口<code>eth0</code>绑定到桥接网络接口<code>br0</code>上,使得主机上的网络应用能够通过桥接网络接口,传递到外网中。编辑<code>/etc/conf.d/bridges</code>:<br />
bridge_br0="eth0"<br />
BRIDGE_INTERFACES=(br0)<br />
<br />
加载tap模块<br />
# modprobe tun<br />
<br />
创建一个<code>/etc/qemu-ifup</code>脚本,用于QEMU用来创建和加载虚拟机对外访问的网络接口。<br />
<br />
#!/bin/sh<br />
<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
sleep 2<br />
这个脚本的属主应该设置为root:kvm,权限为750,以使得kvm组的用户(可以启动虚拟机的用户)也能执行。这里也提醒大家一次,所有需要通过qemu使用KVM虚拟机的用户,都应当加入到kvm组中。<br />
<br />
由于这个脚本里需要调用ifconfig等命令来给虚拟机动态增减网络接口,为了方便我们在脚本里通过sudo来执行。如果不想脚本执行过程中向用户索取密码,请编辑<code>sudo</code>或者<code>visudo</code>的配置文件,加入下面这一行:<br />
<br />
Cmnd_Alias QEMU=/sbin/ifconfig,/sbin/modprobe,/usr/sbin/brctl,/usr/bin/tunctl<br />
%kvm ALL=NOPASSWD: QEMU<br />
<br />
最后,将<code>bridge</code>和<code>tun</code>加入到文件<code>/etc/rc.conf</code>的<code>MODULES</code>变量中,以便开机就能加载。<br />
<br />
==== 启动 ====<br />
一切配置妥当,我们就可以开始体验了。<br />
启动带桥接模式网络接口的QEMU大致有三个步骤<br />
* 通过tunctl申请一个可用的虚拟网络接口——tap设备。<br />
* 配置这个设备并桥接到桥接网络接口,然后启动qemu<br />
* 退出qemu时,别网络删掉这个虚拟网络接口。<br />
听上去很复杂吧?要是每次启动虚拟机都这么复杂不是很烦?我们可以创建一个脚本来实现:<br />
<br />
USERID=`whoami`<br />
IFACE=`sudo tunctl -b -u $USERID`<br />
<br />
qemu-kvm -net nic -net tap,ifname="$IFACE" $*<br />
<br />
sudo tunctl -d $IFACE &> /dev/null<br />
<br />
需要注意一点,由于我们前面创建了<code>/etc/qemu-ifup</code>这个脚本,因此我们只需要把申请到的虚拟网络接口名通过-net tap,ifname="网络接口名"告诉qemu,他自己会用这个接口名为参数,调用/etc/qemu-ifup来完成桥接和配置这个网络接口的过程。<br />
<br />
=== Qemu的前端 ===<br />
<br />
Qemu有几个图形前端,不习惯命令行的可以使用:<br />
<br />
* community/qemu-launcher<br />
* community/qemulator<br />
* community/qtemu<br />
<br />
===Keyboard seems broken / Arrow keys don't work===<br />
<br />
Should you find that some of your keys do not work or "press" the wrong key (in particular, the arrow keys), you likely need to specify your keyboard layout as an option. The keyboard layouts can be found in /usr/share/qemu/keymaps.<br />
<br />
<pre><br />
qemu -k [keymap] [disk_image]<br />
</pre><br />
<br />
=== External links ===<br />
* [http://kidsquid.com/cgi-bin/moin.cgi/QEMUMenu QEMUMenu for Windows].<br />
* [http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/ Network bridging setup for QEMU]</div>Athurghttps://wiki.archlinux.org/index.php?title=QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115481QEMU (简体中文)2010-08-26T09:19:23Z<p>Athurg: /* 启动 */</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[Category:HOWTOs (简体中文)]]<br />
{{i18n|QEMU}}<br />
<br />
Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMware and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is open source. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.<br />
<br />
Qemu has the homepage at http://bellard.org/qemu/.<br />
<br />
<br />
=== 选择Windows版本===<br />
Qemu能够运行任何版本的Windows,不过默认的98, Me and XP运行起来很慢,而 Windows 95 和 Windows 2000都很快,尤其是2000(跑得甚至比95快,而win95的速度已经可以让你忘记自己是在使用虚拟机。)<br />
<br />
如果你同时拥有win95和win98/winme,推荐使用98lite(来自 http://www.litepc.com)。因为此版本不再使用默认的ie,而是替之用win95的Explorer。并且此版本还能最小化安装windows(把你通常不想要的都可以不要了),这样可以获得一个最小、最快、并且还稳定的windows系统,看起来不错哦。<br />
<br />
=== 安装 QEMU ===<br />
<br />
QEMU is available as a package in the [extra] repository. To install it, add the extra repo to /etc/pacman.conf, and do<br />
<pre><br />
pacman -S qemu<br />
</pre><br />
You can also install the optional kernel accelerator module KQEMU, which can also be found in the [extra] repository.<br />
<pre><br />
pacman -S kqemu<br />
</pre><br />
<br />
=== 创建硬盘镜像 ===<br />
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.<br />
<br />
Use the command:<br />
<pre><br />
qemu-img create -f qcow2 win.qcow 4G<br />
</pre><br />
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow2 format compresses the image so that the empty space doesn't add up to the size of the file.<br />
<br />
=== Preparing the installation media===<br />
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named "/dev/cdrom", you can dump it to a file with the command:<br />
<pre><br />
dd if=/dev/cdrom of=win98icd.iso<br />
</pre><br />
<br />
Do the same for floppies:<br />
<br />
<pre><br />
dd if=/dev/fd of=win95d1.img<br />
...<br />
</pre><br />
<br />
When you need to replace floppies within qemu, just copy the contents of one floppy over another. For this reason, it is useful to create a special file that will hold the current floppy:<br />
<br />
<pre><br />
touch floppy.img<br />
</pre><br />
<br />
=== Installing the operating system===<br />
<br />
This is the first time you will need to start the emulator.<br />
One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.<br />
<br />
If you need to use a bootable floppy, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
<br />
If your CD-ROM is bootable or you are using iso files, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
Now partition the virtual hard disk, format the partitions and install the OS.<br />
<br />
A few hints:<br />
# If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work<br />
# There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :<br />
<pre><br />
del %windir%\security\*.log<br />
</pre><br />
<br />
NOTE: According to the official QEMU website, "Windows 2000 has a bug which gives a disk full problem during its installation. When installing it, use the `-win2k-hack' QEMU option to enable a specific workaround. After Windows 2000 is installed, you no longer need this option (this option slows down the IDE transfers)."<br />
<br />
=== Running the system===<br />
<br />
To run the system simply type:<br />
<pre><br />
qemu [hd_image]<br />
</pre><br />
<br />
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file.<br />
You get rid of all the instability, because it is so easy to revert to previous system state :)<br />
<br />
To create an overlay image, type:<br />
<pre><br />
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]<br />
</pre>2<br />
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:<br />
<pre><br />
qemu [overlay_image]<br />
</pre><br />
or if you are on a x86_64 system:<br />
<pre><br />
qemu-system-x86_64 [overlay_image]<br />
</pre><br />
and the original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.<br />
<br />
=== 宿主机和虚拟机数据交互 ===<br />
<br />
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:<br />
<br />
==== Samba====<br />
<br />
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.<br />
<br />
First, you need to have a working samba installation. Then add the following section to your smb.conf:<br />
<pre><br />
[qemu]<br />
comment = Temporary file space<br />
path = /tmp<br />
read only = no<br />
public = yes<br />
</pre><br />
<br />
Now start qemu with:<br />
<pre><br />
qemu [hd_image] -smb qemu<br />
</pre><br />
<br />
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add<br />
<pre><br />
10.0.2.2 smbserver<br />
</pre><br />
to c:\windows\lmhosts (Win9x has Lmhosts.sam as a SAMple, rename it!).<br />
<br />
==== 挂载虚拟硬盘镜像 ====<br />
<br />
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:<br />
<pre><br />
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]<br />
</pre><br />
Now you can copy data in both directions. When you are done, umount with:<br />
<pre><br />
umount [hd_image]<br />
</pre><br />
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw harddrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.<br />
<br />
记住:挂载时千万不要启动虚拟机!<br />
<br />
==== Using any real partition as the single primary partition of a hard disk image ====<br />
<br />
Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.<br />
<br />
Suppose you have a plain, unmounted /dev/hdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:<br />
<br />
dd if=/dev/zero of=/path/to/mbr count=32<br />
<br />
Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:<br />
<br />
losetup -f /path/to/mbr<br />
<br />
Let's assume the resulting device is /dev/loop0, because we woudn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/hdaN disk image using software RAID:<br />
<br />
modprobe linear<br />
mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/hdaN<br />
<br />
The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/hdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:<br />
<br />
fdisk /dev/md0<br />
<br />
Press 'x' to enter the expert menu. Set number of 's'ectors per track so that the size of one<br />
cylinder matches the size of your mbr file. For two heads and the sector size is 512, the number of<br />
sectors per track should be 16, so we get cylinders of size 2x16x512=16k. Now, press 'r' to return<br />
to the main menu. Press 'p' and check that now the cylinder size is 16k.<br />
Now, create a single primary partition corresponding to /dev/hdaN. It should start at cylinder 2 and end at the end of the disk (note that the number of cylinders now differs from what it was when you entered fdisk. Finally, 'w'rite the result to the file: you are done. You know have a partition you can mount directly from your host, as well as part of a qemu disk image: <br />
<br />
qemu -hdc /dev/md0 [...]<br />
<br />
You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/hdaN partition contains the necessary tools.<br />
<br />
=== 优化 Windows 9x CPU使用率 ===<br />
<br />
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.<br />
<br />
=== Using the QEmu Accelerator Module===<br />
<br />
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option<br />
major=0<br />
to automate the creation of the required /dev/kqemu device. The following command<br />
echo "options kqemu major=0" >> /etc/modprobe.d/modprobe.conf<br />
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.<br />
<br />
Append kqemu to the list of modules in /etc/rc.conf to have it loaded the next time the your system starts. To load it now without rebooting, do the following as root<br />
modprobe kqemu<br />
<br />
If you are using Linux, Windows 2000 or Windows XP as guest OS, start qemu with the command line option<br />
qemu [...] -kernel-kqemu<br />
or, if you are on a x86_64 system (will not work otherwise):<br />
qemu-system-x86_64 [...] -kernel-kqemu<br />
This enables full virtualization and thus improves speed considerably.<br />
<br />
=== Using the Kernel-based Virtual Machine ===<br />
<br />
[[Kvm]] is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. Using [[Kvm]], one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.<br />
<br />
This technology requires an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions. It is included in the mainline linux kernel since 2.6.20.<br />
<br />
For versions of QEMU prior to 0.10.2-1 use the <code>qemu-kvm</code> executable. For 0.10.2-1 and later, use <code>qemu --enable-kvm</code>.<br />
<br />
To take advantage of [[Kvm]], you simply need a compatible processor (the following command must return something on screen)<br />
<br />
egrep '^flags.*(vmx|svm)' /proc/cpuinfo<br />
<br />
And load the appropriate module from your rc.conf<br />
<br />
* For Intel® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-intel<br />
<br />
* for AMD® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-amd<br />
<br />
Also, you will need to yourself to the group 'kvm'.<br />
<br />
===普通网络配置===<br />
如果虚拟机只是需要简单的联接外网,你只需给他加添简单的网络接口即可。方法就是在启动时加上“-net nic,vlan=1 -net user,vlan=1”选项即可。比如:<br />
qemu -kernel-kqemu -no-acpi -net nic,vlan=1 -net user,vlan=1 -cdrom dsl-4.3rc1.iso<br />
<br />
=== 桥接网络 ===<br />
<br />
==== 简介 ====<br />
<br />
在QEMU中,桥接网络就是将虚拟机注册到主机的一个单独网络接口上,然后将这个接口和主机对外的网络接口一起桥接起来。如果你需要让虚拟机和外部网络完全互联互通时,就需要这么干了!不过需要提醒的是,这样的话客户机就完全暴露在网络中了。<br />
<br />
==== 准备 ====<br />
<br />
首先,请确认下面的软件包已经安装了:<br />
bridge-utils (for brctl, to manipulate bridges)<br />
uml_utilities (for tunctl, to manipulate taps)<br />
sudo (for manipulating bridges and tunnels as root)<br />
<br />
接下来按下面步骤走:<br />
<br />
1. Replace your normal ethernet adapter with a bridge adapter and bind your normal ethernet adapter to it. First install the bridging module:<br />
<br />
# modprobe bridge<br />
<br />
==== 配置 ====<br />
<br />
首先,修改你的网络配置。增加一个桥接网络接口<code>br0</code>,用它来取代原来主机上的本地链接。打开<code>/etc/rc.conf</code>,将网络配置部分修改如下:<br />
<br />
eth0="eth0 up"<br />
br0="dhcp" #如果你原来的本地链接是DHCP方式获取配置的话<br />
#br0="br0 192.168.0.2 netmask 255.255.255.0 up" #如果你原来的本地链接是静态设置的话<br />
INTERFACES=(eth0 br0)<br />
<br />
然后,将原来的网络接口<code>eth0</code>绑定到桥接网络接口<code>br0</code>上,使得主机上的网络应用能够通过桥接网络接口,传递到外网中。编辑<code>/etc/conf.d/bridges</code>:<br />
bridge_br0="eth0"<br />
BRIDGE_INTERFACES=(br0)<br />
<br />
加载tap模块<br />
# modprobe tun<br />
<br />
创建一个<code>/etc/qemu-ifup</code>脚本,用于QEMU用来创建和加载虚拟机对外访问的网络接口。<br />
<br />
#!/bin/sh<br />
<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
sleep 2<br />
这个脚本的属主应该设置为root:kvm,权限为750,以使得kvm组的用户(可以启动虚拟机的用户)也能执行。这里也提醒大家一次,所有需要通过qemu使用KVM虚拟机的用户,都应当加入到kvm组中。<br />
<br />
由于这个脚本里需要调用ifconfig等命令来给虚拟机动态增减网络接口,为了方便我们在脚本里通过sudo来执行。如果不想脚本执行过程中向用户索取密码,请编辑<code>sudo</code>或者<code>visudo</code>的配置文件,加入下面这一行:<br />
<br />
Cmnd_Alias QEMU=/sbin/ifconfig,/sbin/modprobe,/usr/sbin/brctl,/usr/bin/tunctl<br />
%kvm ALL=NOPASSWD: QEMU<br />
<br />
最后,将<code>bridge</code>和<code>tun</code>加入到文件<code>/etc/rc.conf</code>的<code>MODULES</code>变量中,以便开机就能加载。<br />
<br />
==== 启动 ====<br />
一切配置妥当,我们就可以开始体验了。<br />
启动带桥接模式网络接口的QEMU大致有三个步骤<br />
* 通过tunctl申请一个可用的虚拟网络接口——tap设备。<br />
* 配置这个设备并桥接到桥接网络接口,然后启动qemu<br />
* 退出qemu时,别网络删掉这个虚拟网络接口。<br />
听上去很复杂吧?要是每次启动虚拟机都这么复杂不是很烦?我们可以创建一个脚本来实现:<br />
<br />
USERID=`whoami`<br />
IFACE=`sudo tunctl -b -u $USERID`<br />
<br />
qemu-kvm -net nic -net tap,ifname="$IFACE" $*<br />
<br />
sudo tunctl -d $IFACE &> /dev/null<br />
<br />
需要注意一点,由于我们前面创建了<code>/etc/qemu-ifup</code>这个脚本,因此我们只需要把申请到的虚拟网络接口名通过-net tap,ifname="网络接口名"告诉qemu,他自己会用这个接口名为参数,调用/etc/qemu-ifup来完成桥接和配置这个网络接口的过程。<br />
<br />
=== Qemu的前端 ===<br />
<br />
Qemu有几个图形前端,不习惯命令行的可以使用:<br />
<br />
* community/qemu-launcher<br />
* community/qemulator<br />
* community/qtemu<br />
<br />
===Keyboard seems broken / Arrow keys don't work===<br />
<br />
Should you find that some of your keys do not work or "press" the wrong key (in particular, the arrow keys), you likely need to specify your keyboard layout as an option. The keyboard layouts can be found in /usr/share/qemu/keymaps.<br />
<br />
<pre><br />
qemu -k [keymap] [disk_image]<br />
</pre><br />
<br />
=== External links ===<br />
* [http://kidsquid.com/cgi-bin/moin.cgi/QEMUMenu QEMUMenu for Windows].<br />
* [http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/ Network bridging setup for QEMU]</div>Athurghttps://wiki.archlinux.org/index.php?title=QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115480QEMU (简体中文)2010-08-26T09:13:37Z<p>Athurg: /* 配置 */</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[Category:HOWTOs (简体中文)]]<br />
{{i18n|QEMU}}<br />
<br />
Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMware and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is open source. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.<br />
<br />
Qemu has the homepage at http://bellard.org/qemu/.<br />
<br />
<br />
=== 选择Windows版本===<br />
Qemu能够运行任何版本的Windows,不过默认的98, Me and XP运行起来很慢,而 Windows 95 和 Windows 2000都很快,尤其是2000(跑得甚至比95快,而win95的速度已经可以让你忘记自己是在使用虚拟机。)<br />
<br />
如果你同时拥有win95和win98/winme,推荐使用98lite(来自 http://www.litepc.com)。因为此版本不再使用默认的ie,而是替之用win95的Explorer。并且此版本还能最小化安装windows(把你通常不想要的都可以不要了),这样可以获得一个最小、最快、并且还稳定的windows系统,看起来不错哦。<br />
<br />
=== 安装 QEMU ===<br />
<br />
QEMU is available as a package in the [extra] repository. To install it, add the extra repo to /etc/pacman.conf, and do<br />
<pre><br />
pacman -S qemu<br />
</pre><br />
You can also install the optional kernel accelerator module KQEMU, which can also be found in the [extra] repository.<br />
<pre><br />
pacman -S kqemu<br />
</pre><br />
<br />
=== 创建硬盘镜像 ===<br />
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.<br />
<br />
Use the command:<br />
<pre><br />
qemu-img create -f qcow2 win.qcow 4G<br />
</pre><br />
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow2 format compresses the image so that the empty space doesn't add up to the size of the file.<br />
<br />
=== Preparing the installation media===<br />
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named "/dev/cdrom", you can dump it to a file with the command:<br />
<pre><br />
dd if=/dev/cdrom of=win98icd.iso<br />
</pre><br />
<br />
Do the same for floppies:<br />
<br />
<pre><br />
dd if=/dev/fd of=win95d1.img<br />
...<br />
</pre><br />
<br />
When you need to replace floppies within qemu, just copy the contents of one floppy over another. For this reason, it is useful to create a special file that will hold the current floppy:<br />
<br />
<pre><br />
touch floppy.img<br />
</pre><br />
<br />
=== Installing the operating system===<br />
<br />
This is the first time you will need to start the emulator.<br />
One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.<br />
<br />
If you need to use a bootable floppy, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
<br />
If your CD-ROM is bootable or you are using iso files, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
Now partition the virtual hard disk, format the partitions and install the OS.<br />
<br />
A few hints:<br />
# If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work<br />
# There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :<br />
<pre><br />
del %windir%\security\*.log<br />
</pre><br />
<br />
NOTE: According to the official QEMU website, "Windows 2000 has a bug which gives a disk full problem during its installation. When installing it, use the `-win2k-hack' QEMU option to enable a specific workaround. After Windows 2000 is installed, you no longer need this option (this option slows down the IDE transfers)."<br />
<br />
=== Running the system===<br />
<br />
To run the system simply type:<br />
<pre><br />
qemu [hd_image]<br />
</pre><br />
<br />
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file.<br />
You get rid of all the instability, because it is so easy to revert to previous system state :)<br />
<br />
To create an overlay image, type:<br />
<pre><br />
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]<br />
</pre>2<br />
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:<br />
<pre><br />
qemu [overlay_image]<br />
</pre><br />
or if you are on a x86_64 system:<br />
<pre><br />
qemu-system-x86_64 [overlay_image]<br />
</pre><br />
and the original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.<br />
<br />
=== 宿主机和虚拟机数据交互 ===<br />
<br />
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:<br />
<br />
==== Samba====<br />
<br />
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.<br />
<br />
First, you need to have a working samba installation. Then add the following section to your smb.conf:<br />
<pre><br />
[qemu]<br />
comment = Temporary file space<br />
path = /tmp<br />
read only = no<br />
public = yes<br />
</pre><br />
<br />
Now start qemu with:<br />
<pre><br />
qemu [hd_image] -smb qemu<br />
</pre><br />
<br />
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add<br />
<pre><br />
10.0.2.2 smbserver<br />
</pre><br />
to c:\windows\lmhosts (Win9x has Lmhosts.sam as a SAMple, rename it!).<br />
<br />
==== 挂载虚拟硬盘镜像 ====<br />
<br />
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:<br />
<pre><br />
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]<br />
</pre><br />
Now you can copy data in both directions. When you are done, umount with:<br />
<pre><br />
umount [hd_image]<br />
</pre><br />
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw harddrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.<br />
<br />
记住:挂载时千万不要启动虚拟机!<br />
<br />
==== Using any real partition as the single primary partition of a hard disk image ====<br />
<br />
Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.<br />
<br />
Suppose you have a plain, unmounted /dev/hdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:<br />
<br />
dd if=/dev/zero of=/path/to/mbr count=32<br />
<br />
Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:<br />
<br />
losetup -f /path/to/mbr<br />
<br />
Let's assume the resulting device is /dev/loop0, because we woudn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/hdaN disk image using software RAID:<br />
<br />
modprobe linear<br />
mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/hdaN<br />
<br />
The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/hdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:<br />
<br />
fdisk /dev/md0<br />
<br />
Press 'x' to enter the expert menu. Set number of 's'ectors per track so that the size of one<br />
cylinder matches the size of your mbr file. For two heads and the sector size is 512, the number of<br />
sectors per track should be 16, so we get cylinders of size 2x16x512=16k. Now, press 'r' to return<br />
to the main menu. Press 'p' and check that now the cylinder size is 16k.<br />
Now, create a single primary partition corresponding to /dev/hdaN. It should start at cylinder 2 and end at the end of the disk (note that the number of cylinders now differs from what it was when you entered fdisk. Finally, 'w'rite the result to the file: you are done. You know have a partition you can mount directly from your host, as well as part of a qemu disk image: <br />
<br />
qemu -hdc /dev/md0 [...]<br />
<br />
You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/hdaN partition contains the necessary tools.<br />
<br />
=== 优化 Windows 9x CPU使用率 ===<br />
<br />
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.<br />
<br />
=== Using the QEmu Accelerator Module===<br />
<br />
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option<br />
major=0<br />
to automate the creation of the required /dev/kqemu device. The following command<br />
echo "options kqemu major=0" >> /etc/modprobe.d/modprobe.conf<br />
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.<br />
<br />
Append kqemu to the list of modules in /etc/rc.conf to have it loaded the next time the your system starts. To load it now without rebooting, do the following as root<br />
modprobe kqemu<br />
<br />
If you are using Linux, Windows 2000 or Windows XP as guest OS, start qemu with the command line option<br />
qemu [...] -kernel-kqemu<br />
or, if you are on a x86_64 system (will not work otherwise):<br />
qemu-system-x86_64 [...] -kernel-kqemu<br />
This enables full virtualization and thus improves speed considerably.<br />
<br />
=== Using the Kernel-based Virtual Machine ===<br />
<br />
[[Kvm]] is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. Using [[Kvm]], one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.<br />
<br />
This technology requires an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions. It is included in the mainline linux kernel since 2.6.20.<br />
<br />
For versions of QEMU prior to 0.10.2-1 use the <code>qemu-kvm</code> executable. For 0.10.2-1 and later, use <code>qemu --enable-kvm</code>.<br />
<br />
To take advantage of [[Kvm]], you simply need a compatible processor (the following command must return something on screen)<br />
<br />
egrep '^flags.*(vmx|svm)' /proc/cpuinfo<br />
<br />
And load the appropriate module from your rc.conf<br />
<br />
* For Intel® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-intel<br />
<br />
* for AMD® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-amd<br />
<br />
Also, you will need to yourself to the group 'kvm'.<br />
<br />
===普通网络配置===<br />
如果虚拟机只是需要简单的联接外网,你只需给他加添简单的网络接口即可。方法就是在启动时加上“-net nic,vlan=1 -net user,vlan=1”选项即可。比如:<br />
qemu -kernel-kqemu -no-acpi -net nic,vlan=1 -net user,vlan=1 -cdrom dsl-4.3rc1.iso<br />
<br />
=== 桥接网络 ===<br />
<br />
==== 简介 ====<br />
<br />
在QEMU中,桥接网络就是将虚拟机注册到主机的一个单独网络接口上,然后将这个接口和主机对外的网络接口一起桥接起来。如果你需要让虚拟机和外部网络完全互联互通时,就需要这么干了!不过需要提醒的是,这样的话客户机就完全暴露在网络中了。<br />
<br />
==== 准备 ====<br />
<br />
首先,请确认下面的软件包已经安装了:<br />
bridge-utils (for brctl, to manipulate bridges)<br />
uml_utilities (for tunctl, to manipulate taps)<br />
sudo (for manipulating bridges and tunnels as root)<br />
<br />
接下来按下面步骤走:<br />
<br />
1. Replace your normal ethernet adapter with a bridge adapter and bind your normal ethernet adapter to it. First install the bridging module:<br />
<br />
# modprobe bridge<br />
<br />
==== 配置 ====<br />
<br />
首先,修改你的网络配置。增加一个桥接网络接口<code>br0</code>,用它来取代原来主机上的本地链接。打开<code>/etc/rc.conf</code>,将网络配置部分修改如下:<br />
<br />
eth0="eth0 up"<br />
br0="dhcp" #如果你原来的本地链接是DHCP方式获取配置的话<br />
#br0="br0 192.168.0.2 netmask 255.255.255.0 up" #如果你原来的本地链接是静态设置的话<br />
INTERFACES=(eth0 br0)<br />
<br />
然后,将原来的网络接口<code>eth0</code>绑定到桥接网络接口<code>br0</code>上,使得主机上的网络应用能够通过桥接网络接口,传递到外网中。编辑<code>/etc/conf.d/bridges</code>:<br />
bridge_br0="eth0"<br />
BRIDGE_INTERFACES=(br0)<br />
<br />
加载tap模块<br />
# modprobe tun<br />
<br />
创建一个<code>/etc/qemu-ifup</code>脚本,用于QEMU用来创建和加载虚拟机对外访问的网络接口。<br />
<br />
#!/bin/sh<br />
<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
sleep 2<br />
这个脚本的属主应该设置为root:kvm,权限为750,以使得kvm组的用户(可以启动虚拟机的用户)也能执行。这里也提醒大家一次,所有需要通过qemu使用KVM虚拟机的用户,都应当加入到kvm组中。<br />
<br />
由于这个脚本里需要调用ifconfig等命令来给虚拟机动态增减网络接口,为了方便我们在脚本里通过sudo来执行。如果不想脚本执行过程中向用户索取密码,请编辑<code>sudo</code>或者<code>visudo</code>的配置文件,加入下面这一行:<br />
<br />
Cmnd_Alias QEMU=/sbin/ifconfig,/sbin/modprobe,/usr/sbin/brctl,/usr/bin/tunctl<br />
%kvm ALL=NOPASSWD: QEMU<br />
<br />
最后,将<code>bridge</code>和<code>tun</code>加入到文件<code>/etc/rc.conf</code>的<code>MODULES</code>变量中,以便开机就能加载。<br />
<br />
==== 启动 ====<br />
<br />
8. You launch qemu using the following <code>run-qemu</code> script:<br />
<br />
USERID=`whoami`<br />
IFACE=`sudo tunctl -b -u $USERID`<br />
<br />
qemu-kvm -net nic -net tap,ifname="$IFACE" $*<br />
<br />
sudo tunctl -d $IFACE &> /dev/null<br />
<br />
=== Qemu的前端 ===<br />
<br />
Qemu有几个图形前端,不习惯命令行的可以使用:<br />
<br />
* community/qemu-launcher<br />
* community/qemulator<br />
* community/qtemu<br />
<br />
===Keyboard seems broken / Arrow keys don't work===<br />
<br />
Should you find that some of your keys do not work or "press" the wrong key (in particular, the arrow keys), you likely need to specify your keyboard layout as an option. The keyboard layouts can be found in /usr/share/qemu/keymaps.<br />
<br />
<pre><br />
qemu -k [keymap] [disk_image]<br />
</pre><br />
<br />
=== External links ===<br />
* [http://kidsquid.com/cgi-bin/moin.cgi/QEMUMenu QEMUMenu for Windows].<br />
* [http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/ Network bridging setup for QEMU]</div>Athurghttps://wiki.archlinux.org/index.php?title=QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115479QEMU (简体中文)2010-08-26T08:58:27Z<p>Athurg: /* Tap Networking with QEMU */</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[Category:HOWTOs (简体中文)]]<br />
{{i18n|QEMU}}<br />
<br />
Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMware and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is open source. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.<br />
<br />
Qemu has the homepage at http://bellard.org/qemu/.<br />
<br />
<br />
=== 选择Windows版本===<br />
Qemu能够运行任何版本的Windows,不过默认的98, Me and XP运行起来很慢,而 Windows 95 和 Windows 2000都很快,尤其是2000(跑得甚至比95快,而win95的速度已经可以让你忘记自己是在使用虚拟机。)<br />
<br />
如果你同时拥有win95和win98/winme,推荐使用98lite(来自 http://www.litepc.com)。因为此版本不再使用默认的ie,而是替之用win95的Explorer。并且此版本还能最小化安装windows(把你通常不想要的都可以不要了),这样可以获得一个最小、最快、并且还稳定的windows系统,看起来不错哦。<br />
<br />
=== 安装 QEMU ===<br />
<br />
QEMU is available as a package in the [extra] repository. To install it, add the extra repo to /etc/pacman.conf, and do<br />
<pre><br />
pacman -S qemu<br />
</pre><br />
You can also install the optional kernel accelerator module KQEMU, which can also be found in the [extra] repository.<br />
<pre><br />
pacman -S kqemu<br />
</pre><br />
<br />
=== 创建硬盘镜像 ===<br />
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.<br />
<br />
Use the command:<br />
<pre><br />
qemu-img create -f qcow2 win.qcow 4G<br />
</pre><br />
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow2 format compresses the image so that the empty space doesn't add up to the size of the file.<br />
<br />
=== Preparing the installation media===<br />
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named "/dev/cdrom", you can dump it to a file with the command:<br />
<pre><br />
dd if=/dev/cdrom of=win98icd.iso<br />
</pre><br />
<br />
Do the same for floppies:<br />
<br />
<pre><br />
dd if=/dev/fd of=win95d1.img<br />
...<br />
</pre><br />
<br />
When you need to replace floppies within qemu, just copy the contents of one floppy over another. For this reason, it is useful to create a special file that will hold the current floppy:<br />
<br />
<pre><br />
touch floppy.img<br />
</pre><br />
<br />
=== Installing the operating system===<br />
<br />
This is the first time you will need to start the emulator.<br />
One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.<br />
<br />
If you need to use a bootable floppy, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
<br />
If your CD-ROM is bootable or you are using iso files, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
Now partition the virtual hard disk, format the partitions and install the OS.<br />
<br />
A few hints:<br />
# If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work<br />
# There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :<br />
<pre><br />
del %windir%\security\*.log<br />
</pre><br />
<br />
NOTE: According to the official QEMU website, "Windows 2000 has a bug which gives a disk full problem during its installation. When installing it, use the `-win2k-hack' QEMU option to enable a specific workaround. After Windows 2000 is installed, you no longer need this option (this option slows down the IDE transfers)."<br />
<br />
=== Running the system===<br />
<br />
To run the system simply type:<br />
<pre><br />
qemu [hd_image]<br />
</pre><br />
<br />
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file.<br />
You get rid of all the instability, because it is so easy to revert to previous system state :)<br />
<br />
To create an overlay image, type:<br />
<pre><br />
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]<br />
</pre>2<br />
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:<br />
<pre><br />
qemu [overlay_image]<br />
</pre><br />
or if you are on a x86_64 system:<br />
<pre><br />
qemu-system-x86_64 [overlay_image]<br />
</pre><br />
and the original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.<br />
<br />
=== 宿主机和虚拟机数据交互 ===<br />
<br />
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:<br />
<br />
==== Samba====<br />
<br />
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.<br />
<br />
First, you need to have a working samba installation. Then add the following section to your smb.conf:<br />
<pre><br />
[qemu]<br />
comment = Temporary file space<br />
path = /tmp<br />
read only = no<br />
public = yes<br />
</pre><br />
<br />
Now start qemu with:<br />
<pre><br />
qemu [hd_image] -smb qemu<br />
</pre><br />
<br />
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add<br />
<pre><br />
10.0.2.2 smbserver<br />
</pre><br />
to c:\windows\lmhosts (Win9x has Lmhosts.sam as a SAMple, rename it!).<br />
<br />
==== 挂载虚拟硬盘镜像 ====<br />
<br />
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:<br />
<pre><br />
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]<br />
</pre><br />
Now you can copy data in both directions. When you are done, umount with:<br />
<pre><br />
umount [hd_image]<br />
</pre><br />
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw harddrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.<br />
<br />
记住:挂载时千万不要启动虚拟机!<br />
<br />
==== Using any real partition as the single primary partition of a hard disk image ====<br />
<br />
Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.<br />
<br />
Suppose you have a plain, unmounted /dev/hdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:<br />
<br />
dd if=/dev/zero of=/path/to/mbr count=32<br />
<br />
Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:<br />
<br />
losetup -f /path/to/mbr<br />
<br />
Let's assume the resulting device is /dev/loop0, because we woudn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/hdaN disk image using software RAID:<br />
<br />
modprobe linear<br />
mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/hdaN<br />
<br />
The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/hdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:<br />
<br />
fdisk /dev/md0<br />
<br />
Press 'x' to enter the expert menu. Set number of 's'ectors per track so that the size of one<br />
cylinder matches the size of your mbr file. For two heads and the sector size is 512, the number of<br />
sectors per track should be 16, so we get cylinders of size 2x16x512=16k. Now, press 'r' to return<br />
to the main menu. Press 'p' and check that now the cylinder size is 16k.<br />
Now, create a single primary partition corresponding to /dev/hdaN. It should start at cylinder 2 and end at the end of the disk (note that the number of cylinders now differs from what it was when you entered fdisk. Finally, 'w'rite the result to the file: you are done. You know have a partition you can mount directly from your host, as well as part of a qemu disk image: <br />
<br />
qemu -hdc /dev/md0 [...]<br />
<br />
You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/hdaN partition contains the necessary tools.<br />
<br />
=== 优化 Windows 9x CPU使用率 ===<br />
<br />
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.<br />
<br />
=== Using the QEmu Accelerator Module===<br />
<br />
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option<br />
major=0<br />
to automate the creation of the required /dev/kqemu device. The following command<br />
echo "options kqemu major=0" >> /etc/modprobe.d/modprobe.conf<br />
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.<br />
<br />
Append kqemu to the list of modules in /etc/rc.conf to have it loaded the next time the your system starts. To load it now without rebooting, do the following as root<br />
modprobe kqemu<br />
<br />
If you are using Linux, Windows 2000 or Windows XP as guest OS, start qemu with the command line option<br />
qemu [...] -kernel-kqemu<br />
or, if you are on a x86_64 system (will not work otherwise):<br />
qemu-system-x86_64 [...] -kernel-kqemu<br />
This enables full virtualization and thus improves speed considerably.<br />
<br />
=== Using the Kernel-based Virtual Machine ===<br />
<br />
[[Kvm]] is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. Using [[Kvm]], one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.<br />
<br />
This technology requires an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions. It is included in the mainline linux kernel since 2.6.20.<br />
<br />
For versions of QEMU prior to 0.10.2-1 use the <code>qemu-kvm</code> executable. For 0.10.2-1 and later, use <code>qemu --enable-kvm</code>.<br />
<br />
To take advantage of [[Kvm]], you simply need a compatible processor (the following command must return something on screen)<br />
<br />
egrep '^flags.*(vmx|svm)' /proc/cpuinfo<br />
<br />
And load the appropriate module from your rc.conf<br />
<br />
* For Intel® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-intel<br />
<br />
* for AMD® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-amd<br />
<br />
Also, you will need to yourself to the group 'kvm'.<br />
<br />
===普通网络配置===<br />
如果虚拟机只是需要简单的联接外网,你只需给他加添简单的网络接口即可。方法就是在启动时加上“-net nic,vlan=1 -net user,vlan=1”选项即可。比如:<br />
qemu -kernel-kqemu -no-acpi -net nic,vlan=1 -net user,vlan=1 -cdrom dsl-4.3rc1.iso<br />
<br />
=== 桥接网络 ===<br />
<br />
==== 简介 ====<br />
<br />
在QEMU中,桥接网络就是将虚拟机注册到主机的一个单独网络接口上,然后将这个接口和主机对外的网络接口一起桥接起来。如果你需要让虚拟机和外部网络完全互联互通时,就需要这么干了!不过需要提醒的是,这样的话客户机就完全暴露在网络中了。<br />
<br />
==== 准备 ====<br />
<br />
首先,请确认下面的软件包已经安装了:<br />
bridge-utils (for brctl, to manipulate bridges)<br />
uml_utilities (for tunctl, to manipulate taps)<br />
sudo (for manipulating bridges and tunnels as root)<br />
<br />
接下来按下面步骤走:<br />
<br />
1. Replace your normal ethernet adapter with a bridge adapter and bind your normal ethernet adapter to it. First install the bridging module:<br />
<br />
# modprobe bridge<br />
<br />
==== 配置 ====<br />
<br />
2. Configure your bridge <code>br0</code> to have your real ethernet adapter (herein assumed <code>eth0</code>) in it, in <code>/etc/conf.d/bridges</code>:<br />
bridge_br0="eth0"<br />
BRIDGE_INTERFACES=(br0)<br />
<br />
3. Change your networking configuration so that you just bring up your real ethernet adapter without configuring it, allowing real configuration to happen on the bridge interface. In <code>/etc/rc.conf</code>:<br />
<br />
eth0="eth0 up"<br />
br0="dhcp"<br />
INTERFACES=(eth0 br0)<br />
<br />
Remember, especially if you're doing DHCP, it's essential that the bridge comes up AFTER the real adapter, otherwise the bridge won't be able to talk to anything to get a DHCP address!<br />
<br />
4. Install the tunnel/tap module:<br />
<br />
# modprobe tun<br />
<br />
5. Install the script that QEMU uses to bring up the tap adapter in <code>/etc/qemu-ifup</code> with root:kvm 750 permissions:<br />
<br />
#!/bin/sh<br />
<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
sleep 2<br />
<br />
6. Use <code>visudo</code> to add the following to your <code>sudoers</code> file:<br />
<br />
Cmnd_Alias QEMU=/sbin/ifconfig,/sbin/modprobe,/usr/sbin/brctl,/usr/bin/tunctl<br />
%kvm ALL=NOPASSWD: QEMU<br />
<br />
7. Make sure the user(s) wishing to use this new functionality are in the kvm group. Exit and log in again if necessary.<br />
<br />
9. Add <code>bridge</code> and <code>tun</code> to your <code>MODULES</code> line in <code>/etc/rc.conf</code>.<br />
<br />
==== 启动 ====<br />
<br />
8. You launch qemu using the following <code>run-qemu</code> script:<br />
<br />
USERID=`whoami`<br />
IFACE=`sudo tunctl -b -u $USERID`<br />
<br />
qemu-kvm -net nic -net tap,ifname="$IFACE" $*<br />
<br />
sudo tunctl -d $IFACE &> /dev/null<br />
<br />
=== Qemu的前端 ===<br />
<br />
Qemu有几个图形前端,不习惯命令行的可以使用:<br />
<br />
* community/qemu-launcher<br />
* community/qemulator<br />
* community/qtemu<br />
<br />
===Keyboard seems broken / Arrow keys don't work===<br />
<br />
Should you find that some of your keys do not work or "press" the wrong key (in particular, the arrow keys), you likely need to specify your keyboard layout as an option. The keyboard layouts can be found in /usr/share/qemu/keymaps.<br />
<br />
<pre><br />
qemu -k [keymap] [disk_image]<br />
</pre><br />
<br />
=== External links ===<br />
* [http://kidsquid.com/cgi-bin/moin.cgi/QEMUMenu QEMUMenu for Windows].<br />
* [http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/ Network bridging setup for QEMU]</div>Athurghttps://wiki.archlinux.org/index.php?title=QEMU_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115478QEMU (简体中文)2010-08-26T08:53:55Z<p>Athurg: /* Basic Networking */</p>
<hr />
<div>[[Category:Emulators (简体中文)]]<br />
[[Category:HOWTOs (简体中文)]]<br />
{{i18n|QEMU}}<br />
<br />
Qemu is a fast cpu emulator using dynamic translation to achieve good emulation speed. Unlike VMware and Win4Lin, it emulates the cpu instead of only virtualizing the computer. This means that it is considerably slower, but on the other hand it is much more portable, stable and secure. Plus it is open source. It is great solution if you want to run some simple Windows applications like MS Office on a fast PC and you want to ensure maximum compatibility. It is also a great tool for operating system development. This HOWTO describes how to set up the emulator and install Windows 9x/2000 under it.<br />
<br />
Qemu has the homepage at http://bellard.org/qemu/.<br />
<br />
<br />
=== 选择Windows版本===<br />
Qemu能够运行任何版本的Windows,不过默认的98, Me and XP运行起来很慢,而 Windows 95 和 Windows 2000都很快,尤其是2000(跑得甚至比95快,而win95的速度已经可以让你忘记自己是在使用虚拟机。)<br />
<br />
如果你同时拥有win95和win98/winme,推荐使用98lite(来自 http://www.litepc.com)。因为此版本不再使用默认的ie,而是替之用win95的Explorer。并且此版本还能最小化安装windows(把你通常不想要的都可以不要了),这样可以获得一个最小、最快、并且还稳定的windows系统,看起来不错哦。<br />
<br />
=== 安装 QEMU ===<br />
<br />
QEMU is available as a package in the [extra] repository. To install it, add the extra repo to /etc/pacman.conf, and do<br />
<pre><br />
pacman -S qemu<br />
</pre><br />
You can also install the optional kernel accelerator module KQEMU, which can also be found in the [extra] repository.<br />
<pre><br />
pacman -S kqemu<br />
</pre><br />
<br />
=== 创建硬盘镜像 ===<br />
To run qemu you will probably need a hard disk image. This is a file which stores the contents of the emulated hard disk.<br />
<br />
Use the command:<br />
<pre><br />
qemu-img create -f qcow2 win.qcow 4G<br />
</pre><br />
to create the image file named "win.qcow". The "4G" parameter specifies the size of the disk - in this case 4 GB. You can use suffix M for megabytes (for example "256M"). You shouldn't worry too much about the size of the disk - the qcow2 format compresses the image so that the empty space doesn't add up to the size of the file.<br />
<br />
=== Preparing the installation media===<br />
The installation CD-ROM/floppy shouldn't be mounted, because Qemu accesses the media directly. It is a good idea to dump CD-ROM and/or floppy to a file, because it both improves performance and doesn't require you to have direct access to the devices (that is, you can run Qemu as a regular user). For example, if the CD-ROM device node is named "/dev/cdrom", you can dump it to a file with the command:<br />
<pre><br />
dd if=/dev/cdrom of=win98icd.iso<br />
</pre><br />
<br />
Do the same for floppies:<br />
<br />
<pre><br />
dd if=/dev/fd of=win95d1.img<br />
...<br />
</pre><br />
<br />
When you need to replace floppies within qemu, just copy the contents of one floppy over another. For this reason, it is useful to create a special file that will hold the current floppy:<br />
<br />
<pre><br />
touch floppy.img<br />
</pre><br />
<br />
=== Installing the operating system===<br />
<br />
This is the first time you will need to start the emulator.<br />
One thing to keep in mind: when you click inside qemu window, the mouse pointer is grabbed. To release it press Ctrl+Alt.<br />
<br />
If you need to use a bootable floppy, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -fda [[floppy''image]] -boot a [[hd_image]]<br />
</pre><br />
<br />
If your CD-ROM is bootable or you are using iso files, run Qemu with:<br />
<pre><br />
qemu -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
or if you are on a x86_64 system (will avoid many problems afterwards):<br />
<pre><br />
qemu-system-x86_64 -cdrom [[cdrom''image]] -boot d [[hd''image]]<br />
</pre><br />
Now partition the virtual hard disk, format the partitions and install the OS.<br />
<br />
A few hints:<br />
# If you are using Windows 95 boot floppy, then choosing SAMSUNG as the type of CD-ROM seems to work<br />
# There are problems when installing Windows 2000. Windows setup will generate a lot of edb*.log files, one after the other containing nothing but blank spaces in C:\WINNT\SECURITY which quickly fill the virtual harddisk. A workaround is to open a Windows command prompt as early as possible during setup (by pressing Shift-F10) which will allow you to remove these log files as they appear by typing :<br />
<pre><br />
del %windir%\security\*.log<br />
</pre><br />
<br />
NOTE: According to the official QEMU website, "Windows 2000 has a bug which gives a disk full problem during its installation. When installing it, use the `-win2k-hack' QEMU option to enable a specific workaround. After Windows 2000 is installed, you no longer need this option (this option slows down the IDE transfers)."<br />
<br />
=== Running the system===<br />
<br />
To run the system simply type:<br />
<pre><br />
qemu [hd_image]<br />
</pre><br />
<br />
A good idea is to use overlay images. This way you can create hard disk image once and tell Qemu to store changes in external file.<br />
You get rid of all the instability, because it is so easy to revert to previous system state :)<br />
<br />
To create an overlay image, type:<br />
<pre><br />
qemu-img create -b [[base''image]] -f qcow [[overlay''image]]<br />
</pre>2<br />
Substitute the hard disk image for base_image (in our case win.qcow). After that you can run qemu with:<br />
<pre><br />
qemu [overlay_image]<br />
</pre><br />
or if you are on a x86_64 system:<br />
<pre><br />
qemu-system-x86_64 [overlay_image]<br />
</pre><br />
and the original image will be left untouched. One hitch, the base image cannot be renamed or moved, the overlay remembers the base's full path.<br />
<br />
=== 宿主机和虚拟机数据交互 ===<br />
<br />
If you have servers on your host OS they will be accessible with the ip-address 10.0.2.2 without any further configuration. So you could just FTP or SSH, etc to 10.0.2.2 from windows to share data, or if you would like to use samba:<br />
<br />
==== Samba====<br />
<br />
Qemu supports SAMBA which allows you to mount host directories during the emulation. It seems that there is an incompatibility with SAMBA 3.x. and some versions of qemu. But at least with a current snapshot of qemu it should be working.<br />
<br />
First, you need to have a working samba installation. Then add the following section to your smb.conf:<br />
<pre><br />
[qemu]<br />
comment = Temporary file space<br />
path = /tmp<br />
read only = no<br />
public = yes<br />
</pre><br />
<br />
Now start qemu with:<br />
<pre><br />
qemu [hd_image] -smb qemu<br />
</pre><br />
<br />
Then you should be able to access your host's smb-server with the ip-address 10.0.2.2. If you're running Win9x as guest OS, you may need to add<br />
<pre><br />
10.0.2.2 smbserver<br />
</pre><br />
to c:\windows\lmhosts (Win9x has Lmhosts.sam as a SAMple, rename it!).<br />
<br />
==== 挂载虚拟硬盘镜像 ====<br />
<br />
Fortunately there is a way to mount the hard disk image with a loopback device. Login as root, make a temporary directory and mount the image with the command:<br />
<pre><br />
mount -o loop,offset=32256 [[hd''image]] [[tmp''dir]]<br />
</pre><br />
Now you can copy data in both directions. When you are done, umount with:<br />
<pre><br />
umount [hd_image]<br />
</pre><br />
The drawback of this solution is that you cannot use it with qcow images (including overlay images). So you need to create you images without \"-f qcow\" option. Tip: create a second, raw harddrive image. This way you'll be able to transfer data easily and use qcow overlay images for the primary drive.<br />
<br />
记住:挂载时千万不要启动虚拟机!<br />
<br />
==== Using any real partition as the single primary partition of a hard disk image ====<br />
<br />
Sometimes, you may wish to use one of your system partition from within qemu (for instance, if you wish booting both your real machine or qemu using a given partition as root). You can do this using software RAID in linear mode (you need the linear.ko kernel driver) and a loopback device: the trick is to dynamically prepend a master boot record (MBR) to the real partition you wish to embed in a qemu raw disk image.<br />
<br />
Suppose you have a plain, unmounted /dev/hdaN partition with some filesystem on it you wish to make part of a qemu disk image. First, you create some small file to hold the MBR:<br />
<br />
dd if=/dev/zero of=/path/to/mbr count=32<br />
<br />
Here, a 16 KB (32 * 512 bytes) file is created. It is important not to make it too small (even if the MBR only needs a single 512 bytes block), since the smaller it will be, the smaller the chunk size of the software RAID device will have to be, which could have an impact on performance. Then, you setup a loopback device to the MBR file:<br />
<br />
losetup -f /path/to/mbr<br />
<br />
Let's assume the resulting device is /dev/loop0, because we woudn't already have been using other loopbacks. Next step is to create the "merged" MBR + /dev/hdaN disk image using software RAID:<br />
<br />
modprobe linear<br />
mdadm --build --verbose /dev/md0 --chunk=16 --level=linear --raid-devices=2 /dev/loop0 /dev/hdaN<br />
<br />
The resulting /dev/md0 is what you will use as a qemu raw disk image (don't forget to set the permissions so that the emulator can access it). The last (and somewhat tricky) step is to set the disk configuration (disk geometry and partitions table) so that the primary partition start point in the MBR matches the one of /dev/hdaN inside /dev/md0 (an offset of exactly 16 * 512 = 16384 bytes in this example). Do this using fdisk on the host machine, not in the emulator: the default raw disc detection routine from qemu often results in non kilobyte-roundable offsets (such as 31.5 KB, as in the previous section) that cannot be managed by the software RAID code. Hence, from the the host:<br />
<br />
fdisk /dev/md0<br />
<br />
Press 'x' to enter the expert menu. Set number of 's'ectors per track so that the size of one<br />
cylinder matches the size of your mbr file. For two heads and the sector size is 512, the number of<br />
sectors per track should be 16, so we get cylinders of size 2x16x512=16k. Now, press 'r' to return<br />
to the main menu. Press 'p' and check that now the cylinder size is 16k.<br />
Now, create a single primary partition corresponding to /dev/hdaN. It should start at cylinder 2 and end at the end of the disk (note that the number of cylinders now differs from what it was when you entered fdisk. Finally, 'w'rite the result to the file: you are done. You know have a partition you can mount directly from your host, as well as part of a qemu disk image: <br />
<br />
qemu -hdc /dev/md0 [...]<br />
<br />
You can of course safely set any bootloader on this disk image using qemu, provided the original /boot/hdaN partition contains the necessary tools.<br />
<br />
=== 优化 Windows 9x CPU使用率 ===<br />
<br />
Windows 9x doesn't use hlt instruction, so the emulator always eats up 100% CPU even if no computation is being done. Grab the file http://www.user.cityline.ru/~maxamn/amnhltm.zip, unpack it, copy it to the image and run the .bat file.<br />
<br />
=== Using the QEmu Accelerator Module===<br />
<br />
The developers of qemu have created an optional kernel module to accelerate qemu to sometimes near native levels. This should be loaded with the option<br />
major=0<br />
to automate the creation of the required /dev/kqemu device. The following command<br />
echo "options kqemu major=0" >> /etc/modprobe.d/modprobe.conf<br />
will amend modprobe.conf to ensure that the module option is added every time the module is loaded.<br />
<br />
Append kqemu to the list of modules in /etc/rc.conf to have it loaded the next time the your system starts. To load it now without rebooting, do the following as root<br />
modprobe kqemu<br />
<br />
If you are using Linux, Windows 2000 or Windows XP as guest OS, start qemu with the command line option<br />
qemu [...] -kernel-kqemu<br />
or, if you are on a x86_64 system (will not work otherwise):<br />
qemu-system-x86_64 [...] -kernel-kqemu<br />
This enables full virtualization and thus improves speed considerably.<br />
<br />
=== Using the Kernel-based Virtual Machine ===<br />
<br />
[[Kvm]] is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. Using [[Kvm]], one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.<br />
<br />
This technology requires an x86 machine running a recent Linux kernel on an Intel processor with VT (virtualization technology) extensions, or an AMD processor with SVM extensions. It is included in the mainline linux kernel since 2.6.20.<br />
<br />
For versions of QEMU prior to 0.10.2-1 use the <code>qemu-kvm</code> executable. For 0.10.2-1 and later, use <code>qemu --enable-kvm</code>.<br />
<br />
To take advantage of [[Kvm]], you simply need a compatible processor (the following command must return something on screen)<br />
<br />
egrep '^flags.*(vmx|svm)' /proc/cpuinfo<br />
<br />
And load the appropriate module from your rc.conf<br />
<br />
* For Intel® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-intel<br />
<br />
* for AMD® processors add this module to your MODULES array in /etc/rc.conf<br />
<br />
kvm-amd<br />
<br />
Also, you will need to yourself to the group 'kvm'.<br />
<br />
===普通网络配置===<br />
如果虚拟机只是需要简单的联接外网,你只需给他加添简单的网络接口即可。方法就是在启动时加上“-net nic,vlan=1 -net user,vlan=1”选项即可。比如:<br />
qemu -kernel-kqemu -no-acpi -net nic,vlan=1 -net user,vlan=1 -cdrom dsl-4.3rc1.iso<br />
<br />
=== Tap Networking with QEMU ===<br />
<br />
==== Basic Idea ====<br />
<br />
Tap networking in QEMU lets virtual machines register themselves as though with separate ethernet adapters and have their traffic bridged directly onto your local area network. This is sometimes very desireable, if you want your virtual machines to be able to talk to each other, or for other machines on your LAN to talk to virtual machines.<br />
<br />
==== 安全提示 ====<br />
<br />
如果你的arch是联网状态,请不要使用此网络连接方式,这将让你的虚拟机暴露在互联网攻击威胁之下!<br />
<br />
In general, Arch disclaims any responsibility for security implications (or implications of any kind, really) from following these instructions.<br />
<br />
==== Nitty Gritty ====<br />
<br />
首先,请确认下面的软件包已经安装了:<br />
bridge-utils (for brctl, to manipulate bridges)<br />
uml_utilities (for tunctl, to manipulate taps)<br />
sudo (for manipulating bridges and tunnels as root)<br />
<br />
接下来按下面步骤走:<br />
<br />
1. Replace your normal ethernet adapter with a bridge adapter and bind your normal ethernet adapter to it. First install the bridging module:<br />
<br />
# modprobe bridge<br />
<br />
2. Configure your bridge <code>br0</code> to have your real ethernet adapter (herein assumed <code>eth0</code>) in it, in <code>/etc/conf.d/bridges</code>:<br />
bridge_br0="eth0"<br />
BRIDGE_INTERFACES=(br0)<br />
<br />
3. Change your networking configuration so that you just bring up your real ethernet adapter without configuring it, allowing real configuration to happen on the bridge interface. In <code>/etc/rc.conf</code>:<br />
<br />
eth0="eth0 up"<br />
br0="dhcp"<br />
INTERFACES=(eth0 br0)<br />
<br />
Remember, especially if you're doing DHCP, it's essential that the bridge comes up AFTER the real adapter, otherwise the bridge won't be able to talk to anything to get a DHCP address!<br />
<br />
4. Install the tunnel/tap module:<br />
<br />
# modprobe tun<br />
<br />
5. Install the script that QEMU uses to bring up the tap adapter in <code>/etc/qemu-ifup</code> with root:kvm 750 permissions:<br />
<br />
#!/bin/sh<br />
<br />
echo "Executing /etc/qemu-ifup"<br />
echo "Bringing up $1 for bridged mode..."<br />
sudo /sbin/ifconfig $1 0.0.0.0 promisc up<br />
echo "Adding $1 to br0..."<br />
sudo /usr/sbin/brctl addif br0 $1<br />
sleep 2<br />
<br />
6. Use <code>visudo</code> to add the following to your <code>sudoers</code> file:<br />
<br />
Cmnd_Alias QEMU=/sbin/ifconfig,/sbin/modprobe,/usr/sbin/brctl,/usr/bin/tunctl<br />
%kvm ALL=NOPASSWD: QEMU<br />
<br />
7. Make sure the user(s) wishing to use this new functionality are in the kvm group. Exit and log in again if necessary.<br />
<br />
8. You launch qemu using the following <code>run-qemu</code> script:<br />
<br />
USERID=`whoami`<br />
IFACE=`sudo tunctl -b -u $USERID`<br />
<br />
qemu-kvm -net nic -net tap,ifname="$IFACE" $*<br />
<br />
sudo tunctl -d $IFACE &> /dev/null<br />
<br />
9. Add <code>bridge</code> and <code>tun</code> to your <code>MODULES</code> line in <code>/etc/rc.conf</code>.<br />
<br />
=== Qemu的前端 ===<br />
<br />
Qemu有几个图形前端,不习惯命令行的可以使用:<br />
<br />
* community/qemu-launcher<br />
* community/qemulator<br />
* community/qtemu<br />
<br />
===Keyboard seems broken / Arrow keys don't work===<br />
<br />
Should you find that some of your keys do not work or "press" the wrong key (in particular, the arrow keys), you likely need to specify your keyboard layout as an option. The keyboard layouts can be found in /usr/share/qemu/keymaps.<br />
<br />
<pre><br />
qemu -k [keymap] [disk_image]<br />
</pre><br />
<br />
=== External links ===<br />
* [http://kidsquid.com/cgi-bin/moin.cgi/QEMUMenu QEMUMenu for Windows].<br />
* [http://mychael.gotdns.com/blog/2006/12/14/qemu-setup/ Network bridging setup for QEMU]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115105Arch boot process (简体中文)2010-08-24T10:24:17Z<p>Athurg: </p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
[[Category:简体中文]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[Locale_(简体中文)|本地化]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}}是多用户启动脚本下的本地化(个性化)脚本,默认是空的。通常情况下可以将一些需要在启动过程最后执行的命令放在这个脚本里。 Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
在修改这个文件时切记,该脚本(及其内部的所有命令)在模块载入和守护进程'''之后'''以root用户的权限运行。并且'''不管'''是否启动图形环境X都会执行。下面是一个在该脚本中调整ALSA声音设置例子<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
另外一个{{Filename|rc.local}}的用途,就是实现一些特殊的修改。<br />
<br />
== init: 登录 ==<br />
默认情况下,Arch启动过程完成后,{{Codeline|agetty}}程序就会启动,并提示用户输入用户名。在输入用户名后{{Codeline|agetty}}调用{{Codeline|login}},提示用户输入登录密码。<br />
<br />
最后,再成功登录后{{Codeline|login}}会启动用户的默认会话终端(shell)。默认终端和环境变量在{{Filename|/etc/profile}}下定义。还有一些别的配置在{{Filename|/etc}}目录下的文件中定义。用户也可以在自己的家目录下通过{{Filename|~/.bashrc}}这类的文件重新定义。如果两部分的定义冲突,那么将会优先采用主目录下的定义。<br />
<br />
[[Automatic login to virtual console|mingetty]]提供了一些选项,可以实现自动登录的功能。[[rungetty]]也提供了一些用户登陆时自动运行程序的功能。<br />
<br />
大多数用户可能希望启动[[X|图形界面]],这个时候可以安装一个KDM、GDM之类的显示管理器(参考[[Display Manager_(简体中文)|显示管理器]])。 当然你如果觉得不需要或者不喜欢用显示挂你器,也可以[[Start X at Boot_(简体中文)|直接启动图形界面]]。<br />
<br />
== 参考 ==<br />
<br />
* [[Startup files]]<br />
<br />
== 扩展资源 ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ 通过Grub启动到单用户模式]<br />
* [http://www.linuxjournal.com/article/4622 通过GRUB引导Linux]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Linux驱动过程探究]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix命令之sysctl.conf详解]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics 论坛中的rc.local范例]<br />
* [[Wikipedia:Linux startup process|维基百科中的启动过程解析]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115104Arch boot process (简体中文)2010-08-24T10:14:53Z<p>Athurg: </p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[Locale_(简体中文)|本地化]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}}是多用户启动脚本下的本地化(个性化)脚本,默认是空的。通常情况下可以将一些需要在启动过程最后执行的命令放在这个脚本里。 Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
在修改这个文件时切记,该脚本(及其内部的所有命令)在模块载入和守护进程'''之后'''以root用户的权限运行。并且'''不管'''是否启动图形环境X都会执行。下面是一个在该脚本中调整ALSA声音设置例子<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
另外一个{{Filename|rc.local}}的用途,就是实现一些特殊的修改。<br />
<br />
== init: 登录 ==<br />
默认情况下,Arch启动过程完成后,{{Codeline|agetty}}程序就会启动,并提示用户输入用户名。在输入用户名后{{Codeline|agetty}}调用{{Codeline|login}},提示用户输入登录密码。<br />
<br />
最后,再成功登录后{{Codeline|login}}会启动用户的默认会话终端(shell)。默认终端和环境变量在{{Filename|/etc/profile}}下定义。还有一些别的配置在{{Filename|/etc}}目录下的文件中定义。用户也可以在自己的家目录下通过{{Filename|~/.bashrc}}这类的文件重新定义。如果两部分的定义冲突,那么将会优先采用主目录下的定义。<br />
<br />
[[Automatic login to virtual console|mingetty]]提供了一些选项,可以实现自动登录的功能。[[rungetty]]也提供了一些用户登陆时自动运行程序的功能。<br />
<br />
大多数用户可能希望启动[[X|图形界面]],这个时候可以安装一个KDM、GDM之类的显示管理器(参考[[Display Manager_(简体中文)|显示管理器]])。 当然你如果觉得不需要或者不喜欢用显示挂你器,也可以[[Start X at Boot_(简体中文)|直接启动图形界面]]。<br />
<br />
== 参考 ==<br />
<br />
* [[Startup files]]<br />
<br />
== 扩展资源 ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ 通过Grub启动到单用户模式]<br />
* [http://www.linuxjournal.com/article/4622 通过GRUB引导Linux]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Linux驱动过程探究]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix命令之sysctl.conf详解]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics 论坛中的rc.local范例]<br />
* [[Wikipedia:Linux startup process|维基百科中的启动过程解析]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115103Arch boot process (简体中文)2010-08-24T10:11:20Z<p>Athurg: </p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}}是多用户启动脚本下的本地化(个性化)脚本,默认是空的。通常情况下可以将一些需要在启动过程最后执行的命令放在这个脚本里。 Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
在修改这个文件时切记,该脚本(及其内部的所有命令)在模块载入和守护进程'''之后'''以root用户的权限运行。并且'''不管'''是否启动图形环境X都会执行。下面是一个在该脚本中调整ALSA声音设置例子<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
另外一个{{Filename|rc.local}}的用途,就是实现一些特殊的修改。<br />
<br />
== init: 登录 ==<br />
默认情况下,Arch启动过程完成后,{{Codeline|agetty}}程序就会启动,并提示用户输入用户名。在输入用户名后{{Codeline|agetty}}调用{{Codeline|login}},提示用户输入登录密码。<br />
<br />
最后,再成功登录后{{Codeline|login}}会启动用户的默认会话终端(shell)。默认终端和环境变量在{{Filename|/etc/profile}}下定义。还有一些别的配置在{{Filename|/etc}}目录下的文件中定义。用户也可以在自己的家目录下通过{{Filename|~/.bashrc}}这类的文件重新定义。如果两部分的定义冲突,那么将会优先采用主目录下的定义。<br />
<br />
[[Automatic login to virtual console|mingetty]]提供了一些选项,可以实现自动登录的功能。[[rungetty]]也提供了一些用户登陆时自动运行程序的功能。<br />
<br />
大多数用户可能希望启动[[X|图形界面]],这个时候可以安装一个KDM、GDM之类的显示管理器(参考[[Display Manager|显示管理器]])。 当然你如果觉得不需要或者不喜欢用显示挂你器,也可以[[Start X at Boot|直接启动图形界面]]。<br />
<br />
== 参考 ==<br />
<br />
* [[Startup files]]<br />
<br />
== 扩展资源 ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ 通过Grub启动到单用户模式]<br />
* [http://www.linuxjournal.com/article/4622 通过GRUB引导Linux]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Linux驱动过程探究]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix命令之sysctl.conf详解]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics 论坛中的rc.local范例]<br />
* [[Wikipedia:Linux startup process|维基百科中的启动过程解析]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115102Arch boot process (简体中文)2010-08-24T10:07:49Z<p>Athurg: /* init: Login */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}}是多用户启动脚本下的本地化(个性化)脚本,默认是空的。通常情况下可以将一些需要在启动过程最后执行的命令放在这个脚本里。 Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
在修改这个文件时切记,该脚本(及其内部的所有命令)在模块载入和守护进程'''之后'''以root用户的权限运行。并且'''不管'''是否启动图形环境X都会执行。下面是一个在该脚本中调整ALSA声音设置例子<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
另外一个{{Filename|rc.local}}的用途,就是实现一些特殊的修改。<br />
<br />
== init: Login ==<br />
默认情况下,Arch启动过程完成后,{{Codeline|agetty}}程序就会启动,并提示用户输入用户名。在输入用户名后{{Codeline|agetty}}调用{{Codeline|login}},提示用户输入登录密码。<br />
<br />
最后,再成功登录后{{Codeline|login}}会启动用户的默认会话终端(shell)。默认终端和环境变量在{{Filename|/etc/profile}}下定义。还有一些别的配置在{{Filename|/etc}}目录下的文件中定义。用户也可以在自己的家目录下通过{{Filename|~/.bashrc}}这类的文件重新定义。如果两部分的定义冲突,那么将会优先采用主目录下的定义。<br />
<br />
[[Automatic login to virtual console|mingetty]]提供了一些选项,可以实现自动登录的功能。[[rungetty]]也提供了一些用户登陆时自动运行程序的功能。<br />
<br />
大多数用户可能希望启动[[X|图形界面]],这个时候可以安装一个KDM、GDM之类的显示管理器(参考[[Display Manager|显示管理器]])。 当然你如果觉得不需要或者不喜欢用显示挂你器,也可以[[Start X at Boot|直接启动图形界面]]。<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115101Arch boot process (简体中文)2010-08-24T09:56:12Z<p>Athurg: /* {{Filename|/etc/rc.local}} */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}}是多用户启动脚本下的本地化(个性化)脚本,默认是空的。通常情况下可以将一些需要在启动过程最后执行的命令放在这个脚本里。 Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
在修改这个文件时切记,该脚本(及其内部的所有命令)在模块载入和守护进程'''之后'''以root用户的权限运行。并且'''不管'''是否启动图形环境X都会执行。下面是一个在该脚本中调整ALSA声音设置例子<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
另外一个{{Filename|rc.local}}的用途,就是实现一些特殊的修改。<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115099Arch boot process (简体中文)2010-08-24T09:49:51Z<p>Athurg: /* {{Filename|/etc/rc.multi}} */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}}通常在多用户模式(运行级别为2~5)下执行。通常情况,从{{Filename|rc.sysinit}}切换到{{Filename|rc.multi}}时,用户不太能感觉到。因为两者使用的函数类似,导致输出的提示信息也差不多。这个脚本主要执行以下任务:<br />
<br />
* 首先,会根据{{Filename|/etc/sysctl.conf}}的设置,运行sysctl以在运行时修改内核参数,Arch除了网络配置外,通常很少用这么干。<br />
* 然后,会根据{{Filename|rc.conf}}文件中的{{Codeline|DAEMONS}}变量,执行非常重要的——[[daemons|服务(守护进程)]]启动任务。<br />
* 最后,会执行{{Filename|/etc/rc.local}}脚本<br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115098Arch boot process (简体中文)2010-08-24T09:42:21Z<p>Athurg: /* {{Filename|/etc/rc.single}} */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
单用户(Single)模式通常在无法正常启动时使用,他会直接以root用户启动。除了最基本的syslog-ng和udev外,不会启动任何服务。单用户模式在修复系统时,需要避免远程用户操作导致数据丢失时很有用。单用户模式下可以直接在提示符后输入'exit'进入到多用户模式。<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115097Arch boot process (简体中文)2010-08-24T09:34:36Z<p>Athurg: /* {{Filename|/etc/rc.sysinit}} */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。他通过一系列的初始化人物,完成所有的硬件配置。当你看到屏幕打印出下面这些行时,代表他开始运行了:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115096Arch boot process (简体中文)2010-08-24T09:32:34Z<p>Athurg: /* {{Filename|/etc/rc.sysinit}} */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}}是一个很大的启动脚本。that basically takes care of all hardware configuration plus a number of general initialization tasks. 这个脚本启动的标志就是打印出下面这些行:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
我们可以来看看这个脚本的任务列表:<br />
* 导入{{Filename|/etc/rc.conf}}文件<br />
* 导入{{Filename|/etc/rc.d/functions}}文件<br />
* 显示欢迎信息<br />
* 挂在各种各样的虚拟文件系统(proc、sysfs之类的)<br />
* 创建dummy设备的设备文件<br />
* 启动[[minilogd]]日志服务<br />
* 从[[dmesg]]输出内核启动信息<br />
* 配置硬件时钟<br />
* 清空设备热拔插{{Filename|/proc/sys/kernel/hotplug}}文件<br />
* 启动[[udev]]服务并检查udev事件<br />
* 启动回环([[loopback]])接口<br />
* 根据[[rc.conf]]文件中的{{Codeline|MODULES}}数组变量载入内核模块<br />
* 配置RAID和加密文件系统映射<br />
* 根据[[fstab|/etc/fstab]]的配置,运行[[fsck]]检查相应分区的完整性<br />
* 挂载本地文件系统和交换分区,(由于网络未加载,网络设备不会挂载)<br />
* 激活[[swap|交换分区]]<br />
* 根据{{Filename|rc.conf}}中的配置,设置主机名、locale、系统时钟<br />
* 移除leftover/temporary文件中的临时变量和文件,比如{{Filename|/tmp/*}}<br />
* 配置[[locale]]、终端、键盘映射<br />
* 设置终端字体<br />
* 输出dmesg中输出的信息到{{Filename|/var/log/dmesg.log}}中<br />
<br />
{{Filename|/etc/rc.sysinit}}是一个脚本。他本身并不包含任何的配置信息,而是通过导入[[rc.conf]]来读取配置信息。就连他内部使用的很多实现彩色输出(比如右对齐的busy、done字符串)的函数,也是定义在{{Filename|/etc/rc.d/functions}}中。通常情况下不需要编辑这个文件。当然如果为了通过减少某些不必要的步骤加速启动,也可以试试这么干。<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115095Arch boot process (简体中文)2010-08-24T09:18:51Z<p>Athurg: /* init: The Arch boot scripts */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
根据这个文件的第一个未被注释掉的行克制,系统默认的启动级别为3(启动器(bootloader)通常可以给内核传递系统的运行级别,如果没有传递,系统运行级别就采用这里的默认值),当内核调用init时:<br />
<br />
* 首先,运行主初始化脚本{{Filename|/etc/rc.sysinit}},这是个[[Bash]]脚本。 <br />
* 如果系统处于单用户模式(运行级别为1或者S),系统就会接着运行{{Filename|/etc/rc.single}}脚本。否者,如果系统处于2~5之间的运行级别,系统就会接着运行{{Filename|/etc/rc.multi}}脚本。<br />
* 最后运行的脚本是{{Filename|/etc/rc.local}},这个脚本默认什么都没有。<br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}} is a huge startup script that basically takes care of all hardware configuration plus a number of general initialization tasks. It can be identified by its first task, printing the lines:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
A rough overview of its tasks:<br />
* Sources the {{Filename|/etc/rc.conf}} script<br />
* Sources the {{Filename|/etc/rc.d/functions}} script<br />
* Displays a welcome message<br />
* Mounts various virtual file systems<br />
* Creates dummy device files<br />
* Starts [[minilogd]]<br />
* Outputs messages from [[dmesg]]<br />
* Configures the hardware clock<br />
* Empties the {{Filename|/proc/sys/kernel/hotplug}} file<br />
* Starts [[udev]] and checks for udev events <br />
* Starts the [[loopback]] interface<br />
* Loads modules from the {{Codeline|MODULES}} array defined in [[rc.conf]]<br />
* Configures RAID and encrypted filesystem mappings<br />
* Runs a forced check of partitions ([[fsck]]) if the [[fstab|/etc/fstab]] file contains instructions to do so<br />
* Mounts local partitions and swap (networked drives are not mounted before a network profile is up)<br />
* Activates [[swap]] areas<br />
* Sets the hostname, locale and system clock as defined in {{Filename|rc.conf}}<br />
* Removes various leftover/temporary files, such as {{Filename|/tmp/*}}<br />
* Configures the [[locale]], console and keyboard mappings<br />
* Sets the console font<br />
* Writes output from dmesg to {{Filename|/var/log/dmesg.log}}<br />
<br />
{{Filename|/etc/rc.sysinit}} is a script and not a place for settings. It sources (i.e. reads and inherits variables and functions) [[rc.conf]] for settings and {{Filename|/etc/rc.d/functions}} for the functions that produce its graphical output (nice colors, alignments, switching 'busy' to 'done', etc.) There is no particular need to edit this file, although some may wish to do so in order to speed up the boot process.<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115094Arch boot process (简体中文)2010-08-24T09:06:50Z<p>Athurg: /* init: The Arch boot scripts */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
Arch主要的启动过程是由{{Codeline|init}}完成的,他通过克隆出其他的进程(以及这些进程克隆出的进程),使系统进入一个可用的状态。正如前文中提到的,Arch使用的是一种BSD风格的引导脚本。具体来说,{{Codeline|init}}程序会首先读取{{Filename|/etc/inittab}}这个配置文件,{{Filename|inittab}}通常像这样:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
The first uncommented line defines the default system runlevel (3). When the kernel calls init:<br />
<br />
* First, the main initialization script is run, {{Filename|/etc/rc.sysinit}} (a [[Bash]] script). <br />
* If started in single user mode (runlevel 1 or S), the script {{Filename|/etc/rc.single}} will be run. <br />
* If in any other runlevel (2-5), {{Filename|/etc/rc.multi}} is run instead.<br />
* The last script to run will be {{Filename|/etc/rc.local}}, which is empty by default. <br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}} is a huge startup script that basically takes care of all hardware configuration plus a number of general initialization tasks. It can be identified by its first task, printing the lines:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
A rough overview of its tasks:<br />
* Sources the {{Filename|/etc/rc.conf}} script<br />
* Sources the {{Filename|/etc/rc.d/functions}} script<br />
* Displays a welcome message<br />
* Mounts various virtual file systems<br />
* Creates dummy device files<br />
* Starts [[minilogd]]<br />
* Outputs messages from [[dmesg]]<br />
* Configures the hardware clock<br />
* Empties the {{Filename|/proc/sys/kernel/hotplug}} file<br />
* Starts [[udev]] and checks for udev events <br />
* Starts the [[loopback]] interface<br />
* Loads modules from the {{Codeline|MODULES}} array defined in [[rc.conf]]<br />
* Configures RAID and encrypted filesystem mappings<br />
* Runs a forced check of partitions ([[fsck]]) if the [[fstab|/etc/fstab]] file contains instructions to do so<br />
* Mounts local partitions and swap (networked drives are not mounted before a network profile is up)<br />
* Activates [[swap]] areas<br />
* Sets the hostname, locale and system clock as defined in {{Filename|rc.conf}}<br />
* Removes various leftover/temporary files, such as {{Filename|/tmp/*}}<br />
* Configures the [[locale]], console and keyboard mappings<br />
* Sets the console font<br />
* Writes output from dmesg to {{Filename|/var/log/dmesg.log}}<br />
<br />
{{Filename|/etc/rc.sysinit}} is a script and not a place for settings. It sources (i.e. reads and inherits variables and functions) [[rc.conf]] for settings and {{Filename|/etc/rc.d/functions}} for the functions that produce its graphical output (nice colors, alignments, switching 'busy' to 'done', etc.) There is no particular need to edit this file, although some may wish to do so in order to speed up the boot process.<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115091Arch boot process (简体中文)2010-08-24T08:58:41Z<p>Athurg: /* init进程之前 */</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
内核是一个操作系统的核心。他作用于非常底层的硬件和控制硬件的程序之间的部分(又称之为''内核空间'')。由于CPU在某个时刻只能执行一个任务,为了更为高效的使用CPU,内核使用称之为调度器的玩意。他通过一定的优先级算法,来将CPU按照时间动态的分配给各个人物。给我们的感觉就像所有程序都在使用CPU一样。<br />
<br />
在内核载入后,会去处理[[initramfs]](初始化RAM文件系统)。initramfs不一定是必须的,仅限于根文件系统所需的内核模块(比如IDE驱动)没有被编译到内核中时才需要(参考[[FHS]])。换句话说他只需要包含内核中没有,并且访问根文件系统所必须的模块。比如IDE、SCSI、SATA(如果从USB设备中启动的话,肯定还有USB/FW模块)这类驱动驱动。在initramfs载入了必要的模块后,他就会将控制权交回给内核,继续引导过程。因此,initrd无须包含其他的模块都包含,其他模块可以在随后的引导中会通过[[udev]]载入。<br />
<br />
然后内核就会去找{{Codeline|init}}程序,通常就是根文件系统下的{{Filename|/sbin/init}}文件。{{Codeline|init}}的实现依赖于GNU C基础库{{Codeline|glibc}}。Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. 这部分启动过程又称之为''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
The main Arch startup process is initiated by the program {{Codeline|init}}, which spawns all other processes. The purpose of {{Codeline|init}} is to bring the system into a usable state, using the boot scripts to do so. As previously mentioned, Arch uses BSD-style boot scripts. {{Codeline|init}} reads the file {{Filename|/etc/inittab}}; the default {{Filename|inittab}} begins with the following:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
The first uncommented line defines the default system runlevel (3). When the kernel calls init:<br />
<br />
* First, the main initialization script is run, {{Filename|/etc/rc.sysinit}} (a [[Bash]] script). <br />
* If started in single user mode (runlevel 1 or S), the script {{Filename|/etc/rc.single}} will be run. <br />
* If in any other runlevel (2-5), {{Filename|/etc/rc.multi}} is run instead.<br />
* The last script to run will be {{Filename|/etc/rc.local}}, which is empty by default. <br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}} is a huge startup script that basically takes care of all hardware configuration plus a number of general initialization tasks. It can be identified by its first task, printing the lines:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
A rough overview of its tasks:<br />
* Sources the {{Filename|/etc/rc.conf}} script<br />
* Sources the {{Filename|/etc/rc.d/functions}} script<br />
* Displays a welcome message<br />
* Mounts various virtual file systems<br />
* Creates dummy device files<br />
* Starts [[minilogd]]<br />
* Outputs messages from [[dmesg]]<br />
* Configures the hardware clock<br />
* Empties the {{Filename|/proc/sys/kernel/hotplug}} file<br />
* Starts [[udev]] and checks for udev events <br />
* Starts the [[loopback]] interface<br />
* Loads modules from the {{Codeline|MODULES}} array defined in [[rc.conf]]<br />
* Configures RAID and encrypted filesystem mappings<br />
* Runs a forced check of partitions ([[fsck]]) if the [[fstab|/etc/fstab]] file contains instructions to do so<br />
* Mounts local partitions and swap (networked drives are not mounted before a network profile is up)<br />
* Activates [[swap]] areas<br />
* Sets the hostname, locale and system clock as defined in {{Filename|rc.conf}}<br />
* Removes various leftover/temporary files, such as {{Filename|/tmp/*}}<br />
* Configures the [[locale]], console and keyboard mappings<br />
* Sets the console font<br />
* Writes output from dmesg to {{Filename|/var/log/dmesg.log}}<br />
<br />
{{Filename|/etc/rc.sysinit}} is a script and not a place for settings. It sources (i.e. reads and inherits variables and functions) [[rc.conf]] for settings and {{Filename|/etc/rc.d/functions}} for the functions that produce its graphical output (nice colors, alignments, switching 'busy' to 'done', etc.) There is no particular need to edit this file, although some may wish to do so in order to speed up the boot process.<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_boot_process_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=115088Arch boot process (简体中文)2010-08-24T08:36:26Z<p>Athurg: Created page with "Category:Boot process (简体中文) Category:About Arch (简体中文) {{i18n|Arch Boot Process}} This article is intended to give a chronological overview of the Arch ..."</p>
<hr />
<div>[[Category:Boot process (简体中文)]]<br />
[[Category:About Arch (简体中文)]]<br />
{{i18n|Arch Boot Process}}<br />
<br />
This article is intended to give a chronological overview of the Arch boot process and the system files and processes involved, providing links to relevant wiki articles where necessary. Arch famously follows the BSD init convention as opposed to the more common SysV. What this means is that there is little distinction between runlevels, since the system by default is configured to use the same modules and run the same processes on all runlevels. The advantage is that users have a simple way to configure the startup process (see [[rc.conf]]); the disadvantage is that some fine-grained configuration options that SysV offers are lost. See [[Adding Runlevels]] for a way to hack some SysV-like capabilities into Arch. See [[Wikipedia:init]] for more on the distinctions between SysV and BSD style.<br />
<br />
== init进程之前 ==<br />
系统开机并且执行完[[Wikipedia:Power-on self-test|开机自检]]后,BIOS会根据自身设置选择最佳的启动媒介。把控制权传递给该媒介的主引导记录([[Master Boot Record]])部分。再GNU/Linux系统中,MBR里通常是像[[GRUB]]、[[LILO]]这样的引导器(bootloader)。引导器通常会给用户一个菜单或者命令行之类的机制,供用户选择和设置。例如[[Windows and Arch Dual Boot|双系统的设置]]。一旦你选择启动Arch时,引导器就会载入{{Filename|/boot}} 目录下的内核镜像(比如{{Filename|kernel26.img}}),并解压缩。<br />
<br />
The kernel is the core of an operating system. It functions on a low level (''kernelspace'') interacting between the hardware of the machine, and the programs which use the hardware to run. To make efficient use of the CPU, the kernel uses a scheduler to arbitrate which tasks take priority at any given moment, creating the illusion (to human perception) of many tasks being executed simultaneously. <br />
<br />
After the kernel is loaded, it reads from the [[initramfs]] (initial RAM filesystem). The purpose of the initramfs is to bootstrap the system to the point where it can access the root filesystem (see [[FHS]] for details). This means that any modules that are required for devices like IDE, SCSI, or SATA drives (or USB/FW, if booting off a USB/FW drive) must be loaded. Once the initramfs loads the proper modules, either manually or through [[udev]], it passes control to the kernel and the boot process continues. For this reason, the initrd only needs to contain the modules necessary to access the root filesystem; it does not need to contain every module one would ever want to use. The majority of modules will be loaded later on by udev, during the init process. <br />
<br />
The kernel then looks for the program {{Codeline|init}} which resides at {{Filename|/sbin/init}}. {{Codeline|init}} relies on {{Codeline|glibc}}, the GNU C library. Libraries are collections of frequently used program routines and are readily identifiable through their filename extension of {{Filename|*.so}}. They are essential for basic system functionality. This part of the boot process is called ''early userspace''.<br />
<br />
== init: The Arch boot scripts ==<br />
The main Arch startup process is initiated by the program {{Codeline|init}}, which spawns all other processes. The purpose of {{Codeline|init}} is to bring the system into a usable state, using the boot scripts to do so. As previously mentioned, Arch uses BSD-style boot scripts. {{Codeline|init}} reads the file {{Filename|/etc/inittab}}; the default {{Filename|inittab}} begins with the following:<br />
<br />
{{File<br />
|name=/etc/inittab<br />
|content=<nowiki><br />
...<br />
<br />
# Boot to console<br />
id:3:initdefault:<br />
# Boot to X11<br />
#id:5:initdefault:<br />
<br />
rc::sysinit:/etc/rc.sysinit<br />
rs:S1:wait:/etc/rc.single<br />
rm:2345:wait:/etc/rc.multi<br />
rh:06:wait:/etc/rc.shutdown<br />
su:S:wait:/sbin/sulogin<br />
<br />
...<br />
</nowiki>}}<br />
<br />
The first uncommented line defines the default system runlevel (3). When the kernel calls init:<br />
<br />
* First, the main initialization script is run, {{Filename|/etc/rc.sysinit}} (a [[Bash]] script). <br />
* If started in single user mode (runlevel 1 or S), the script {{Filename|/etc/rc.single}} will be run. <br />
* If in any other runlevel (2-5), {{Filename|/etc/rc.multi}} is run instead.<br />
* The last script to run will be {{Filename|/etc/rc.local}}, which is empty by default. <br />
<br />
=== {{Filename|/etc/rc.sysinit}} ===<br />
{{Filename|rc.sysinit}} is a huge startup script that basically takes care of all hardware configuration plus a number of general initialization tasks. It can be identified by its first task, printing the lines:<br />
<br />
Arch Linux<br />
http://www.archlinux.org<br />
Copyright 2002-2007 Judd Vinet<br />
Copyright 2007-2010 Aaron Griffin<br />
Distributed under the GNU General Public License (GPL)<br />
<br />
A rough overview of its tasks:<br />
* Sources the {{Filename|/etc/rc.conf}} script<br />
* Sources the {{Filename|/etc/rc.d/functions}} script<br />
* Displays a welcome message<br />
* Mounts various virtual file systems<br />
* Creates dummy device files<br />
* Starts [[minilogd]]<br />
* Outputs messages from [[dmesg]]<br />
* Configures the hardware clock<br />
* Empties the {{Filename|/proc/sys/kernel/hotplug}} file<br />
* Starts [[udev]] and checks for udev events <br />
* Starts the [[loopback]] interface<br />
* Loads modules from the {{Codeline|MODULES}} array defined in [[rc.conf]]<br />
* Configures RAID and encrypted filesystem mappings<br />
* Runs a forced check of partitions ([[fsck]]) if the [[fstab|/etc/fstab]] file contains instructions to do so<br />
* Mounts local partitions and swap (networked drives are not mounted before a network profile is up)<br />
* Activates [[swap]] areas<br />
* Sets the hostname, locale and system clock as defined in {{Filename|rc.conf}}<br />
* Removes various leftover/temporary files, such as {{Filename|/tmp/*}}<br />
* Configures the [[locale]], console and keyboard mappings<br />
* Sets the console font<br />
* Writes output from dmesg to {{Filename|/var/log/dmesg.log}}<br />
<br />
{{Filename|/etc/rc.sysinit}} is a script and not a place for settings. It sources (i.e. reads and inherits variables and functions) [[rc.conf]] for settings and {{Filename|/etc/rc.d/functions}} for the functions that produce its graphical output (nice colors, alignments, switching 'busy' to 'done', etc.) There is no particular need to edit this file, although some may wish to do so in order to speed up the boot process.<br />
<br />
=== {{Filename|/etc/rc.single}} ===<br />
Single-user mode will boot straight into the root user account and should only be used if one cannot boot normally. This script ensures no daemons are running except for the bare minimum: syslog-ng and udev. The single-user mode is useful for system recovery where preventing remote users from doing anything that might cause data loss or damage is necessary. In single-user mode, users can continue with the standard (multi-user) boot by entering 'exit' at the prompt.<br />
<br />
=== {{Filename|/etc/rc.multi}} ===<br />
{{Filename|/etc/rc.multi}} is run on any multi-user runlevel (i.e. 2, 3. 4 and 5) which basically means any ordinary boot. Typically, users will not notice the transition from {{Filename|rc.sysinit}} to {{Filename|rc.multi}} as {{Filename|rc.multi}} also uses the functions file to produce output. This script has three tasks:<br />
<br />
* First, it runs sysctl (to modify kernel parameters at runtime) which applies the settings in {{Filename|/etc/sysctl.conf}}. Arch has very few of these by default; mainly networking settings.<br />
* Secondly, and most importantly, it starts [[daemons]], as per the {{Codeline|DAEMONS}} array in {{Filename|rc.conf}}.<br />
* Finally, it will run {{Filename|/etc/rc.local}}. <br />
<br />
=== {{Filename|/etc/rc.local}} ===<br />
{{Filename|rc.local}} is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing<br />
the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to {{Filename|rc.local}} is not already residing in {{Filename|/etc/profile.d}}, or any other existing configuration location instead.<br />
<br />
When editing this file, keep in mind that it is run '''after''' the basic setup (modules/daemons), as the '''root''' user, and '''whether or not''' X starts. Here is an example which just un-mutes the ALSA sound settings:<br />
<br />
{{File<br />
|name=/etc/rc.local<br />
|content=<nowiki><br />
#!/bin/bash<br />
<br />
# /etc/rc.local: Local multi-user startup script.<br />
<br />
amixer sset 'Master Mono' 50% unmute &> /dev/null<br />
amixer sset 'Master' 50% unmute &> /dev/null<br />
amixer sset 'PCM' 75% unmute &> /dev/null<br />
</nowiki>}}<br />
<br />
Another common usage for {{Filename|rc.local}} is to apply various hacks when one cannot make the ordinary initialization work correctly.<br />
<br />
== init: Login ==<br />
By default, after the Arch boot scripts are completed, the {{Codeline|agetty}} program prompts users for a login name. After a login name is received, {{Codeline|agetty}} calls {{Codeline|login}} to prompt for the login password.<br />
<br />
Finally, with a successful login, the {{Codeline|login}} program starts the user's default shell. The default shell and environment variables may be globally defined within {{Filename|/etc/profile}}. All variables within a user's home directory shall take precedence over those globally defined under {{Filename|/etc}}. For instance, if two conflicting variables are specified within {{Filename|/etc/profile}} and {{Filename|~/.bashrc}}, the one dictated by {{Filename|~/.bashrc}} shall prevail.<br />
<br />
Other options include [[Automatic login to virtual console|mingetty]] which allows for auto-login and [[rungetty]] which allows for auto-login and automatically running commands and programs, e.g. the always useful htop. <br />
<br />
The majority of users wishing to start an [[X]] server during the boot process will want to install a display manager, and see [[Display Manager]] for details. Alternatively, [[Start X at Boot]] outlines methods that do not involve a display manager.<br />
<br />
== See also ==<br />
<br />
* [[Startup files]]<br />
<br />
== External resources ==<br />
* [http://www.cyberciti.biz/faq/grub-boot-into-single-user-mode/ Boot Linux Grub Into Single User Mode]<br />
* [http://www.linuxjournal.com/article/4622 Boot with GRUB]<br />
* [http://www.ibm.com/developerworks/linux/library/l-linuxboot/ Inside the Linux boot process]<br />
* [http://linux.about.com/library/cmd/blcmdl5_sysctl.conf.htm Linux / Unix Command: sysctl.conf]<br />
* [http://bbs.archlinux.org/search.php?action=search&keywords=rc.local&search_in=topic&sort_dir=DESC&show_as=topics Search the forum for rc.local examples]<br />
* [[Wikipedia:Linux startup process]]<br />
* [[Wikipedia:initrd]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=105686Arch 文章命名规则 (简体中文)2010-05-05T09:20:49Z<p>Athurg: </p>
<hr />
<div>[[Category:简体中文]]<br />
[[Category:ArchWiki帮助 (简体中文)]]<br />
{{i18n|Article Naming Guidelines}}<br />
<br />
:目前简体中文版ArchWiki的文章命名主要是这样的,在此作简短描述:<br />
:2010-01-01,在经过[http://wiki.archlinux.org/index.php/Special:Contributions/Gen2ly Gen2ly]的大量整理后,所有文章标题被改名成:<br />
:'''English title''' 的标题添加 '''_(简体中文)''' 后缀,如本文的:'''Article Naming Guidelines (简体中文)'''<br />
<br />
{{Warning|'''广大非英文世界强烈抗议此种英文中心主义行为'''}}<br />
<br />
:目前推荐的做法还是(除保留arch外,把所有英文的文章名全部翻译,arch如有较好翻译,也可以换成中文。):<br />
'''Arch+文章名+(语言名)'''<br />
<br />
:同时请给文章添加'''简体中文'''分类,以方便管理与检索,完毕!<br />
<br />
:''对wiki的编辑者来说,文章命名是最重要的任务中的一项''<br />
<br />
:''这篇文章是一个命名的指导,也是现有ArchWiki的作者和编辑者为他们文章命名时的参考''<br />
<br />
<br />
:NOTE By Athurg<br />
我个人的建议,文章的命名规则可以采用这样的原则:<br />
* 所有文章创建时(包括某文章到原版本,及其翻译版本)均应该以其所属语言命名;<br />
* 原创版本创建时,作者应设立一个英文标题,并且以该标题为模板,创建'''英文标题_(语言)'''的各语种版本文章,并重定向到原创版本。<br />
* 翻译版本创建时,可以自由按照所属语言命名,并修改该文的'''英文标题_(翻译语言)'''链接到本文。<br />
* 所有文章在要链接到其他文章时候,链接目的地统一为'''链接文英文标题_(本文的语言)'''。<br />
举个例子来说,由两篇文章”文章甲“、”文章乙“。其中,文章乙中会链接到文章甲。我们怎么做呢?<br />
# 以''文章甲''为标题,创建这篇文章。并给本文起一个英文名''Article A''<br />
# 创建''Article A_(zh_CN)''、''Article A_(en)''、''Article A_(spalish)''……,并且把这些文章都重定向到''文章甲''<br />
# 我来翻译文章甲的西班牙版本,并以西班牙语命名为'''xxxxxx''(原谅我不懂西班牙语)。然后修改''Article A_(spanlish)'',将其重定向到'''xxxxxx'''<br />
# 其他翻译版本依此类推<br />
这样,文章甲就搞定了。中文用户可以直接访问'''文章甲'''。其他用户只需要访问'''Article A_(lang)''',如果该语言版本存在,则会自动跳转到该语言版本。如果不存在,则会跳转到原文。<br />
<br />
我们再来看看文章乙,文章乙的创建和甲一样,这里不多言。我只说说文章乙在需要链接到文章甲的时候,如何处理。<br />
<br />
通常,我们会以下面这种方式链接<br />
[[文章甲]]<br />
现在,我们改成下面这种方式:<br />
[[Article A_(lang)]]<br />
什么意思呢?以前,我们链接的时候,都是直接链接到原文。现在,我们将链接到以原文所使用的英文名为模板,本文所使用的语言为后缀的地方。即使——'''原文英文名_(本文所用语言)'''。<br />
<br />
这样有一个好处,就是浏览者在浏览本文的时候,跳转链接的文章,也自动跳转到同一语言。如果链接文章的这个语言版本不存在,则上文所述的创建过程,这篇文章会重定向到原文。<br />
<br />
== 关于文章名称 ==<br />
<br />
文章名字有两个作用. 它们是ArchWiki站点上文章的标识符,同时它们也能让读者知道文章的内容. 也就是说一个文章的标题必须是独一无二而又具有描述性的.<br />
<br />
有时,文章标题反映出文章的''类型'', 也有时提供出额外的信息,如文章编辑的语言.<br />
<br />
== 描述性的名称 ==<br />
<br />
'''名称要尽可能的详细精确,并且反映出文章所描述的范围'''<br />
<br />
Wiki文档与大家从报纸或者网站上看到的软硬件评测不同,大家一般在出现某些问题的时候,或者有某些特定需求的时候才来查阅Wiki文档.所以,迅速的定位这些需求然后提供快速的解决方案是第一重要的.为便于提高可读性,使读者能够快速的获得想要的信息,文章的名字(或者说它们的标题)必须在文章范围要求下尽可能的详细和明确<br />
<br />
=== 例子 ===<br />
<br />
类似《Boost Pacman》的名称可能会让大多数读者误解. 某些读者可能看成boos Pacman的某些方面(Boos在英文中是嘘某人,喝倒彩的意思),但是这些方面并不是作者描述的.名称必须详细精确,但为了便于检视,也不要太长. 例如这篇'''[[Boost Pacman|示例文章]]'''就应该改成类似《[[Improve Pacman Performance]]》(《[[Improve Pacman Performance (简体中文)|改善Pacman性能]]》).<br />
<br />
== 允许的对名称增强 ==<br />
<br />
'''名称必须比较全面,以方便以后对文章内容的扩展'''<br />
<br />
为了给以后编辑和增补预留空间,文章的名字有的时候需要故意不那么精确.当然为了缩短标题长度而缩短标题长度不是个好主意.另一方便,如果你觉的你的文章涵盖了所有想要描述的方面,并且未来没有增补文章''范围''的需求,那么就让文章标题越精确越好.<br />
<br />
=== 例子 ===<br />
<br />
让我们举一个新例子.有一篇文章标题是《[[在启动时自动启动一个登录管理器(KDM, GDM, or XDM)]]》。然而将来可能有新的DM取代KDM,GDM,XDM。所以这篇文章需要一个范围更大的标题,例如《[[自动启动登录管理器_(简体中文)|自动启动登录管理器]]》。<br />
<br />
== 简短的名称 ==<br />
<br />
'''名称必须精简'''<br />
<br />
为了让读者能够尽量快速的检视文章列表,一个简短的文章标题是重要的。很多读者使用扫视来阅读Wiki,所以你大概不想写一个几千米长的标题。同时简短的标题看起来更加专业。<br />
<br />
=== 例子 ===<br />
<br />
我们将会在[[Writing Short Article Names|这篇文章]]中展示如何精简文章标题的长度。<br />
<br />
== 文章类型的后缀 (推荐) ==<br />
<br />
'''名称必须有一个类型后缀'''<br />
<br />
'''注意:''' 这只是一个建议, 并不是规则. 你可以考虑使用, 但不一定必须遵循.<br />
<br />
尽管文章的类型并不是十分重要,但是文章类型对于那些只是想要找到一个快速的解决方案,而不是全面的教程的读者来说类型还是很有帮助的。例如HOWTOS的内容一般是简短的,Step-by-step的对简单任务的指导。而教程的内容一般包括完成很多相关任务的全面指导。<br />
<br />
为了让读者了解一共有哪些文章类型,ArchWiki 有下面两个已经排好序的页面 [[:Category:按主题索引页面_(简体中文)|按主题索引页面_(简体中文)]] 和 [[:Category:按类型索引页面(简体中文)|按类型索引页面(简体中文)]].如果你浏览后一个页面,你将会看到所有ArchWiki支持的文章类型.<br />
<br />
用下面表格作为能用作文章类型的后缀的参考.<br />
<br />
{| cellspacing="0" cellpadding="4" rules="all" style="margin:1em 1em 1em 0; border-style:solid; border-width:1px; border-collapse:collapse; empty-cells:show"<br />
|-<br />
! 文章类型 || 后缀(使用斜体) || 文章类型描述<br />
|-<br />
| HOWTO || 文章标题 ''HOWTO'' || 简短的,一步一步的对单个任务的指导.<br />
|-<br />
| Tutorial || 文章标题 ''tutorial'' || 较长的,全面的对完成一系列相关任务的指导.<br />
|-<br />
| FAQ || 文章标题 ''FAQ'' || 一问一答形式的文章,文章长短不一.<br />
|-<br />
| General || (no suffix) || 一般意义的文章,不包括任何任务,过程或者指导.<br />
|-<br />
| Guideline || 文章标题 ''guideline'' || 关于社区行为标准的文章,或者包含一个或者一系列的任务.<br />
|-<br />
| Book || 文章标题 ''book'' || 多个相关教程的文章容器<br />
|}<br />
<br />
'''慎重:''' 文章名称的后缀需要适应大多数情况. 如果你决定使用这个, 需要考虑文章名称时候适应后缀.<br />
<br />
== 多语言文章 ==<br />
<br />
更多关于多语言文章命名的规则,请参考[[文章命名规范]]<br />
<br />
'''名称需要有一个标识'''<br />
<br />
要知道,不是只有英文用户阅读ArchWiki. 文章也需要在名称后面加上''语言标识''. 到写这文章为止,还不能自动完成这工作。<br />
<br />
一个语言标识就是在文章名称后面加上 "_(语言)"(把''语言'' 题换成适当的语言). 每篇文章都需要有"_(语言)"这样的语言标识加在名称的后面.<br />
<br />
'''注意:''' 通常, 绝大多数ArchWiki文章没有语言标识,因为英文文章被认为是后来被翻译成别的语言文章的''基础''文章. 这一点有希望改变, 所以上述规则仍然有效.<br />
<br />
=== 例子 ===<br />
<br />
举例说明,如果你有一篇文章叫做[[Pacman|Pacman (English)]], 你就应该叫中文翻译版本文章为 [[Pacman (简体中文)]], 而塞尔维亚版本叫 [[Pacman (српски)]].<br />
<br />
== 注意事项 ==<br />
<br />
这个指南是个有效的版本, 但是这里的规则任何时候都可能更改. 所以你可能希望对这篇文章作标记,通过文章下方的"Watch this page/监视"链接,然后通过导航栏上右边"My watchlist/我的监视列表"来关注本文的变化.</div>Athurghttps://wiki.archlinux.org/index.php?title=NFSv3_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=105685NFSv3 (简体中文)2010-05-05T08:46:12Z<p>Athurg: </p>
<hr />
<div>[[Category:网络]]<br />
[[Category:HOWTOs (简体中文)]]<br />
[[Category:简体中文]]<br />
{{i18n|NFS}}<br />
{{Translateme}}<br />
<br />
==目标==<br />
这篇文档的目的是建立一个通过网络共享文件的nfs服务器。我们将尽可能的使其简单,容易理解。<br />
'''备注: 查看更多关于 [[NFSv4]] 的信息'''<br />
<br />
==必须的软件包==<br />
服务器端和客户端所需要的软件包都是很少的。<br><br />
你只需要安装:<br />
*core/portmap<br />
*core/nfs-utils<br />
这两个软件包都在 [core] repository 中, 新的Arch会默认包含他们。<br />
<br />
==安装服务器端==<br />
现在你可以编辑配置文件(configuration),启动守护进程。需要以root身份运行以下命令。<br />
<br />
<br />
===文件===<br />
====/etc/exports====<br />
这个文件(/ect/exports)定义了服务器端不同的共享,及其权限。<br><br />
A few examples:<br />
<pre><br />
/files *(ro,sync) ; Read-only access to anyone<br />
/files 192.168.0.100(rw,sync) ; Read-write access to a client on 192.168.0.100<br />
/files 192.168.1.1/24(rw,sync) ; Read-write access to all clients from 192.168.1.1 to 192.168.1.255<br />
</pre><br />
如果你在启动守护进程后修改了 /etc/exports,可以通过以下命令使其立即生效:<br />
<pre><br />
exportfs -r<br />
</pre><br />
<br />
如果希望NFS共享是公开(public)和可写(writable),可和 anonuid 选项,anongid 选项一起使用 all_squash 选项。<br />
例如,给 nobody 组中的用户 nobody 设定优先级,可以:<br />
<pre><br />
; Read-write access to a client on 192.168.0.100, with rw access for the user 99 with gid 99<br />
/files 192.168.0.100(rw,sync,all_squash,anonuid=99,anongid=99))<br />
</pre><br />
<br />
这也意味着,如果想对这个目录拥有写权限,nobody.nobody 必须是共享目录的所有者(owner)。<br />
<pre><br />
chown -R nobody.nobody /files<br />
</pre><br />
<br />
exports 文件的详细信息请参考 exports 的man page。<br />
<br />
====/etc/conf.d/nfs====<br />
编辑这个文件以传递合适(appropriate)的运行选项给 nfsd, mountd, statd, 和 sm-notify。默认的 Arch NFS 初始化脚本(init scripts)要求 --no-notify 参数的 statd 选项,如下:<br />
STATD_OPTS="--no-notify"<br />
其他的选项可采用默认,或者根据需要修改。<br />
详细信息请参考相应的man pages。<br />
<br />
====/etc/hosts.allow====<br />
编辑 /etc/hosts.allow ,允许对nfs 服务器的网络访问。<br><br />
下面的例子对所有人打开这些服务:<br />
<pre><br />
nfsd: ALL<br />
portmap: ALL<br />
mountd:ALL<br />
</pre><br />
这样运行网络访问是非常不安全的(This is a very insecure way of allowing host access)。 To get better control over who is allowed to access the daemons hosts.deny should be everyone, and hosts.allow should specifically allow certain people. In this example, 192.168.0.101 should be the IP address of the person(s) allowed to access it.<br />
<pre><br />
nfsd: 192.168.0.101/255.255.255.0<br />
portmap: 192.168.0.101/255.255.255.0<br />
mountd: 192.168.0.101/255.255.255.0<br />
</pre><br />
希望得到更好的控制,请参看 hosts_access(5) man page.<br />
<br />
===守护进程===<br />
你可以用如下命令开启NFS服务程序:<br />
<pre><br />
/etc/rc.d/portmap start<br />
/etc/rc.d/nfslock start<br />
/etc/rc.d/nfsd start<br />
</pre><br />
请注意,必须按照如上顺序启动.<br><br />
可以将portmap nfslock nfsd 依次加入到/etc/rc.conf的DAEMONS中以使NFS服务程序一开始就启动.<br />
<br />
==设置客户端==<br />
===文件===<br />
====/etc/conf.d/nfs====<br />
Edit this file to pass appropriate run-time options to statd - the remaining options are for server use only. Do NOT use the --no-notify option on the client side, unless you are fully aware of the consequences of doing so.<br />
<br />
Please refer to the statd man page for full details.<br />
<br />
===守护进程===<br />
Start the portmap and nfslock daemons:<br />
/etc/rc.d/portmap start<br />
/etc/rc.d/nfslock start<br />
Please note that they must be started in that order.<br><br />
To start the daemons at boot time, add them to the DAEMONS array in /etc/rc.conf.<br />
<br />
Then just mount as normal:<br />
mount server:/files /files<br />
<br />
===启动时自动挂载===<br />
欲使网络文件夹在启动时自动挂载,须确保netfs在'''/etc/rc.conf'''的'''DAEMONS'''行中,且在'''/etc/fstab''' 中有相应设置,例如:<br />
<br />
server:/files /files nfs defaults 0 0<br />
<br />
如果你要指定读写数据包的大小,可以在fstab中设置。如下所列数据为默认值:<br />
<br />
server:/files /files nfs rsize=32768,wsize=32768 0 0<br />
<br />
'''man nfs''' 以获取更多信息,包括可用的挂载选项等.<br />
<br />
==疑难问题解决==<br />
=== failed to contact local rpcbind server ===<br />
表现在挂载到时候,出现“无法链接到本地rpcbind服务器”,错误号是512。具体错误信息如下:<br />
rpcbind: server localhost not responding, timed out<br />
RPC: failed to contact local rpcbind server (errno 5) .<br />
rpcbind: server localhost not responding, timed out<br />
RPC: failed to contact local rpcbind server (errno 5).<br />
lockd_up: makesock failed, error=-5<br />
^CRPC: failed to contact local rpcbind server (errno 512).<br />
解决方法,在挂载的时候,加上-o nolock 参数即可。<br />
<br />
===Unreliable performance, slow data transfer, and/or high load when using NFS and gigabit===<br />
This is a result of the default packetsize used by NFS, which causes significant fragmentation on gigabit networks. You can modify this behavior by the rsize and wsize mount parameters. Using rsize=32768,wsize=32768 should suffice. Please note that this problem does not occur on 100Mb networks, due to the lower packet transfer speed.<br />
<br />
Note: NFSv4 的默认值是32768。最大可以取65536. Increase from default in increments of 1024 until maximum transfer rate is achieved.<br />
<br />
===Portmap daemon fails to start at boot===<br />
Make sure you place portmap BEFORE netfs in the daemons array in /etc/rc.conf .<br />
<br />
==参考链接==<br />
HOWTO: [[Diskless network boot NFS root]]<br><br />
[http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/nfs_perf.htm Very helpful]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71502Bootchart (简体中文)2009-07-03T11:27:01Z<p>Athurg: /* Generating a chart */</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= 简介 =<br />
<br />
Bootchart是一种很方便的工具,可以用来分析Linux启动流程使系统启动更快。他由bootchartd服务和bootchart-render两部分组成,后者主要负责生成启动流程的分析结果图。<br />
<br />
= 安装Bootchart =<br />
<br />
Bootchart安装非常简单,你只需要以管理员帐户运行下面的命令即可:<br />
# pacman -Sy bootchart<br />
<br />
= 运行Bootchart =<br />
In general, be extra careful with this step.<br />
要使bootchart运行,你需要将他添加到引导器的初始化进程选项,或者手动在init脚本(通常是rc.sysinit)中手动添加。不过需要注意的是,如果你是手动添加到init脚本的,那么也要手动停止它,这种情况需要特别留意!<br />
== 启动引导器设置 ==<br />
下面我们介绍常用的方法,即将原有引导选项复制一份,并在内核项后面添加'init=/sbin/bootchartd',然后通过启动引导器引导bootchart。这样bootchart会在登录提示符出现的时候自动停止。<br />
=== Grub ===<br />
打开/boot/grub/menu.lst, 复制粘贴原有的引导记录,并在kernel行后添加"init=/sbin/bootchartd"。如下例:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Grub 2 ===<br />
打开/boot/grub/grub.cfg,复制原来的引导区域并按照下面的范例修改之:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) 带bootchartd的Arch Linux引导项<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
然后你就可以重启,并选择代bootchart选项的启动项了。<br />
<br />
== rc.sysinit脚本设置 ==<br />
这种方法有一定的危险性(可能导致原有系统无法启动),所以除非前一种方法失败,否则不要用这种方法。采用这种方式,不光是每次都要手动停止bootchart(否则很快就会占满硬件资源),而且每次开机都会运行一次,而且以后每次软件包升级 /etc/rc.sysinit的时候,这些设置都会被覆盖掉。<br />
<br />
另一方面,这种方式是可以让你看到登录后所发生的一些东西的。<br />
=== 编辑/etc/rc.sysinit脚本 ===<br />
先将下面这一行添加到/etc/rc.sysinit<br />
/sbin/bootchartd start<br />
<br />
<br />
这一行不宜太靠前,否则这部分出问题会导致系统无法启动。当然也不宜太靠后,因为他之前的项目都无法观察得到。<br />
<br />
我们推荐把他放在配置系统时钟行的前面。<br />
<br />
找到如下行:<br />
stat_busy "Configuring System Clock"<br />
将下面这一行添加到其前面:<br />
/sbin/bootchartd start<br />
<br />
=== 登录后关闭bootchartd服务===<br />
这种方式一定记住,在登录后停止bootchartd服务。<br />
你可以以管理员帐户执行:<br />
/sbin/bootchartd stop<br />
也可以用sudo通过下面的命令来执行:<br />
sudo /sbin/bootchartd stop<br />
<br />
= 生成分析结果图表 =<br />
你可以通过运行下面的命令来生成分析结果图:<br />
bootchart-render<br />
<br />
确保运行命令的目录有写权限,程序就会生成一个名为'bootchart.png'的图像,这就是分析结果图。<br />
<br />
你需要事先安装Java运行环境并且在此之前设置正确。<br />
== bootcharts用户秀 ==<br />
=== 5秒内启动完成的例子 ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
<br />
= 参考资料 =<br />
* [http://www.bootchart.org/ Bootchart主页]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71501Bootchart (简体中文)2009-07-03T11:23:15Z<p>Athurg: /* Running Bootchart */</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= 简介 =<br />
<br />
Bootchart是一种很方便的工具,可以用来分析Linux启动流程使系统启动更快。他由bootchartd服务和bootchart-render两部分组成,后者主要负责生成启动流程的分析结果图。<br />
<br />
= 安装Bootchart =<br />
<br />
Bootchart安装非常简单,你只需要以管理员帐户运行下面的命令即可:<br />
# pacman -Sy bootchart<br />
<br />
= 运行Bootchart =<br />
In general, be extra careful with this step.<br />
要使bootchart运行,你需要将他添加到引导器的初始化进程选项,或者手动在init脚本(通常是rc.sysinit)中手动添加。不过需要注意的是,如果你是手动添加到init脚本的,那么也要手动停止它,这种情况需要特别留意!<br />
== 启动引导器设置 ==<br />
下面我们介绍常用的方法,即将原有引导选项复制一份,并在内核项后面添加'init=/sbin/bootchartd',然后通过启动引导器引导bootchart。这样bootchart会在登录提示符出现的时候自动停止。<br />
=== Grub ===<br />
打开/boot/grub/menu.lst, 复制粘贴原有的引导记录,并在kernel行后添加"init=/sbin/bootchartd"。如下例:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Grub 2 ===<br />
打开/boot/grub/grub.cfg,复制原来的引导区域并按照下面的范例修改之:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) 带bootchartd的Arch Linux引导项<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
然后你就可以重启,并选择代bootchart选项的启动项了。<br />
<br />
== rc.sysinit脚本设置 ==<br />
这种方法有一定的危险性(可能导致原有系统无法启动),所以除非前一种方法失败,否则不要用这种方法。采用这种方式,不光是每次都要手动停止bootchart(否则很快就会占满硬件资源),而且每次开机都会运行一次,而且以后每次软件包升级 /etc/rc.sysinit的时候,这些设置都会被覆盖掉。<br />
<br />
另一方面,这种方式是可以让你看到登录后所发生的一些东西的。<br />
=== 编辑/etc/rc.sysinit脚本 ===<br />
先将下面这一行添加到/etc/rc.sysinit<br />
/sbin/bootchartd start<br />
<br />
<br />
这一行不宜太靠前,否则这部分出问题会导致系统无法启动。当然也不宜太靠后,因为他之前的项目都无法观察得到。<br />
<br />
我们推荐把他放在配置系统时钟行的前面。<br />
<br />
找到如下行:<br />
stat_busy "Configuring System Clock"<br />
将下面这一行添加到其前面:<br />
/sbin/bootchartd start<br />
<br />
=== 登录后关闭bootchartd服务===<br />
这种方式一定记住,在登录后停止bootchartd服务。<br />
你可以以管理员帐户执行:<br />
/sbin/bootchartd stop<br />
也可以用sudo通过下面的命令来执行:<br />
sudo /sbin/bootchartd stop<br />
<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= 参考资料 =<br />
* [http://www.bootchart.org/ Bootchart主页]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71500Bootchart (简体中文)2009-07-03T11:06:55Z<p>Athurg: /* Installing Bootchart */</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= 简介 =<br />
<br />
Bootchart是一种很方便的工具,可以用来分析Linux启动流程使系统启动更快。他由bootchartd服务和bootchart-render两部分组成,后者主要负责生成启动流程的分析结果图。<br />
<br />
= 安装Bootchart =<br />
<br />
Bootchart安装非常简单,你只需要以管理员帐户运行下面的命令即可:<br />
# pacman -Sy bootchart<br />
<br />
= Running Bootchart =<br />
To make use of bootchart, you have to either set it as the init process in your boot loader or starting it manually from one of the init scripts (rc.sysinit preferrably). Note that if you start bootchartd manually, you have to stop it manually too. In general, be extra careful with this step.<br />
== Boot loader setup ==<br />
This generally involves making a copy of the boot option you want to profile and adding 'init=/sbin/bootchartd' to it. When started from the boot loader, bootchart will stop when you get to the login prompt.<br />
=== Grub ===<br />
Open up /boot/grub/menu.lst, and copy/paste the entry you want to log. Append "init=/sbin/bootchartd" to the kernel line. Generally, you'll want your entry to look something like this:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Lilo ===<br />
TODO<br />
=== Grub 2 ===<br />
Open up /boot/grub/grub.cfg, copy the boot option you want to profile and edit it to look like this:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) Arch Linux with Bootchart<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
Now you can reboot and choose the new bootcharting option.<br />
<br />
== rc.sysinit setup ==<br />
This one is dangerous (you can make your Arch Linux unbootable) - use it only when the first approach fails. When run in this way, not only you'll have to stop bootchartd manually after you boot up (or it will completely fill your harddrive) but it will start with every boot too. Also, any changes to /etc/rc.sysinit will be reverted next time you update the initscripts package.<br />
On the positive side, you'll end up with a bootchart that shows what happens after you log in.<br />
=== Edit /etc/rc.sysinit ===<br />
Now, we're going to add this line:<br />
/sbin/bootchartd start<br />
to /etc/rc.sysinit<br />
<br />
It can't be too high up, because that would render the system unbootable, but placing it too far into the script will hide anything that happened before from the bootchart.<br />
It should be safe to put this right before the section that brings up the system clock.<br />
Look for this line:<br />
stat_busy "Configuring System Clock"<br />
Put this:<br />
/sbin/bootchartd start<br />
before it.<br />
=== Stop bootchartd after login ===<br />
As stated previouslt, you have to stop bootchartd manually.<br />
Either run this as root:<br />
/sbin/bootchartd stop<br />
Or with sudo if you have that set up:<br />
sudo /sbin/bootchartd stop<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= 参考资料 =<br />
* [http://www.bootchart.org/ Bootchart主页]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71499Bootchart (简体中文)2009-07-03T11:06:13Z<p>Athurg: /* Introduction */</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= 简介 =<br />
<br />
Bootchart是一种很方便的工具,可以用来分析Linux启动流程使系统启动更快。他由bootchartd服务和bootchart-render两部分组成,后者主要负责生成启动流程的分析结果图。<br />
<br />
= Installing Bootchart =<br />
<br />
Bootchart can be easily installed by:<br />
# pacman -Sy bootchart<br />
<br />
= Running Bootchart =<br />
To make use of bootchart, you have to either set it as the init process in your boot loader or starting it manually from one of the init scripts (rc.sysinit preferrably). Note that if you start bootchartd manually, you have to stop it manually too. In general, be extra careful with this step.<br />
== Boot loader setup ==<br />
This generally involves making a copy of the boot option you want to profile and adding 'init=/sbin/bootchartd' to it. When started from the boot loader, bootchart will stop when you get to the login prompt.<br />
=== Grub ===<br />
Open up /boot/grub/menu.lst, and copy/paste the entry you want to log. Append "init=/sbin/bootchartd" to the kernel line. Generally, you'll want your entry to look something like this:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Lilo ===<br />
TODO<br />
=== Grub 2 ===<br />
Open up /boot/grub/grub.cfg, copy the boot option you want to profile and edit it to look like this:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) Arch Linux with Bootchart<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
Now you can reboot and choose the new bootcharting option.<br />
<br />
== rc.sysinit setup ==<br />
This one is dangerous (you can make your Arch Linux unbootable) - use it only when the first approach fails. When run in this way, not only you'll have to stop bootchartd manually after you boot up (or it will completely fill your harddrive) but it will start with every boot too. Also, any changes to /etc/rc.sysinit will be reverted next time you update the initscripts package.<br />
On the positive side, you'll end up with a bootchart that shows what happens after you log in.<br />
=== Edit /etc/rc.sysinit ===<br />
Now, we're going to add this line:<br />
/sbin/bootchartd start<br />
to /etc/rc.sysinit<br />
<br />
It can't be too high up, because that would render the system unbootable, but placing it too far into the script will hide anything that happened before from the bootchart.<br />
It should be safe to put this right before the section that brings up the system clock.<br />
Look for this line:<br />
stat_busy "Configuring System Clock"<br />
Put this:<br />
/sbin/bootchartd start<br />
before it.<br />
=== Stop bootchartd after login ===<br />
As stated previouslt, you have to stop bootchartd manually.<br />
Either run this as root:<br />
/sbin/bootchartd stop<br />
Or with sudo if you have that set up:<br />
sudo /sbin/bootchartd stop<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= 参考资料 =<br />
* [http://www.bootchart.org/ Bootchart主页]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71498Bootchart (简体中文)2009-07-03T11:03:00Z<p>Athurg: /* Useful links */</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
<br />
Bootchart is a handy tool used for profiling the Linux boot sequence, generally used for making your computer boot faster. It consists of the bootchartd daemon and bootchart-render, which is used to generate the resulting chart.<br />
<br />
= Installing Bootchart =<br />
<br />
Bootchart can be easily installed by:<br />
# pacman -Sy bootchart<br />
<br />
= Running Bootchart =<br />
To make use of bootchart, you have to either set it as the init process in your boot loader or starting it manually from one of the init scripts (rc.sysinit preferrably). Note that if you start bootchartd manually, you have to stop it manually too. In general, be extra careful with this step.<br />
== Boot loader setup ==<br />
This generally involves making a copy of the boot option you want to profile and adding 'init=/sbin/bootchartd' to it. When started from the boot loader, bootchart will stop when you get to the login prompt.<br />
=== Grub ===<br />
Open up /boot/grub/menu.lst, and copy/paste the entry you want to log. Append "init=/sbin/bootchartd" to the kernel line. Generally, you'll want your entry to look something like this:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Lilo ===<br />
TODO<br />
=== Grub 2 ===<br />
Open up /boot/grub/grub.cfg, copy the boot option you want to profile and edit it to look like this:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) Arch Linux with Bootchart<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
Now you can reboot and choose the new bootcharting option.<br />
<br />
== rc.sysinit setup ==<br />
This one is dangerous (you can make your Arch Linux unbootable) - use it only when the first approach fails. When run in this way, not only you'll have to stop bootchartd manually after you boot up (or it will completely fill your harddrive) but it will start with every boot too. Also, any changes to /etc/rc.sysinit will be reverted next time you update the initscripts package.<br />
On the positive side, you'll end up with a bootchart that shows what happens after you log in.<br />
=== Edit /etc/rc.sysinit ===<br />
Now, we're going to add this line:<br />
/sbin/bootchartd start<br />
to /etc/rc.sysinit<br />
<br />
It can't be too high up, because that would render the system unbootable, but placing it too far into the script will hide anything that happened before from the bootchart.<br />
It should be safe to put this right before the section that brings up the system clock.<br />
Look for this line:<br />
stat_busy "Configuring System Clock"<br />
Put this:<br />
/sbin/bootchartd start<br />
before it.<br />
=== Stop bootchartd after login ===<br />
As stated previouslt, you have to stop bootchartd manually.<br />
Either run this as root:<br />
/sbin/bootchartd stop<br />
Or with sudo if you have that set up:<br />
sudo /sbin/bootchartd stop<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= 参考资料 =<br />
* [http://www.bootchart.org/ Bootchart主页]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=71497Bootchart (简体中文)2009-07-03T11:02:18Z<p>Athurg: Created page with ' {{i18n_links_start}} {{i18n_entry|English|Bootchart}} {{i18n_entry|简体中文|Bootchart (简体中文)}} {{i18n_links_end}} = Introduction = Bootchart is a handy tool use…'</p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
<br />
Bootchart is a handy tool used for profiling the Linux boot sequence, generally used for making your computer boot faster. It consists of the bootchartd daemon and bootchart-render, which is used to generate the resulting chart.<br />
<br />
= Installing Bootchart =<br />
<br />
Bootchart can be easily installed by:<br />
# pacman -Sy bootchart<br />
<br />
= Running Bootchart =<br />
To make use of bootchart, you have to either set it as the init process in your boot loader or starting it manually from one of the init scripts (rc.sysinit preferrably). Note that if you start bootchartd manually, you have to stop it manually too. In general, be extra careful with this step.<br />
== Boot loader setup ==<br />
This generally involves making a copy of the boot option you want to profile and adding 'init=/sbin/bootchartd' to it. When started from the boot loader, bootchart will stop when you get to the login prompt.<br />
=== Grub ===<br />
Open up /boot/grub/menu.lst, and copy/paste the entry you want to log. Append "init=/sbin/bootchartd" to the kernel line. Generally, you'll want your entry to look something like this:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Lilo ===<br />
TODO<br />
=== Grub 2 ===<br />
Open up /boot/grub/grub.cfg, copy the boot option you want to profile and edit it to look like this:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) Arch Linux with Bootchart<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
Now you can reboot and choose the new bootcharting option.<br />
<br />
== rc.sysinit setup ==<br />
This one is dangerous (you can make your Arch Linux unbootable) - use it only when the first approach fails. When run in this way, not only you'll have to stop bootchartd manually after you boot up (or it will completely fill your harddrive) but it will start with every boot too. Also, any changes to /etc/rc.sysinit will be reverted next time you update the initscripts package.<br />
On the positive side, you'll end up with a bootchart that shows what happens after you log in.<br />
=== Edit /etc/rc.sysinit ===<br />
Now, we're going to add this line:<br />
/sbin/bootchartd start<br />
to /etc/rc.sysinit<br />
<br />
It can't be too high up, because that would render the system unbootable, but placing it too far into the script will hide anything that happened before from the bootchart.<br />
It should be safe to put this right before the section that brings up the system clock.<br />
Look for this line:<br />
stat_busy "Configuring System Clock"<br />
Put this:<br />
/sbin/bootchartd start<br />
before it.<br />
=== Stop bootchartd after login ===<br />
As stated previouslt, you have to stop bootchartd manually.<br />
Either run this as root:<br />
/sbin/bootchartd stop<br />
Or with sudo if you have that set up:<br />
sudo /sbin/bootchartd stop<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= Useful links =<br />
* [http://www.bootchart.org/ Bootchart home page]</div>Athurghttps://wiki.archlinux.org/index.php?title=Bootchart&diff=71496Bootchart2009-07-03T11:02:06Z<p>Athurg: </p>
<hr />
<div> {{i18n_links_start}}<br />
{{i18n_entry|English|Bootchart}}<br />
{{i18n_entry|简体中文|Bootchart (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
<br />
Bootchart is a handy tool used for profiling the Linux boot sequence, generally used for making your computer boot faster. It consists of the bootchartd daemon and bootchart-render, which is used to generate the resulting chart.<br />
<br />
= Installing Bootchart =<br />
<br />
Bootchart can be easily installed by:<br />
# pacman -Sy bootchart<br />
<br />
= Running Bootchart =<br />
To make use of bootchart, you have to either set it as the init process in your boot loader or starting it manually from one of the init scripts (rc.sysinit preferrably). Note that if you start bootchartd manually, you have to stop it manually too. In general, be extra careful with this step.<br />
== Boot loader setup ==<br />
This generally involves making a copy of the boot option you want to profile and adding 'init=/sbin/bootchartd' to it. When started from the boot loader, bootchart will stop when you get to the login prompt.<br />
=== Grub ===<br />
Open up /boot/grub/menu.lst, and copy/paste the entry you want to log. Append "init=/sbin/bootchartd" to the kernel line. Generally, you'll want your entry to look something like this:<br />
<br />
# (1) Arch Linux Bootchart<br />
title Arch Linux<br />
root (hd0,0)<br />
kernel /vmlinuz26 root=/dev/disk/by-uuid/d531ff5b-de65-499a-9942-d18682375163 ro vga=37C init=/sbin/bootchartd<br />
initrd /kernel26.img<br />
<br />
=== Lilo ===<br />
TODO<br />
=== Grub 2 ===<br />
Open up /boot/grub/grub.cfg, copy the boot option you want to profile and edit it to look like this:<br />
<br />
# (0) Arch Linux<br />
menuentry "Arch Linux" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro<br />
initrd /boot/kernel26.img<br />
}<br />
# (1) Arch Linux with Bootchart<br />
menuentry "Arch Linux with Bootchart" {<br />
set root=(hd0,1)<br />
linux /boot/vmlinuz26 root=/dev/sda1 ro init=/sbin/bootchartd<br />
initrd /boot/kernel26.img<br />
}<br />
<br />
Now you can reboot and choose the new bootcharting option.<br />
<br />
== rc.sysinit setup ==<br />
This one is dangerous (you can make your Arch Linux unbootable) - use it only when the first approach fails. When run in this way, not only you'll have to stop bootchartd manually after you boot up (or it will completely fill your harddrive) but it will start with every boot too. Also, any changes to /etc/rc.sysinit will be reverted next time you update the initscripts package.<br />
On the positive side, you'll end up with a bootchart that shows what happens after you log in.<br />
=== Edit /etc/rc.sysinit ===<br />
Now, we're going to add this line:<br />
/sbin/bootchartd start<br />
to /etc/rc.sysinit<br />
<br />
It can't be too high up, because that would render the system unbootable, but placing it too far into the script will hide anything that happened before from the bootchart.<br />
It should be safe to put this right before the section that brings up the system clock.<br />
Look for this line:<br />
stat_busy "Configuring System Clock"<br />
Put this:<br />
/sbin/bootchartd start<br />
before it.<br />
=== Stop bootchartd after login ===<br />
As stated previouslt, you have to stop bootchartd manually.<br />
Either run this as root:<br />
/sbin/bootchartd stop<br />
Or with sudo if you have that set up:<br />
sudo /sbin/bootchartd stop<br />
= Generating a chart =<br />
Generating a bootchart involves running:<br />
bootchart-render<br />
<br />
in a folder to which you have write access. This will generate a 'bootchart.png' image with your chart.<br />
You'll have to have a Java runtime installed and properly set up before you can do this.<br />
== Example bootcharts ==<br />
=== Boot in 5 seconds ===<br />
[http://lwn.net/Articles/299483/ LWN Article on fast booting netbooks]<br />
<br />
This article is really awesome and along with a bunch of bootcharts provides some tips on how to boot faster. Some of those improvements are beyond reach of the ordinary user though (patching X.org, kernel, etc.).<br />
=== A fast system getting even faster ===<br />
These bootcharts are from a system with proprietary NVidia drivers and KDE 4.2. It acts as a print server for everyone in the house and is set up to play music on boot using mpd.<br />
<br />
* [http://www.progarden.cz/bootchart.png Bootchart - 'almost' stock Arch]<br />
<br />
Sevices start mostly in sequence, the kernel isn't tweaked in any way and there are no changes to the initscripts.<br />
<br />
* [http://www.progarden.cz/bootchart2.png Bootchart - further optimizations]<br />
<br />
Services now start in parallel - netfs, network have been combined into a single script that also starts the music player daemon. KDM starts sooner, so less of the bootchart is visible.<br />
<br />
* [http://www.progarden.cz/bootchart-ssd.png Bootchart - system migrated to SSD drive]<br />
Bootchartd is started from rc.sysinit, because the bootloader approach failed (bootchartd doesn't have enough time to initialize).<br />
<br />
As you can see, there are hardly any latencies from HDD seek operations. The whole boot process is CPU-bound and is slowed down by poor nvidia drivers which can't properly accelerate 2D operations - KDE apps fight for the CPU. At the 4 second mark, the base system is ready for use in CLI. At ~10 seconds, mpd starts playing music from a samba share.<br />
System daemons - syslog-ng, dethnet, kdm, cups, hal and preload start in parallel. This is not exactly ideal, because preload and kdm/X use the SSD at the same time. A waiting state between preload and KDM could save an another second or two (maybe).<br />
KDM is set up to autologin and lock the session automatically. This starts the 'vermiculate' screensaver, which acts as a login window and hides the apps starting in background. The big red bar is when the login dialog appears.<br />
<br />
Obviously, KDE isn't optimized at all. There's over-use of CPU resources and applications don't start in parallel.<br />
----<br />
Add yours here :)<br />
= Useful links =<br />
* [http://www.bootchart.org/ Bootchart home page]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=70327Arch 文章命名规则 (简体中文)2009-06-11T09:44:52Z<p>Athurg: /* 多语言文章 */</p>
<hr />
<div>[[Category:简体中文]]<br />
[[Category:ArchWiki帮助 (简体中文)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|Article naming guideline (English)}}<br />
{{i18n_entry|简体中文|Article naming guideline 文章命名规则(简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
:''对wiki的编辑者来说,文章命名是最重要的任务中的一项''<br />
<br />
:''这篇文章是一个命名的指导,也是现有ArchWiki的作者和编辑者为他们文章命名时的参考''<br />
<br />
== 关于文章名称 ==<br />
<br />
文章名字有两个作用. 它们是ArchWiki站点上文章的标识符,同时它们也能让读者知道文章的内容. 也就是说一个文章的标题必须是独一无二而又具有描述性的.<br />
<br />
有时,文章标题反映出文章的''类型'', 也有时提供出额外的信息,如文章编辑的语言.<br />
<br />
== 描述性的名称 ==<br />
<br />
'''名称要尽可能的详细精确,并且反映出文章所描述的范围'''<br />
<br />
Wiki文档与大家从报纸或者网站上看到的软硬件评测不同,大家一般在出现某些问题的时候,或者有某些特定需求的时候才来查阅Wiki文档.所以,迅速的定位这些需求然后提供快速的解决方案是第一重要的.为便于提高可读性,使读者能够快速的获得想要的信息,文章的名字(或者说它们的标题)必须在文章范围要求下尽可能的详细和明确<br />
<br />
=== 例子 ===<br />
<br />
类似《Boost Pacman》的名称可能会让大多数读者误解. 某些读者可能看成boos Pacman的某些方面(Boos在英文中是嘘某人,喝倒彩的意思),但是这些方面并不是作者描述的.名称必须详细精确,但为了便于检视,也不要太长. 例如这篇 [[Boost Pacman|示例文章]] 就应该改成类似 《How to improve pacman download speed using wget, snarf, and lftp》(《如何用wget, snarf 和 lftp 提高 Pacman 下载的速度》).<br />
<br />
== 允许的对名称增强 ==<br />
<br />
'''名称必须比较全面,以方便以后对文章内容的扩展'''<br />
<br />
为了给以后编辑和增补预留空间,文章的名字有的时候需要故意不那么精确.当然为了缩短标题长度而缩短标题长度不是个好主意.另一方便,如果你觉的你的文章涵盖了所有想要描述的方面,并且未来没有增补文章''范围''的需求,那么就让文章标题越精确越好.<br />
<br />
=== 例子 ===<br />
<br />
让我们还是举上一个例子.新的文章标题是《如何用wget, snarf 和 lftp 提高 Pacman 下载的速度》。然而将来可能有新的下载工具取代wget,snarf,lftp。所以这篇文章需要一个外延更为广泛的标题,例如《如何利用下载工具提高Pacman下载速度》。<br />
<br />
== 简短的名称 ==<br />
<br />
'''名称必须精简'''<br />
<br />
为了让读者能够尽量快速的检视文章列表,一个简短的文章标题是重要的。很多读者使用扫视来阅读Wiki,所以你大概不想写一个几千米长的标题。同时简短的标题看起来更加专业。<br />
<br />
=== 例子 ===<br />
<br />
我们还是用刚才提到的,拥有一个长标题的例子来说明(《如何利用下载工具提高Pacman下载速度》)。我们将会在这篇文章[[Short article names HOWTO|separate article]]中展示如何精简文章标题的长度。<br />
<br />
== 文章类型的后缀 (推荐) ==<br />
<br />
'''名称必须有一个类型后缀'''<br />
<br />
'''注意:''' 这只是一个建议, 并不是规则. 你可以考虑使用, 但不一定必须遵循.<br />
<br />
尽管文章的类型并不是十分重要,但是文章类型对于那些只是想要找到一个快速的解决方案,而不是全面的教程的读者来说类型还是很有帮助的。例如HOWTOS的内容一般是简短的,Step-by-step的对简单任务的指导。而教程的内容一般包括完成很多相关任务的全面指导。<br />
<br />
为了让读者了解一共有哪些文章类型,ArchWiki 有下面两个已经排好序的页面 [[:Category:按主题索引页面_(简体中文)|按主题索引页面_(简体中文)]] 和 [[:Category:按类型索引页面(简体中文)|按类型索引页面(简体中文)]].如果你浏览后一个页面,你将会看到所有ArchWiki支持的文章类型.<br />
<br />
用下面表格作为能用作文章类型的后缀的参考.<br />
<br />
{| cellspacing="0" cellpadding="4" rules="all" style="margin:1em 1em 1em 0; border-style:solid; border-width:1px; border-collapse:collapse; empty-cells:show"<br />
|-<br />
! 文章类型 || 后缀(使用斜体) || 文章类型描述<br />
|-<br />
| HOWTO || 文章标题 ''HOWTO'' || 简短的,一步一步的对单个任务的指导.<br />
|-<br />
| Tutorial || 文章标题 ''tutorial'' || 较长的,全面的对完成一系列相关任务的指导.<br />
|-<br />
| FAQ || 文章标题 ''FAQ'' || 一问一答形式的文章,文章长短不一.<br />
|-<br />
| General || (no suffix) || 一般意义的文章,不包括任何任务,过程或者指导.<br />
|-<br />
| Guideline || 文章标题 ''guideline'' || 关于社区行为标准的文章,或者包含一个或者一系列的任务.<br />
|-<br />
| Book || 文章标题 ''book'' || 多个相关教程的文章容器<br />
|}<br />
<br />
'''慎重:''' 文章名称的后缀需要适应大多数情况. 如果你决定使用这个, 需要考虑文章名称时候适应后缀.<br />
<br />
== 多语言文章 ==<br />
<br />
更多关于多语言文章命名的规则,请参考[[文章命名规范]]<br />
<br />
'''名称需要有一个标识'''<br />
<br />
要知道,不是只有英文用户阅读ArchWiki. 文章也需要在名称后面加上''语言标识''. 到写这文章为止,还不能自动完成这工作。<br />
<br />
一个语言标识就是在文章名称后面加上 "_(语言)"(把''语言'' 题换成适当的语言). 每篇文章都需要有"_(语言)"这样的语言标识加在名称的后面.<br />
<br />
'''注意:''' 通常, 绝大多数ArchWiki文章没有语言标识,因为英文文章被认为是后来被翻译成别的语言文章的''基础''文章. 这一点有希望改变, 所以上述规则仍然有效.<br />
<br />
=== 例子 ===<br />
<br />
举例说明,如果你有一篇文章叫做[[Pacman|Pacman (English)]], 你就应该叫中文翻译版本文章为 [[Pacman (简体中文)]], 而塞尔维亚版本叫 [[Pacman (српски)]].<br />
<br />
== 注意事项 ==<br />
<br />
这个指南是个有效的版本, 但是这里的规则任何时候都可能更改. 所以你可能希望对这篇文章作标记,通过文章下方的"Watch this page/监视"链接,然后通过导航栏上右边"My watchlist/我的监视列表"来关注本文的变化.</div>Athurghttps://wiki.archlinux.org/index.php?title=%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&diff=70326文章命名规范2009-06-11T09:41:45Z<p>Athurg: /* 推荐 */</p>
<hr />
<div>我会尽量尝试将本文中的命名规范完善,以适用于任何语言,在本行文字由本人去掉之前,此文仅适用于简体中文文章的命名。<br />
==翻译文章==<br />
这里,我们假设通用语言是英语。如果你所将要翻译的文章已经有符合下面规则的标题了,但是内容是重定向到某个语言的版本(包括英语),那么你就不需要考虑标题命名的问题了,只需要翻译好之后,去掉原文中的重定向指令<nowiki>#redirect [[原始文章标题]]</nowiki>,然后将翻译好的内容放上去即可!<br />
<br />
===原始文章包含英语版本===<br />
如果原始文章是英语原创或者包含英语版本,那么翻译后的文章应该命名为''英语标题_(翻译成的语言)''。即''英语标题''加上下划线''_''再加上引文括号''()'',括号里面填写翻译成的语言。<br />
<br />
比如,我们要翻译维基中的''dbus''这篇文章为简体中文。那么<br />
<br />
英语的标题就是:<br />
hal<br />
翻译的简体中文文章的标题就是:<br />
hal_(简体中文)<br />
<br />
同时,如果合适的话,推荐用本国语言撰写标题,然后将用上面的规则命名的文章重定向到你撰写的标题文章。<br />
<br />
比如,我们要翻译维基中的''kernel compilition''为简体中文,并且我们给他起了个简体中文的标题——“内核编译”,那么我们就可以这样做:<br />
# 新建文章,标题为''kernel compilition_(简体中文)'';<br />
# 信件文章,标题为''内核编译'',然后将翻译后的内容放在这里;<br />
# 将''kernel compilition_(简体中文)''重定向到''内核编译''。方法就是编译''kernel compilition_(简体中文)'',内容如下:<br />
<nowiki>#redirect [[内核编译]]</nowiki><br />
<br />
但是要注意如果有些特定的英语名词没有公认的翻译,就不宜过渡翻译。比如kernel就可以翻译成内核,而pidgin就不宜作翻译。<br />
===原始文章非英语===<br />
如果原始文章为非英语,需要先建立其英语版本。<br />
# 参考原始文章的标题和内容,拟定一个合适的英语标题,然后建立这篇文章。<br />
# 如果你能将原始文章翻译成英语,那么就翻译好后放到新建的这篇文章里。如果不能,就按照上文提到的方法重定向到原始文章。<br />
# 最后按照''原始文章为英语''小节所讲的方法,确定你所适用的语言的标题。<br />
<br />
==原创文章==<br />
首先,非常鼓励大家原创文章!!<br />
<br />
如果你将创建的文章采用英语,那么只需要想一个好的名字就可以了。<br />
如果你不是适用英语创建,那么在写好文章的同时,请给他一个合适的英文标题和本国语言的标题。将所写的内容发布为你本国语言标题的文章里。然后建立''英文标题''和''英文标题_(你所采用的语言)''两篇文章,并且都按照前文所述的方法,重定向到你的本国语言标题文章里。<br />
例如:<br />
我要创建一篇简体中文文章,标题为''如果配置内核'',而且还给他取了一个英文名字叫''kernel configure howto'',那么我就可以这样做:<br />
# 创建文章''如何配置内核'',并添加文章内容;<br />
# 创建文章''kernel configure howto''和''kernel configure howto_(简体中文)''<br />
# 将''kernel configure howto''和''kernel configure howto_(简体中文)''都重定向到''如何配置内核''。<br />
<br />
'''推荐''':如果可以的话,我们推荐你完成上面的步骤后,再创建其他各种语言的版本,并且把他们都重定向到你创建的原始文章。<br />
<br />
==引用文章==<br />
得益于WIKI的强大功能,我们可以在写作的时候方便的引用别的文章。为了便于读者查阅所引用文章,我们有必要将引用的链接指向到自己文章所采用的语言。那么如何做到这一点呢?我们用一个例子来说明:<br />
<br />
假设我们正在撰写或者翻译一篇''简体中文''的文章,里面要引用一篇文章“kernel compilation”,他的英文版本标题为“kernel compilation”(这里看上去是一样的,但如果我们引用的文章没有英语版本,这里可就不一样了。下一个例子中就可以看到这种情况)。那么我们可以用下面的方式来引用:<br />
<nowiki>[[kernel compilation_(简体中文)]]</nowiki><br />
如果''kernel compilation_(简体中文)''这篇文章不存在,那么请在完成你的文章后,按照上文所说的方法,手动编辑这篇文章使他指向该文章的英文版''kernel compilation''。<br />
<br />
再举个例子:<br />
假设我们正在撰写或者翻译一篇''简体中文''的文章,里面要引用一篇文章“內核編譯”,他的英文版本标题为“kernel compilation”。那么我们就该用下面的方式来引用:<br />
<nowiki>[[kernel compilation_(简体中文)]]</nowiki><br />
如果''kernel compilation_(简体中文)''这篇文章不存在,那么请在完成你的文章后,按照上文所说的方法,手动编辑这篇文章使他指向该文章的英文版''kernel compilation'',或者是原始语言版“內核編譯”。<br />
<br />
==推荐==<br />
# 无论什么时候,在撰写任何文章后,请按照'''英文标题_(其他语言)'''的方式建立起你所知道的各种语言的版本,如果能翻译就翻译,如果不能,就重定向他们到你的原始版本。<br />
# 无论什么时候,推荐你在文章的最后都加上一句<nowiki>[[category:你的语言]]</nowiki>,这样便于和你使用同样语言的人索引你的文章。<br />
# 学会使用使用文章标题的国际化模板,即在你的文章的开头处,加上如下内容:<br />
<nowiki><br />
{{i18n_links_start}}<br />
{{i18n_entry|English|English Title}}<br />
{{i18n_entry|简体中文|English Title (简体中文)}}<br />
{{i18n_entry|Español|English Title (Español)}}<br />
……Other Language<br />
{{i18n_links_end}}<br />
</nowiki><br />
[[category:简体中文]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_Linux_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=70325Arch Linux (简体中文)2009-06-11T09:38:38Z<p>Athurg: </p>
<hr />
<div>[[Category:简体中文]]<br />
[[Category:关于Arch_(简体中文)]]<br />
[[Category:General (简体中文)]]<br />
[[Category:关于Arch (简体中文)]]<br />
<br />
{{Arch Linux i18n Links}}<br />
== Arch Linux 是什么? ==<br />
<br />
Arch Linux 是个 '''针对 i686 优化的 linux 发行版'''。最初灵感源于 Per Lidén 开发的一个非常不错的 CRUX 发行版。<br />
<br />
== 优势 ==<br />
Arch 基本理念是快速、轻巧、弹性与简单。这并非华而不实的行话,他们都是事实。Arch 是为 i686 处理器优化的, 所以可以为你取得更多的cpu cycle(快速)。他相较于 RedHat 或是其他的 Linux 而言是轻巧的, 而且简单的设计使他富有弹性并且可以成为任何你想建立的系统的模型。<br />
<br />
== 特有的包管理 ==<br />
通过可以轻松使用的二进制包系统 - [[pacman]] - 一个命令就让您升级整个系统。Arch 同时也拥有一个类似 ports 的包构建系统(Arch Build System),通过它可以轻松构建软件包。它也是一个命令就可完成同步。哦,是的,您也可以用一个命令重新构建(rebuild)整个系统。所有事情都是在一个非常简单、明了的情况下完成的。<br />
<br />
== 只要最好的 ==<br />
Arch Linux 的使用者和发展者也很有效率的支持维护 current 与 extra 集,让Arch Linux的软件维持在最新的稳定版。<br />
<br />
== 简单是关键 ==<br />
Arch 要达到的目标是简单和轻巧,我已经省去于 linux 系统无用的相关部分,比如 /usr/doc 和 info pages。按我个人经验,这些都是没多大用处的,而且真的需要时,可以从网络上获取等价的信息。Man pages 就足够了...<br />
<br />
== 时髦的工具 ==<br />
Arch Linux 努力采用用户可以使用的更新的特性,比如 Ext3/ReiserFS 和 udev 等。Arch Linux 0.7 (Wombat) 缺省使用 2.6 的 linux 内核,而且支持 XFS/JFS。<br />
<br />
== 进一步了解 ==<br />
Arch 的主页在 http://www.archlinux.org/ ,在那里您可以找到 [http://bbs.archlinux.org 用户论坛]的链接,官方文档,和所有其他 Arch 相关的东西。也可以通过阅读 [[Arch之道]]</div>Athurghttps://wiki.archlinux.org/index.php?title=Arch_Linux_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&diff=70324Arch Linux (简体中文)2009-06-11T09:38:10Z<p>Athurg: </p>
<hr />
<div>[[Category:简体中文]]<br />
[[Category:关于Arch_(简体中文)]]<br />
[[Category:General (简体中文)]]<br />
[[Category:关于Arch (简体中文)]]<br />
<br />
{{Arch Linux i18n Links}}<br />
{{kernel compilation i18n Links}}<br />
== Arch Linux 是什么? ==<br />
<br />
Arch Linux 是个 '''针对 i686 优化的 linux 发行版'''。最初灵感源于 Per Lidén 开发的一个非常不错的 CRUX 发行版。<br />
<br />
== 优势 ==<br />
Arch 基本理念是快速、轻巧、弹性与简单。这并非华而不实的行话,他们都是事实。Arch 是为 i686 处理器优化的, 所以可以为你取得更多的cpu cycle(快速)。他相较于 RedHat 或是其他的 Linux 而言是轻巧的, 而且简单的设计使他富有弹性并且可以成为任何你想建立的系统的模型。<br />
<br />
== 特有的包管理 ==<br />
通过可以轻松使用的二进制包系统 - [[pacman]] - 一个命令就让您升级整个系统。Arch 同时也拥有一个类似 ports 的包构建系统(Arch Build System),通过它可以轻松构建软件包。它也是一个命令就可完成同步。哦,是的,您也可以用一个命令重新构建(rebuild)整个系统。所有事情都是在一个非常简单、明了的情况下完成的。<br />
<br />
== 只要最好的 ==<br />
Arch Linux 的使用者和发展者也很有效率的支持维护 current 与 extra 集,让Arch Linux的软件维持在最新的稳定版。<br />
<br />
== 简单是关键 ==<br />
Arch 要达到的目标是简单和轻巧,我已经省去于 linux 系统无用的相关部分,比如 /usr/doc 和 info pages。按我个人经验,这些都是没多大用处的,而且真的需要时,可以从网络上获取等价的信息。Man pages 就足够了...<br />
<br />
== 时髦的工具 ==<br />
Arch Linux 努力采用用户可以使用的更新的特性,比如 Ext3/ReiserFS 和 udev 等。Arch Linux 0.7 (Wombat) 缺省使用 2.6 的 linux 内核,而且支持 XFS/JFS。<br />
<br />
== 进一步了解 ==<br />
Arch 的主页在 http://www.archlinux.org/ ,在那里您可以找到 [http://bbs.archlinux.org 用户论坛]的链接,官方文档,和所有其他 Arch 相关的东西。也可以通过阅读 [[Arch之道]]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&diff=70323文章命名规范2009-06-11T09:23:50Z<p>Athurg: /* 翻译文章 */</p>
<hr />
<div>我会尽量尝试将本文中的命名规范完善,以适用于任何语言,在本行文字由本人去掉之前,此文仅适用于简体中文文章的命名。<br />
==翻译文章==<br />
这里,我们假设通用语言是英语。如果你所将要翻译的文章已经有符合下面规则的标题了,但是内容是重定向到某个语言的版本(包括英语),那么你就不需要考虑标题命名的问题了,只需要翻译好之后,去掉原文中的重定向指令<nowiki>#redirect [[原始文章标题]]</nowiki>,然后将翻译好的内容放上去即可!<br />
<br />
===原始文章包含英语版本===<br />
如果原始文章是英语原创或者包含英语版本,那么翻译后的文章应该命名为''英语标题_(翻译成的语言)''。即''英语标题''加上下划线''_''再加上引文括号''()'',括号里面填写翻译成的语言。<br />
<br />
比如,我们要翻译维基中的''dbus''这篇文章为简体中文。那么<br />
<br />
英语的标题就是:<br />
hal<br />
翻译的简体中文文章的标题就是:<br />
hal_(简体中文)<br />
<br />
同时,如果合适的话,推荐用本国语言撰写标题,然后将用上面的规则命名的文章重定向到你撰写的标题文章。<br />
<br />
比如,我们要翻译维基中的''kernel compilition''为简体中文,并且我们给他起了个简体中文的标题——“内核编译”,那么我们就可以这样做:<br />
# 新建文章,标题为''kernel compilition_(简体中文)'';<br />
# 信件文章,标题为''内核编译'',然后将翻译后的内容放在这里;<br />
# 将''kernel compilition_(简体中文)''重定向到''内核编译''。方法就是编译''kernel compilition_(简体中文)'',内容如下:<br />
<nowiki>#redirect [[内核编译]]</nowiki><br />
<br />
但是要注意如果有些特定的英语名词没有公认的翻译,就不宜过渡翻译。比如kernel就可以翻译成内核,而pidgin就不宜作翻译。<br />
===原始文章非英语===<br />
如果原始文章为非英语,需要先建立其英语版本。<br />
# 参考原始文章的标题和内容,拟定一个合适的英语标题,然后建立这篇文章。<br />
# 如果你能将原始文章翻译成英语,那么就翻译好后放到新建的这篇文章里。如果不能,就按照上文提到的方法重定向到原始文章。<br />
# 最后按照''原始文章为英语''小节所讲的方法,确定你所适用的语言的标题。<br />
<br />
==原创文章==<br />
首先,非常鼓励大家原创文章!!<br />
<br />
如果你将创建的文章采用英语,那么只需要想一个好的名字就可以了。<br />
如果你不是适用英语创建,那么在写好文章的同时,请给他一个合适的英文标题和本国语言的标题。将所写的内容发布为你本国语言标题的文章里。然后建立''英文标题''和''英文标题_(你所采用的语言)''两篇文章,并且都按照前文所述的方法,重定向到你的本国语言标题文章里。<br />
例如:<br />
我要创建一篇简体中文文章,标题为''如果配置内核'',而且还给他取了一个英文名字叫''kernel configure howto'',那么我就可以这样做:<br />
# 创建文章''如何配置内核'',并添加文章内容;<br />
# 创建文章''kernel configure howto''和''kernel configure howto_(简体中文)''<br />
# 将''kernel configure howto''和''kernel configure howto_(简体中文)''都重定向到''如何配置内核''。<br />
<br />
'''推荐''':如果可以的话,我们推荐你完成上面的步骤后,再创建其他各种语言的版本,并且把他们都重定向到你创建的原始文章。<br />
<br />
==推荐==<br />
<br />
[[category:简体中文]]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&diff=70322文章命名规范2009-06-11T09:21:01Z<p>Athurg: /* 原创文章 */</p>
<hr />
<div>我会尽量尝试将本文中的命名规范完善,以适用于任何语言,在本行文字由本人去掉之前,此文仅适用于简体中文文章的命名。<br />
==翻译文章==<br />
这里,我们假设通用语言是英语。<br />
===原始文章包含英语版本===<br />
如果原始文章是英语原创或者包含英语版本,那么翻译后的文章应该命名为''英语标题_(翻译成的语言)''。即''英语标题''加上下划线''_''再加上引文括号''()'',括号里面填写翻译成的语言。<br />
<br />
比如,我们要翻译维基中的''dbus''这篇文章为简体中文。那么<br />
<br />
英语的标题就是:<br />
hal<br />
翻译的简体中文文章的标题就是:<br />
hal_(简体中文)<br />
<br />
同时,如果合适的话,推荐用本国语言撰写标题,然后将用上面的规则命名的文章重定向到你撰写的标题文章。<br />
<br />
比如,我们要翻译维基中的''kernel compilition''为简体中文,并且我们给他起了个简体中文的标题——“内核编译”,那么我们就可以这样做:<br />
# 新建文章,标题为''kernel compilition_(简体中文)'';<br />
# 信件文章,标题为''内核编译'',然后将翻译后的内容放在这里;<br />
# 将''kernel compilition_(简体中文)''重定向到''内核编译''。方法就是编译''kernel compilition_(简体中文)'',内容如下:<br />
<nowiki>#redirect [[内核编译]]</nowiki><br />
<br />
但是要注意如果有些特定的英语名词没有公认的翻译,就不宜过渡翻译。比如kernel就可以翻译成内核,而pidgin就不宜作翻译。<br />
===原始文章非英语===<br />
如果原始文章为非英语,需要先建立其英语版本。<br />
# 参考原始文章的标题和内容,拟定一个合适的英语标题,然后建立这篇文章。<br />
# 如果你能将原始文章翻译成英语,那么就翻译好后放到新建的这篇文章里。如果不能,就按照上文提到的方法重定向到原始文章。<br />
# 最后按照''原始文章为英语''小节所讲的方法,确定你所适用的语言的标题。<br />
<br />
==原创文章==<br />
首先,非常鼓励大家原创文章!!<br />
<br />
如果你将创建的文章采用英语,那么只需要想一个好的名字就可以了。<br />
如果你不是适用英语创建,那么在写好文章的同时,请给他一个合适的英文标题和本国语言的标题。将所写的内容发布为你本国语言标题的文章里。然后建立''英文标题''和''英文标题_(你所采用的语言)''两篇文章,并且都按照前文所述的方法,重定向到你的本国语言标题文章里。<br />
例如:<br />
我要创建一篇简体中文文章,标题为''如果配置内核'',而且还给他取了一个英文名字叫''kernel configure howto'',那么我就可以这样做:<br />
# 创建文章''如何配置内核'',并添加文章内容;<br />
# 创建文章''kernel configure howto''和''kernel configure howto_(简体中文)''<br />
# 将''kernel configure howto''和''kernel configure howto_(简体中文)''都重定向到''如何配置内核''。<br />
<br />
'''推荐''':如果可以的话,我们推荐你完成上面的步骤后,再创建其他各种语言的版本,并且把他们都重定向到你创建的原始文章。<br />
<br />
==推荐==<br />
<br />
[[category:简体中文]]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&diff=70321文章命名规范2009-06-11T09:11:06Z<p>Athurg: /* 翻译文章 */</p>
<hr />
<div>我会尽量尝试将本文中的命名规范完善,以适用于任何语言,在本行文字由本人去掉之前,此文仅适用于简体中文文章的命名。<br />
==翻译文章==<br />
这里,我们假设通用语言是英语。<br />
===原始文章包含英语版本===<br />
如果原始文章是英语原创或者包含英语版本,那么翻译后的文章应该命名为''英语标题_(翻译成的语言)''。即''英语标题''加上下划线''_''再加上引文括号''()'',括号里面填写翻译成的语言。<br />
<br />
比如,我们要翻译维基中的''dbus''这篇文章为简体中文。那么<br />
<br />
英语的标题就是:<br />
hal<br />
翻译的简体中文文章的标题就是:<br />
hal_(简体中文)<br />
<br />
同时,如果合适的话,推荐用本国语言撰写标题,然后将用上面的规则命名的文章重定向到你撰写的标题文章。<br />
<br />
比如,我们要翻译维基中的''kernel compilition''为简体中文,并且我们给他起了个简体中文的标题——“内核编译”,那么我们就可以这样做:<br />
# 新建文章,标题为''kernel compilition_(简体中文)'';<br />
# 信件文章,标题为''内核编译'',然后将翻译后的内容放在这里;<br />
# 将''kernel compilition_(简体中文)''重定向到''内核编译''。方法就是编译''kernel compilition_(简体中文)'',内容如下:<br />
<nowiki>#redirect [[内核编译]]</nowiki><br />
<br />
但是要注意如果有些特定的英语名词没有公认的翻译,就不宜过渡翻译。比如kernel就可以翻译成内核,而pidgin就不宜作翻译。<br />
===原始文章非英语===<br />
如果原始文章为非英语,需要先建立其英语版本。<br />
# 参考原始文章的标题和内容,拟定一个合适的英语标题,然后建立这篇文章。<br />
# 如果你能将原始文章翻译成英语,那么就翻译好后放到新建的这篇文章里。如果不能,就按照上文提到的方法重定向到原始文章。<br />
# 最后按照''原始文章为英语''小节所讲的方法,确定你所适用的语言的标题。<br />
<br />
==原创文章==<br />
==推荐==<br />
<br />
[[category:简体中文]]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E6%96%87%E7%AB%A0%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&diff=70320文章命名规范2009-06-11T08:47:03Z<p>Athurg: Created page with '==翻译文章== ==原创文章== ==推荐== category:简体中文'</p>
<hr />
<div>==翻译文章==<br />
==原创文章==<br />
==推荐==<br />
<br />
[[category:简体中文]]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8&diff=70319编译内核2009-06-11T08:31:55Z<p>Athurg: /* 使用Arch Build System (ABS) */</p>
<hr />
<div>[[Category:Kernel (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|Kernel Compilation}}<br />
{{i18n_entry|Česky|Kompilace jádra (Česky)}}<br />
{{i18n_entry|简体中文|Kernel Compilation (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
==作个选择==<br />
Arch Linux 提供了多种内核编译的方法。<br />
<br />
===传统方式===<br />
传统方式可能最简单,但是如果要重复编译多次的话,就有点繁琐了。具体可参考: [[Kernel Compilation From Source|传统方式]] '''或''' [[Kernel Compilation From Source For New Users Guide|传统方式(适用于新用户)]]<br />
<br />
采用这种方式,会先手动下载内核源代码包,然后在自己的主目录里以普通用户的权限编译。一旦完成配置之后,两种编译(安装)的方式都行。传统的安装方式和适用makepkg/pacman的差不多。<br />
[[File:Example.jpg]]<br />
<br />
===使用[[ABS_-_The_Arch_Build_System|Arch Build System (ABS)]]===<br />
<br />
有几种用ABS自动编译个性化内核的方式。目前看来还没有哪一种是通用的,你可以根据你自己的需求选择一种。不过需要注意的是,很多中方式都需要修改PKGBUILD脚本,所以在此之前用ABS编译一些包熟悉一下ABS。具体可参考[http://bbs.archlinux.org/viewtopic.php?id=66253 论坛ABS板的这个帖子]<br />
<br />
* 第一种方法,就是使用''/var/abs/core/kernel26''里的文件。官方的内核也是用这些文件编译而来的。不过要注意文件里的内容都是官方标准的,没有经过个性化配置。所以在编译之前你要先自己有针对性的修改一下。<br />
<br />
* 另外,维基中还提到了另外两种方法来使用ABS编译个性化内核:[[从源码编译内核 (简体中文)]] 和 [[从ABS定制内核]]。没一种都有不同的理念,所以请根据自己的情况选择。提醒一下,可能这两篇文章的内容不一定适合最新的内核版本,所以自己要稍微调整一下。<br />
<br />
* 还有一种方法,就是在AUR中搜索用户们提交的他们编译的内核。比如我就用的是[http://aur.archlinux.org/packages.php?ID=23467 kernel26parallel]这个,而且用起来感觉还不错。<br />
<br />
== 参考文献 ==<br />
* [http://www.kroah.com/lkn/ O'Reilly - Linux Kernel in a Nutshell] (自由开源的电子书,包含内核配置、安装和其他的东西)<br />
[http://www.example.com 链接标题]</div>Athurghttps://wiki.archlinux.org/index.php?title=%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8&diff=70318编译内核2009-06-11T08:30:21Z<p>Athurg: /* Choices */</p>
<hr />
<div>[[Category:Kernel (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|Kernel Compilation}}<br />
{{i18n_entry|Česky|Kompilace jádra (Česky)}}<br />
{{i18n_entry|简体中文|Kernel Compilation (简体中文)}}<br />
{{i18n_links_end}}<br />
<br />
==作个选择==<br />
Arch Linux 提供了多种内核编译的方法。<br />
<br />
===传统方式===<br />
传统方式可能最简单,但是如果要重复编译多次的话,就有点繁琐了。具体可参考: [[Kernel Compilation From Source|传统方式]] '''或''' [[Kernel Compilation From Source For New Users Guide|传统方式(适用于新用户)]]<br />
<br />
采用这种方式,会先手动下载内核源代码包,然后在自己的主目录里以普通用户的权限编译。一旦完成配置之后,两种编译(安装)的方式都行。传统的安装方式和适用makepkg/pacman的差不多。<br />
[[File:Example.jpg]]<br />
<br />
===使用[[ABS_-_The_Arch_Build_System|Arch Build System (ABS)]]===<br />
<br />
有几种用ABS自动编译个性化内核的方式。目前看来还没有哪一种是通用的,你可以根据你自己的需求选择一种。不过需要注意的是,很多中方式都需要修改PKGBUILD脚本,所以在此之前用ABS编译一些包熟悉一下ABS。具体可参考[http://bbs.archlinux.org/viewtopic.php?id=66253 论坛ABS板的这个帖子]<br />
<br />
* 第一种方法,就是使用''/var/abs/core/kernel26''里的文件。官方的内核也是用这些文件编译而来的。不过要注意文件里的内容都是官方标准的,没有经过个性化配置。所以在编译之前你要先自己有针对性的修改一下。<br />
<br />
* 另外,维基中还提到了另外两种方法来使用ABS编译个性化内核:[[Kernel_Compilation_with_ABS| Kernel Compilation with ABS]] 和 [[Custom_Kernel_Compilation_with_ABS|Custom Kernel Compilation with ABS]]。没一种都有不同的理念,所以请根据自己的情况选择。提醒一下,可能这两篇文章的内容不一定适合最新的内核版本,所以自己要稍微调整一下。<br />
<br />
* 还有一种方法,就是在AUR中搜索用户们提交的他们编译的内核。比如我就用的是[http://aur.archlinux.org/packages.php?ID=23467 kernel26parallel]这个,而且用起来感觉还不错。<br />
<br />
== 参考文献 ==<br />
* [http://www.kroah.com/lkn/ O'Reilly - Linux Kernel in a Nutshell] (自由开源的电子书,包含内核配置、安装和其他的东西)<br />
[http://www.example.com 链接标题]</div>Athurg