From 5caa9f505de87fc2929cb2d0287c2408062677a3 Mon Sep 17 00:00:00 2001 From: wxy Date: Sat, 24 Jun 2017 21:55:54 +0800 Subject: [PATCH 01/25] PUB:20170314 One Year Using Go.md @geekpi --- published/20170314 One Year Using Go.md | 110 ++++++++++++++++++ translated/talk/20170314 One Year Using Go.md | 110 ------------------ 2 files changed, 110 insertions(+), 110 deletions(-) create mode 100644 published/20170314 One Year Using Go.md delete mode 100644 translated/talk/20170314 One Year Using Go.md diff --git a/published/20170314 One Year Using Go.md b/published/20170314 One Year Using Go.md new file mode 100644 index 0000000000..6ddebb7f76 --- /dev/null +++ b/published/20170314 One Year Using Go.md @@ -0,0 +1,110 @@ +使用 Go 一年的体验 +============================================================ + +![](https://bugfender.com/wp-content/uploads/2017/03/one-year-using-go-social-1.jpg) + +我们公司 [Mobile Jazz][6] 从一个内部试验性项目开始使用 [Go][5]。如公司名暗示的那样,我们是开发移动应用的。 + +在发布一个应用给公众后,我们很快意识到我们缺失一个工具来检查用户实际发生的情况以及他们是如何与应用交互的 - 如果有任何问题或者 bug 的报告,这将会相当方便。 + +现在有几款工具声称能在这个方面帮助开发者,但是没有一个能完全满足要求,因此我们决定自己构建一个。我们开始创建一组基础的脚本,如今它很快进化成了完整的工具,称为 [Bugfender][7]! + +由于这最初是一个实验,我们决定使用一种新的趋势技术。对学习以及持续教育的热爱是 Mobile Jazz 的核心价值的之一,因此我们决定使用 Go 构建。这是一个由 Google 开发的相对较新的编程语言。它是编程世界的的新玩家,已经有许多受尊敬的开发者对它赞不绝口。 + +一年后,这个实验变成了一个初创项目,我们拥有了一个已经帮助了来自全世界的数以千计的开发者的令人难以置信的工具。我们的服务器每天处理来自 700 万台设备的超过 200GB 的数据。 + +在使用 Go 一年之后,我们想要分享我们将一个小小的实验变成处理百万日志的生产服务器的一些想法和经验。 + +### Go 生态系统 + +公司中没有人有使用 Go 的经验。Bugfender 是我们第一次深入这个语言。 + +学习基本上相当直接的。我们之前在 C/C++/Java/Objective-C/PHP 的经验让我们学习 Go 相当快,并且在几天内就开始开发了。当然会有一些新的和不常见的东西需要学习,包括 GOPATH 还有如何处理包,但这在我们的预期之内。 + +几天之内,我们意识到即使是一个以简化为设计目的的语言,Go 也是非常强大的。它能够做任何现代编程语言应该能做的事:能够处理 JSON、服务器之间通讯甚至访问数据库也没问题(并且只需要几行代码)。 + +在构建一个服务器时,你应该首先决定是否使用任何第三方库或者框架。对于 Bugfender,我们决定使用: + +#### Martini + +[Martini][8] 是一个强大的 Go 的 web 框架。我们开始这个实验时,它是一个很棒的解决方案,至今也是,我们还没遇到任何问题。然而如果我们今天再次开始这个实验的话,我们会选择一个不同的框架,因为 Martini 不在维护了。 + +我们还试验了 [Iris][9](我们目前的最爱)还有 [Gin][10]。Gin 是 Martini 继任者,并且迁移到这上能让我们重用已有的代码。 + +在过去的一年中,我们意识到 Go 的标准库是非常强大的,你不必依靠一个臃肿的 web 框架来构建一个服务器。最好在特定任务上使用专门的高性能库。 + +~~Iris 是我们目前最喜欢的,并且将来我们将使用它重写服务来替代 Martini/Gin,但这目前并不是优先的。~~ + +**修改:** 在讨论了 Iris 的各个方面之后,我们意识到 Iris 或许不是最好的选择。如果我们决定重写我们的 web 组件,我们或许会研究其他的选择,我们欢迎你的建议。 + +#### Gorm + +有些人喜欢 ORM,而有些人则不喜欢。我们决定使用 ORM,更确切地说是 [GORM][11]。我们的实现只针对 web 前端,对于日志提取 API 仍然继续使用手工优化的 SQL。在一开始,我们确实很喜欢它,但是随着时间的推移,我们开始发现问题,并且我们很快将它从代码中完全移除,并且使用 [sqlx][12] 这个标准 SQL 库。 + +GORM 的一个主要问题是 Go 的生态系统。作为一个新语言,自我们开始开发产品以来 Go 已经有很多新版本。在这些新版本中的一些改变并不向后兼容,因此要使用最新的库版本,我们要经常重写已有代码并检查我们为解决版本问题所做的 hack。 + +上述这两个库是大多数 web 服务的主要组件,因此做一个好的选择很重要,因为将来更改会很困难,并且会影响你服务器的性能。 + +### 第三方服务 + +在创建一个实际使用的产品的另外一个重要方面是考虑库、第三方服务和工具的可用性。在这方面,Go 还缺乏成熟度,大多数公司还没有提供 Go 库,因此你或许需要依赖其他人写的不能一直保证质量的库。 + +比如,对于使用 [Redis][13] 和 [ElasticSearch][14] 有很好的库,但是对于其他服务比如 Mixpanel 或者 Stripe 还没有好的。 + +我们建议在使用 Go 之前事先检查对于你需要的产品是否有好的库可用。 + +我们在 Go 的包管理系统上也遇到了很多问题。它处理版本的方式远没有达到最好,并且在过去的一年中,我们在不同的团队成员之间使用同一个库的不同版本上遇到了很多问题。然而,最近要归功于 Go 新支持的 vendor 包特性,除了 [gopkg.in][15] 服务外,这个问题基本被解决了。 + +### 开发者工具 + +![](https://bugfender.com/wp-content/uploads/2017/03/go-ide.jpg) + +由于 Go 是一门相对新的语言,你或许发现相比其他成熟的语言像 Java,它可用的开发工具并不很好。当我们开始 Bugfender 时,使用任何 IDE 都很困难,似乎没有 IDE 支持 Go。但是在过去的一年中,随着 [IntelliJ][16] 和 [Visual Studio Code Go][17] 插件的引入,这一切改善了很多。 + +最后看下其他的 Go 工具,调试器并不很好,而分析器甚至更糟,因此有时调试你的代码或者尝试优化它会很困难。 + +### 前往生产 + +这确实是 Go 最好的东西之一,如果你想要部署一些东西到生产环境中,你只需要构建你的二进制并发送到服务器中,没有依赖,不需要安装额外的软件,你只需要能在服务器中运行二进制文件就行。 + +如果你习惯于处理那些需要包管理器或者需要小心你使用的语言解释器的语言,用 Go 工作会感到很高兴。 + +我们对 Go 的稳定性也很满意,因为服务器似乎从没有崩溃过。我们在发送大量数据给 Go Routines 时遇到过一个问题,但是我们几乎没见到任何崩溃。注意:如果你需要发送大量数据给 Go Routine,你需要小心堆溢出。 + +如果你对性能感兴趣,我们没法与其他语言相比较,因为我们从零开始使用 Go,但是对于我们处理的数据量,我们感觉性能是非常好的,我们绝对不能如此轻松地使用 PHP 处理同等数量的请求。 + +### 总结 + +在过去的一年中,我们对 Go 的感觉起起伏伏。最初我们是兴奋的,但是在实验变成真实的产品后我们开始发现问题。我们几次考虑过用 Java 完全重写,但是目前为止,仍旧使用的是 Go,并且过去的一年中, Go 生态已经有了很大的提升,这简化了我们的工作。 + +如果你想要使用 Go 构建你的产品,你可以保证它可以工作,但是你确实需要小心一件事:可以雇佣的开发者。硅谷中只有很少的高级 Go 开发者,并且在其他地方寻找也是一件非常困难的任务。 + +-------------------------------------------------------------------------------- + +via: https://bugfender.com/one-year-using-go + +作者:[ALEIX VENTAYOL][a] +译者:[geekpi](https://github.com/geekpi) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://bugfender.com/author/aleixventayol +[1]:https://bugfender.com/#facebook +[2]:https://bugfender.com/#twitter +[3]:https://bugfender.com/#google_plus +[4]:https://www.addtoany.com/share#url=https%3A%2F%2Fbugfender.com%2Fone-year-using-go&title=One%20Year%20Using%20Go +[5]:https://golang.org/ +[6]:http://mobilejazz.com/ +[7]:https://www.bugfender.com/ +[8]:https://github.com/go-martini/martini +[9]:https://github.com/kataras/iris +[10]:https://github.com/gin-gonic/gin +[11]:https://github.com/jinzhu/gorm +[12]:https://github.com/jmoiron/sqlx +[13]:https://github.com/go-redis/redis +[14]:https://github.com/olivere/elastic +[15]:http://labix.org/gopkg.in +[16]:https://plugins.jetbrains.com/plugin/5047-go +[17]:https://github.com/Microsoft/vscode-go +[18]:https://bugfender.com/one-year-using-go diff --git a/translated/talk/20170314 One Year Using Go.md b/translated/talk/20170314 One Year Using Go.md deleted file mode 100644 index 18e90116e2..0000000000 --- a/translated/talk/20170314 One Year Using Go.md +++ /dev/null @@ -1,110 +0,0 @@ -[Go 使用一周年][18] -============================================================ - - ![](https://bugfender.com/wp-content/uploads/2017/03/one-year-using-go-social-1.jpg) - -我们在 [Mobile Jazz][6] 的一个内部项目开始使用 [Go][5]。如公司名暗示的那样,我们开发移动应用。 - -在发布一个应用给公众后,我们很快意识到我们缺失一个工具来检查用户实际发生的情况以及他们是如何与应用交互的 - 如果有任何问题后者 bug 报告,这将会相当方便。 - -现在有几款工具声称能在这个方面帮助开发者,但是没有一个能完全满足要求,因此我们决定自己构建。我们开始创建一组基础的脚本,如今它很快进化成了完整的工具,称为 [Bugfender][7]! - -由于这最初是一个实验,我们决定使用一种新的趋势技术。对学习以及持续教育的热爱是 Mobile Jazz 的核心价值的重要方面之一,因此我们决定使用 Go 构建。这是一个由 Google 开发的相对新的编程语言。它是游戏中的新玩家,已经有许多受尊敬的开发者对它称赞。 - -一年后,实验变成了一个启动项目,我们拥有了一个已经帮助了来自全世界的数以千计的开发者的令人难以置信的工具。我们的服务器每天处理来自 700 万台设备的超过 200GB 的数据。 - -在使用 Go 一年之后,我们想要分享我们将一个小的实验变成处理百万日志的生产服务器的一些想法和经验。 - -### Go 生态系统 - -公司中没有人有使用 Go 的经验。Bugfender 是我们第一次深入这个语言。 - -学习基本相当直接。我们之前在 C/C++/Java/Objective-C/PHP 的经验让我们学习 Go 相当快,并且在几天内就开始开发。当然会有一些新的还有不常见的东西需要学习,包括 GOPATH 还有如何处理包,但这在预期内。 - -几天之内,我们意识到即使是一个简化设计的语言,Go 是非常强大的。它能够做任何现代编程语言应该能做的事:能够处理 JSON、服务器之间通讯甚至访问数据库也没问题(并且只需要几行代码)。 - -在构建一个服务器时,你应该首先决定是否使用任何第三方库或者框架。对于 Bugfender,我们决定使用: - -### Martini - -[Martini][8] 是一个强大的 Go web 框架。我们开始这个实验时,它是一个很棒的解决方案,至今也是,我们还没遇到任何问题。然而如果我们如今再次开始这个实验,我们会选择一个不同的框架,因为 Martini 不在被维护了。 - -我们还试验了 [Iris][9](我们目前的最爱)还有 [Gin][10]。Gin 是 Martini 继任者,并且迁移到这上能让我们重用已有的代码。 - -在过去的一年中,我们意识到 Go 的标准库是非常强大的,你不必依靠一个臃肿的 web 框架来构建一个服务器。最好在特定任务上使用专门的高性能库。 - -~~Iris 是我们目前 ~~最喜欢的~~ 并且将来我们将使用它重写服务来替代 Martini/Gin,但这目前并不优先。 - -**编辑:** 在不同地方讨论 Iris 之后,我们意识到 Iris 或许不是最好的选择。如果我们决定重写我们的 web 组件,我们或许会研究其他的选择,我们对提议开放。 - -### Gorm - -一些人是 ORM 的粉丝,一些人不是。我们决定使用 ORM,更确切地说是 [GORM][11]。我们的实现只针对 web 前端,对于日志提取 API 仍然保持使用手写优化的 SQL。在一开始,我们确实很高兴,但是随着时间的推移,我们开始发现问题,并且我们很快将它从代码中完全移除,并且使用 [sqlx][12] 这个标准 SQL 库。 - -GORM 的一个主要问题是 Go 的生态系统。作为一个新语言,自我们开始开发产品以来已经有很多新版本。在这些新版本中的一些改变并不向后兼容,因此要使用最新库版本,我们要经常重新已有代码并检查我们为解决版本问题做的 hack。 - -这两个库是大多数 web 服务的主要组件,因此做一个好的选择很重要,因为将来更改会很困难,并且会影响你服务器的性能。 - -### 第三方服务 - -在创建一个真实世界产品的另外一个重要方面是考虑库、第三方服务和工具的可用性。在这方面,Go 还缺乏成熟度,大多数公司还没有提供 Go 库,因此你或许需要依赖其他人写的质量不能总是保证的库。 - -比如,对于使用 [Redis][13] 和 [ElasticSearch][14] 有很好的库,但是对于其他服务比如 Mixpanel 或者 Stripe 还没有好的。 - -我们建议在使用 Go 之前事先检查对于你需要的产品是否有好的库可用。 - -我们在 Go 的包管理系统上也遇到了很多问题。它处理版本的方式远没有达到最好,并且在过去的一年中,我们在不同的团队成员之间获取到同一个库的不同版本上遇到了很多问题。然而,最近要归功于 Go 新支持的 vendor 包特性,除了 [gopkg.in][15] 服务外,这个问题基本被解决了。 - -### 开发者工具 - - ![](https://bugfender.com/wp-content/uploads/2017/03/go-ide.jpg) - -由于 Go 是一门相对新的语言,你或许发现相比其他成熟的语言像 Java,它可用的开发工具并不很好。当我们开始 Bugfender 时,使用任何 IDE 都很困难,似乎没有 IDE 支持 Go。但是在过去的一年中,随着 [IntelliJ][16] 和 [Visual Studio Code Go][17] 插件的引入,这一切提高了很多。 - -最后看下其他的 Go 工具,调试器并不很好并且分析器甚至更糟,因此有时调试你的代码或者尝试优化它会很困难。 - -### 前往生产 - -这确实是 Go 最好的东西之一,如果你想要部署一些东西到生产环境中,你只需要构建你的二进制并发送到服务器中,没有依赖,不需要安装额外的软件,你只需要能在服务器中运行进制文件。 - -如果你习惯于处理那些需要包管理器或者需要小心你使用的语言解释器的语言,用 Go 工作会很高兴。 - -我们对 Go 的稳定性也很满意,因为服务器似乎从没有崩溃过。我们在发送大量数据给 Go Routines 时遇到过一个问题,但是我们几乎没见到任何崩溃。注意:如果你需要发送大量数据给 Go Routine,你需要小心堆溢出。 - -如果你对性能感兴趣,我们不能与其他语言比较,因为我们从零开始使用 Go,但是对于我们处理的数据量,我们感觉性能是非常好的,我们绝对不能如此轻松地使用 PHP 处理同等数量的请求。 - -### 总结 - -在过去的一年中,我们对 Go 有起起伏伏。最初我们是兴奋的,但是在实验变成真实的产品后我们开始揭露问题。我们几次考虑过用 Java 完全重写,但是目前为止,仍旧使用的是 Go,并且过去的一年中,生态已经有了很大的提升,这简化了我们的工作。 - -如果你想要使用 Go 构建你的产品,你可以保证这可以工作,但是你确实需要小心一件事:可以雇佣的开发者。硅谷中只有很少的高级 Go 开发者,并且在其他地方寻找也是一件非常困难的任务。 - --------------------------------------------------------------------------------- - -via: https://bugfender.com/one-year-using-go - -作者:[ALEIX VENTAYOL][a] -译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://bugfender.com/author/aleixventayol -[1]:https://bugfender.com/#facebook -[2]:https://bugfender.com/#twitter -[3]:https://bugfender.com/#google_plus -[4]:https://www.addtoany.com/share#url=https%3A%2F%2Fbugfender.com%2Fone-year-using-go&title=One%20Year%20Using%20Go -[5]:https://golang.org/ -[6]:http://mobilejazz.com/ -[7]:https://www.bugfender.com/ -[8]:https://github.com/go-martini/martini -[9]:https://github.com/kataras/iris -[10]:https://github.com/gin-gonic/gin -[11]:https://github.com/jinzhu/gorm -[12]:https://github.com/jmoiron/sqlx -[13]:https://github.com/go-redis/redis -[14]:https://github.com/olivere/elastic -[15]:http://labix.org/gopkg.in -[16]:https://plugins.jetbrains.com/plugin/5047-go -[17]:https://github.com/Microsoft/vscode-go -[18]:https://bugfender.com/one-year-using-go From 5c1d4d4d3a3181375913a0fe8686b8eaa2dc7841 Mon Sep 17 00:00:00 2001 From: cinlen_0x05 <237448382@qq.com> Date: Sun, 25 Jun 2017 10:01:06 +0800 Subject: [PATCH 02/25] translated (#5726) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 取消翻译,此篇其他平台已经有译文了 * translating by chenxinlong * deleted article removed by origin * translating * translating * keep translating * keep updating * keep updating * keep updating * keep updating * add content * finished translating * move to translated * mv to translated * remove the bullet symbol --- ...introduction to Linux s EXT4 filesystem.md | 302 ------------------ ...introduction to Linux s EXT4 filesystem.md | 301 +++++++++++++++++ 2 files changed, 301 insertions(+), 302 deletions(-) delete mode 100644 sources/tech/20170525 An introduction to Linux s EXT4 filesystem.md create mode 100644 translated/tech/20170525 An introduction to Linux s EXT4 filesystem.md diff --git a/sources/tech/20170525 An introduction to Linux s EXT4 filesystem.md b/sources/tech/20170525 An introduction to Linux s EXT4 filesystem.md deleted file mode 100644 index ecb2084da7..0000000000 --- a/sources/tech/20170525 An introduction to Linux s EXT4 filesystem.md +++ /dev/null @@ -1,302 +0,0 @@ -Translating by chenxinlong -An introduction to Linux's EXT4 filesystem -============================================================ - -### Take a walk through EXT4's history, features, and optimal use, and learn how it differs from previous iterations of the EXT filesystem. - - -![An introduction to the EXT4 filesystem](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/hard_drives.png?itok=yZWyaSO6 "An introduction to the EXT4 filesystem") ->Image credits : [WIlliam][8][ Warby][9]. Modified by [Jason Baker][10]. Creative Commons [BY-SA 2.0][11]. - -In previous articles about Linux filesystems, I wrote [an introduction to Linux filesystems][12] and about some higher-level concepts such as [everything is a file][13]. I want to go into more detail about the specifics of the EXT filesystems, but first, let's answer the question, "What is a filesystem?" A filesystem is all of the following: - -1. **Data storage: **The primary function of any filesystem is to be a structured place to store and retrieve data. - -2. **Namespace: **A naming and organizational methodology that provides rules for naming and structuring data. - -3. **Security model: **A scheme for defining access rights. - -4. **API: **System function calls to manipulate filesystem objects like directories and files. - -5. **Implementation: **The software to implement the above. - -This article concentrates on the first item in the list and explores the metadata structures that provide the logical framework for data storage in an EXT filesystem. - -### EXT filesystem history - -Although written for Linux, the EXT filesystem has its roots in the Minix operating system and the Minix filesystem, which predate Linux by about five years, being first released in 1987\. Understanding the EXT4 filesystem is much easier if we look at the history and technical evolution of the EXT filesystem family from its Minix roots. - -### Minix - -When writing the original Linux kernel, Linus Torvalds needed a filesystem but didn't want to write one then. So he simply included the [Minix filesystem][14], which had been written by [Andrew S. Tanenbaum][15] and was a part of Tanenbaum's Minix operating system. [Minix][16] was a Unix-like operating system written for educational purposes. Its code was freely available and appropriately licensed to allow Torvalds to include it in his first version of Linux. - -Minix has the following structures, most of which are located in the partition where the filesystem is generated: - -* A [**boot sector**][6] in the first sector of the hard drive on which it is installed. The boot block includes a very small boot record and a partition table. - -* The first block in each partition is a **superblock **that contains the metadata that defines the other filesystem structures and locates them on the physical disk assigned to the partition. - -* An **inode bitmap block**, which determines which inodes are used and which are free. - -* The **inodes**, which have their own space on the disk. Each inode contains information about one file, including the locations of the data blocks, i.e., zones belonging to the file. - -* A **zone bitmap** to keep track of the used and free data zones. - -* A **data zone**, in which the data is actually stored. - -For both types of bitmaps, one bit represents one specific data zone or one specific inode. If the bit is zero, the zone or inode is free and available for use, but if the bit is one, the data zone or inode is in use. - -What is an [inode][17]? Short for index-node, an inode is a 256-byte block on the disk and stores data about the file. This includes the file's size; the user IDs of the file's user and group owners; the file mode (i.e., the access permissions); and three timestamps specifying the time and date that: the file was last accessed, last modified, and the data in the inode was last modified. - -The inode also contains data that points to the location of the file's data on the hard drive. In Minix and the EXT1-3 filesystems, this is a list of data zones or blocks. The Minix filesystem inodes supported nine data blocks, seven direct and two indirect. If you'd like to learn more, there is an excellent PDF with a detailed description of the [Minix filesystem structure][18] and a quick overview of the [inode pointer structure][19] on Wikipedia. - -### EXT - -The original [EXT filesystem][20] (Extended) was written by [Rémy Card][21] and released with Linux in 1992 to overcome some size limitations of the Minix filesystem. The primary structural changes were to the metadata of the filesystem, which was based on the Unix filesystem (UFS), which is also known as the Berkeley Fast File System (FFS). I found very little published information about the EXT filesystem that can be verified, apparently because it had significant problems and was quickly superseded by the EXT2 filesystem. - -### EXT2 - -The [EXT2 filesystem][22] was quite successful. It was used in Linux distributions for many years, and it was the first filesystem I encountered when I started using Red Hat Linux 5.0 back in about 1997\. The EXT2 filesystem has essentially the same metadata structures as the EXT filesystem, however EXT2 is more forward-looking, in that a lot of disk space is left between the metadata structures for future use. - -Like Minix, EXT2 has a [boot sector][23] in the first sector of the hard drive on which it is installed, which includes a very small boot record and a partition table. Then there is some reserved space after the boot sector, which spans the space between the boot record and the first partition on the hard drive that is usually on the next cylinder boundary. [GRUB2][24]—and possibly GRUB1—uses this space for part of its boot code. - -The space in each EXT2 partition is divided into cylinder groups that allow for more granular management of the data space. In my experience, the group size usually amounts to about 8MB. Figure 1, below, shows the basic structure of a cylinder group. The data allocation unit in a cylinder is the block, which is usually 4K in size. - -![cylindergroup-01_1.png](https://opensource.com/sites/default/files/images/life-uploads/cylindergroup-01_1.png) - -Figure 1: The structure of a cylinder group in the EXT filesystems - -The first block in the cylinder group is a superblock, which contains the metadata that defines the other filesystem structures and locates them on the physical disk. Some of the additional groups in the partition will have backup superblocks, but not all. A damaged superblock can be replaced by using a disk utility such as **dd** to copy the contents of a backup superblock to the primary superblock. It does not happen often, but once, many years ago, I had a damaged superblock, and I was able to restore its contents using one of the backup superblocks. Fortunately, I had been foresighted and used the **dumpe2fs** command to dump the descriptor information of the partitions on my system. - -Following is the partial output from the **dumpe2fs** command. It shows the metadata contained in the superblock, as well as data about each of the first two cylinder groups in the filesystem. - -``` -# dumpe2fs /dev/sda1 -Filesystem volume name: boot -Last mounted on: /boot -Filesystem UUID: 79fc5ed8-5bbc-4dfe-8359-b7b36be6eed3 -Filesystem magic number: 0xEF53 -Filesystem revision #: 1 (dynamic) -Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir nlink extra_isize -Filesystem flags: signed_directory_hash -Default mount options: user_xattr acl -Filesystem state: clean -Errors behavior: Continue -Filesystem OS type: Linux -Inode count: 122160 -Block count: 488192 -Reserved block count: 24409 -Free blocks: 376512 -Free inodes: 121690 -First block: 0 -Block size: 4096 -Fragment size: 4096 -Group descriptor size: 64 -Reserved GDT blocks: 238 -Blocks per group: 32768 -Fragments per group: 32768 -Inodes per group: 8144 -Inode blocks per group: 509 -Flex block group size: 16 -Filesystem created: Tue Feb 7 09:33:34 2017 -Last mount time: Sat Apr 29 21:42:01 2017 -Last write time: Sat Apr 29 21:42:01 2017 -Mount count: 25 -Maximum mount count: -1 -Last checked: Tue Feb 7 09:33:34 2017 -Check interval: 0 () -Lifetime writes: 594 MB -Reserved blocks uid: 0 (user root) -Reserved blocks gid: 0 (group root) -First inode: 11 -Inode size: 256 -Required extra isize: 32 -Desired extra isize: 32 -Journal inode: 8 -Default directory hash: half_md4 -Directory Hash Seed: c780bac9-d4bf-4f35-b695-0fe35e8d2d60 -Journal backup: inode blocks -Journal features: journal_64bit -Journal size: 32M -Journal length: 8192 -Journal sequence: 0x00000213 -Journal start: 0 - -Group 0: (Blocks 0-32767) - Primary superblock at 0, Group descriptors at 1-1 - Reserved GDT blocks at 2-239 - Block bitmap at 240 (+240) - Inode bitmap at 255 (+255) - Inode table at 270-778 (+270) - 24839 free blocks, 7676 free inodes, 16 directories - Free blocks: 7929-32767 - Free inodes: 440, 470-8144 -Group 1: (Blocks 32768-65535) - Backup superblock at 32768, Group descriptors at 32769-32769 - Reserved GDT blocks at 32770-33007 - Block bitmap at 241 (bg #0 + 241) - Inode bitmap at 256 (bg #0 + 256) - Inode table at 779-1287 (bg #0 + 779) - 8668 free blocks, 8142 free inodes, 2 directories - Free blocks: 33008-33283, 33332-33791, 33974-33975, 34023-34092, 34094-34104, 34526-34687, 34706-34723, 34817-35374, 35421-35844, 35935-36355, 36357-36863, 38912-39935, 39940-40570, 42620-42623, 42655, 42674-42687, 42721-42751, 42798-42815, 42847, 42875-42879, 42918-42943, 42975, 43000-43007, 43519, 43559-44031, 44042-44543, 44545-45055, 45116-45567, 45601-45631, 45658-45663, 45689-45695, 45736-45759, 45802-45823, 45857-45887, 45919, 45950-45951, 45972-45983, 46014-46015, 46057-46079, 46112-46591, 46921-47103, 49152-49395, 50027-50355, 52237-52255, 52285-52287, 52323-52351, 52383, 52450-52479, 52518-52543, 52584-52607, 52652-52671, 52734-52735, 52743-53247 - Free inodes: 8147-16288 -Group 2: (Blocks 65536-98303) - Block bitmap at 242 (bg #0 + 242) - Inode bitmap at 257 (bg #0 + 257) - Inode table at 1288-1796 (bg #0 + 1288) - 6326 free blocks, 8144 free inodes, 0 directories - Free blocks: 67042-67583, 72201-72994, 80185-80349, 81191-81919, 90112-94207 - Free inodes: 16289-24432 -Group 3: (Blocks 98304-131071) - - -``` - -Each cylinder group has its own inode bitmap that is used to determine which inodes are used and which are free within that group. The inodes have their own space in each group. Each inode contains information about one file, including the locations of the data blocks belonging to the file. The block bitmap keeps track of the used and free data blocks within the filesystem. Notice that there is a great deal of data about the filesystem in the output shown above. On very large filesystems the group data can run to hundreds of pages in length. The group metadata includes a listing of all of the free data blocks in the group. - -The EXT filesystem implemented data-allocation strategies that ensured minimal file fragmentation. Reducing fragmentation improved filesystem performance. Those strategies are described below, in the section on EXT4. - -The biggest problem with the EXT2 filesystem, which I encountered on some occasions, was that it could take many hours to recover after a crash because the **fsck** (file system check) program took a very long time to locate and correct any inconsistencies in the filesystem. It once took over 28 hours on one of my computers to fully recover a disk upon reboot after a crash—and that was when disks were measured in the low hundreds of megabytes in size. - -### EXT3 - -The [EXT3 filesystem][25] had the singular objective of overcoming the massive amounts of time that the **fsck** program required to fully recover a disk structure damaged by an improper shutdown that occurred during a file-update operation. The only addition to the EXT filesystem was the [journal][26], which records in advance the changes that will be performed to the filesystem. The rest of the disk structure is the same as it was in EXT2. - -Instead of writing data to the disk's data areas directly, as in previous versions, the journal in EXT3 writes file data, along with its metadata, to a specified area on the disk. Once the data is safely on the hard drive, it can be merged in or appended to the target file with almost zero chance of losing data. As this data is committed to the data area of the disk, the journal is updated so that the filesystem will remain in a consistent state in the event of a system failure before all the data in the journal is committed. On the next boot, the filesystem will be checked for inconsistencies, and data remaining in the journal will then be committed to the data areas of the disk to complete the updates to the target file. - -Journaling does reduce data-write performance, however there are three options available for the journal that allow the user to choose between performance and data integrity and safety. My personal preference is on the side of safety because my environments do not require heavy disk-write activity. - -The journaling function reduces the time required to check the hard drive for inconsistencies after a failure from hours (or even days) to mere minutes, at the most. I have had many issues over the years that have crashed my systems. The details could fill another article, but suffice it to say that most were self-inflicted, like kicking out a power plug. Fortunately, the EXT journaling filesystems have reduced that bootup recovery time to two or three minutes. In addition, I have never had a problem with lost data since I started using EXT3 with journaling. - -The journaling feature of EXT3 can be turned off and it then functions as an EXT2 filesystem. The journal itself still exists, empty and unused. Simply remount the partition with the mount command using the type parameter to specify EXT2\. You may be able to do this from the command line, depending upon which filesystem you are working with, but you can change the type specifier in the **/etc/fstab** file and then reboot. I strongly recommend against mounting an EXT3 filesystem as EXT2 because of the additional potential for lost data and extended recovery times. - -An existing EXT2 filesystem can be upgraded to EXT3 with the addition of a journal using the following command. - -``` -tune2fs -j /dev/sda1 -``` - -Where **/dev/sda1** is the drive and partition identifier. Be sure to change the file type specifier in **/etc/fstab** and remount the partition or reboot the system to have the change take effect. - -### EXT4 - -The [EXT4 filesystem][27] primarily improves performance, reliability, and capacity. To improve reliability, metadata and journal checksums were added. To meet various mission-critical requirements, the filesystem timestamps were improved with the addition of intervals down to nanoseconds. The addition of two high-order bits in the timestamp field defers the [Year 2038 problem][28] until 2446—for EXT4 filesystems, at least. - -In EXT4, data allocation was changed from fixed blocks to extents. An extent is described by its starting and ending place on the hard drive. This makes it possible to describe very long, physically contiguous files in a single inode pointer entry, which can significantly reduce the number of pointers required to describe the location of all the data in larger files. Other allocation strategies have been implemented in EXT4 to further reduce fragmentation. - -EXT4 reduces fragmentation by scattering newly created files across the disk so that they are not bunched up in one location at the beginning of the disk, as many early PC filesystems did. The file-allocation algorithms attempt to spread the files as evenly as possible among the cylinder groups and, when fragmentation is necessary, to keep the discontinuous file extents as close as possible to others in the same file to minimize head seek and rotational latency as much as possible. Additional strategies are used to pre-allocate extra disk space when a new file is created or when an existing file is extended. This helps to ensure that extending the file will not automatically result in its becoming fragmented. New files are never allocated immediately after existing files, which also prevents fragmentation of the existing files. - -Aside from the actual location of the data on the disk, EXT4 uses functional strategies, such as delayed allocation, to allow the filesystem to collect all the data being written to the disk before allocating space to it. This can improve the likelihood that the data space will be contiguous. - -Older EXT filesystems, such as EXT2 and EXT3, can be mounted as EXT4 to make some minor performance gains. Unfortunately, this requires turning off some of the important new features of EXT4, so I recommend against this. - -EXT4 has been the default filesystem for Fedora since Fedora 14\. An EXT3 filesystem can be upgraded to EXT4 using the [procedure ][29]described in the Fedora documentation, however its performance will still suffer due to residual EXT3 metadata structures. The best method for upgrading to EXT4 from EXT3 is to back up all the data on the target filesystem partition, use the **mkfs** command to write an empty EXT4 filesystem to the partition, and then restore all the data from the backup. - -### Inode - -The inode, described previously, is a key component of the metadata in EXT filesystems. Figure 2 shows the relationship between the inode and the data stored on the hard drive. This diagram is the directory and inode for a single file which, in this case, may be highly fragmented. The EXT filesystems work actively to reduce fragmentation, so it is very unlikely you will ever see a file with this many indirect data blocks or extents. In fact, as you will see below, fragmentation is extremely low in EXT filesystems, so most inodes will use only one or two direct data pointers and none of the indirect pointers. - -![inodesanddataallocation-01_0.png](https://opensource.com/sites/default/files/images/life-uploads/inodesanddataallocation-01_0.png) - -Figure 2: The inode stores information about each file and enables the EXT filesystem to locate all data belonging to it. - -The inode does not contain the name of the file. Access to a file is via the directory entry, which itself is the name of the file and contains a pointer to the inode. The value of that pointer is the inode number. Each inode in a filesystem has a unique ID number, but inodes in other filesystems on the same computer (and even the same hard drive) can have the same inode number. This has implications for [links][30], and this discussion is beyond the scope of this article. - -The inode contains the metadata about the file, including its type and permissions as well as its size. The inode also contains space for 15 pointers that describe the location and length of data blocks or extents in the data portion of the cylinder group. Twelve of the pointers provide direct access to the data extents and should be sufficient to handle most files. However, for files that have significant fragmentation, it becomes necessary to have some additional capabilities in the form of indirect nodes. Technically these are not really inodes, so I use the term "node" here for convenience. - -An indirect node is a normal data block in the filesystem that is used only for describing data and not for storage of metadata, thus more than 15 entries can be supported. For example, a block size of 4K can support 512 4-byte indirect nodes, allowing **12 (direct) + 512 (indirect) = 524** extents for a single file. Double and triple indirect node support is also supported, but most of us are unlikely to encounter files requiring that many extents. - -### Data fragmentation - -For many older PC filesystems, such as FAT (and all its variants) and NTFS, fragmentation has been a significant problem resulting in degraded disk performance. Defragmentation became an industry in itself with different brands of defragmentation software that ranged from very effective to only marginally so. - -Linux's extended filesystems use data-allocation strategies that help to minimize fragmentation of files on the hard drive and reduce the effects of fragmentation when it does occur. You can use the **fsck** command on EXT filesystems to check the total filesystem fragmentation. The following example checks the home directory of my main workstation, which was only 1.5% fragmented. Be sure to use the **-n** parameter, because it prevents **fsck** from taking any action on the scanned filesystem. - -``` -fsck -fn /dev/mapper/vg_01-home -``` - -I once performed some theoretical calculations to determine whether disk defragmentation might result in any noticeable performance improvement. While I did make some assumptions, the disk performance data I used were from a new 300GB, Western Digital hard drive with a 2.0ms track-to-track seek time. The number of files in this example was the actual number that existed in the filesystem on the day I did the calculation. I did assume that a fairly large amount of the fragmented files (20%) would be touched each day. - -| **Total files** | **271,794** | -| % fragmentation | 5.00% | -| Discontinuities | 13,590 | -|   |   | -| % fragmented files touched per day | 20% (assume) | -| Number of additional seeks | 2,718 | -| Average seek time | 10.90 ms | -| Total additional seek time per day | 29.63 sec | -|   | 0.49 min | -|   |   | -| Track-to-track seek time | 2.00 ms | -| Total additional seek time per day | 5.44 sec | -|   | 0.091 min | - -Table 1: The theoretical effects of fragmentation on disk performance - -I have done two calculations for the total additional seek time per day, one based on the track-to-track seek time, which is the more likely scenario for most files due to the EXT file allocation strategies, and one for the average seek time, which I assumed would make a fair worst-case scenario. - -As you can see from Table 1, the impact of fragmentation on a modern EXT filesystem with a hard drive of even modest performance would be minimal and negligible for the vast majority of applications. You can plug the numbers from your environment into your own similar spreadsheet to see what you might expect in the way of performance impact. This type of calculation most likely will not represent actual performance, but it can provide a bit of insight into fragmentation and its theoretical impact on a system. - -Most of my partitions are around 1.5% or 1.6% fragmented; I do have one that is 3.3% fragmented but that is a large, 128GB filesystem with fewer than 100 very large ISO image files; I've had to expand the partition several times over the years as it got too full. - -That is not to say that some application environments don't require greater assurance of even less fragmentation. The EXT filesystem can be tuned with care by a knowledgeable admin who can adjust the parameters to compensate for specific workload types. This can be done when the filesystem is created or later using the **tune2fs** command. The results of each tuning change should be tested, meticulously recorded, and analyzed to ensure optimum performance for the target environment. In the worst case, where performance cannot be improved to desired levels, other filesystem types are available that may be more suitable for a particular workload. And remember that it is common to mix filesystem types on a single host system to match the load placed on each filesystem. - -Due to the low amount of fragmentation on most EXT filesystems, it is not necessary to defragment. In any event, there is no safe defragmentation tool for EXT filesystems. There are a few tools that allow you to check the fragmentation of an individual file or the fragmentation of the remaining free space in a filesystem. There is one tool, **e4defrag**, which will defragment a file, directory, or filesystem as much as the remaining free space will allow. As its name implies, it only works on files in an EXT4 filesystem, and it does have some limitations. - -If it becomes necessary to perform a complete defragmentation on an EXT filesystem, there is only one method that will work reliably. You must move all the files from the filesystem to be defragmented, ensuring that they are deleted after being safely copied to another location. If possible, you could then increase the size of the filesystem to help reduce future fragmentation. Then copy the files back onto the target filesystem. Even this does not guarantee that all the files will be completely defragmented. - -### Conclusions - -The EXT filesystems have been the default for many Linux distributions for more than 20 years. They offer stability, high capacity, reliability, and performance while requiring minimal maintenance. I have tried other filesystems but always return to EXT. Every place I have worked with Linux has used the EXT filesystems and found them suitable for all the mainstream loads used on them. Without a doubt, the EXT4 filesystem should be used for most Linux systems unless there is a compelling reason to use another filesystem. - --------------------------------------------------------------------------------- - -作者简介: - -David Both - David Both is a Linux and Open Source advocate who resides in Raleigh, North Carolina. He has been in the IT industry for over forty years and taught OS/2 for IBM where he worked for over 20 years. While at IBM, he wrote the first training course for the original IBM PC in 1981. He has taught RHCE classes for Red Hat and has worked at MCI Worldcom, Cisco, and the State of North Carolina. He has been working with Linux and Open Source Software for almost 20 years. - -------------------- - -via: https://opensource.com/article/17/5/introduction-ext4-filesystem - -作者:[David Both ][a] -译者:[译者ID](https://github.com/chenxinlong) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://opensource.com/users/dboth -[1]:https://opensource.com/resources/what-is-linux?src=linux_resource_menu -[2]:https://opensource.com/resources/what-are-linux-containers?src=linux_resource_menu -[3]:https://developers.redhat.com/promotions/linux-cheatsheet/?intcmp=7016000000127cYAAQ -[4]:https://developers.redhat.com/cheat-sheet/advanced-linux-commands-cheatsheet?src=linux_resource_menu&intcmp=7016000000127cYAAQ -[5]:https://opensource.com/tags/linux?src=linux_resource_menu -[6]:https://en.wikipedia.org/wiki/Boot_sector -[7]:https://opensource.com/article/17/5/introduction-ext4-filesystem?rate=B4QU3W_JYmEKsIKZf5yqMpztt7CRF6uzC0wfNBidEbs -[8]:https://www.flickr.com/photos/wwarby/11644168395 -[9]:https://www.flickr.com/photos/wwarby/11644168395 -[10]:https://opensource.com/users/jason-baker -[11]:https://creativecommons.org/licenses/by/2.0/ -[12]:https://opensource.com/life/16/10/introduction-linux-filesystems -[13]:https://opensource.com/life/15/9/everything-is-a-file -[14]:https://en.wikipedia.org/wiki/MINIX_file_system -[15]:https://en.wikipedia.org/wiki/Andrew_S._Tanenbaum -[16]:https://en.wikipedia.org/wiki/MINIX -[17]:https://en.wikipedia.org/wiki/Inode -[18]:http://ohm.hgesser.de/sp-ss2012/Intro-MinixFS.pdf -[19]:https://en.wikipedia.org/wiki/Inode_pointer_structure -[20]:https://en.wikipedia.org/wiki/Extended_file_system -[21]:https://en.wikipedia.org/wiki/R%C3%A9my_Card -[22]:https://en.wikipedia.org/wiki/Ext2 -[23]:https://en.wikipedia.org/wiki/Boot_sector -[24]:https://opensource.com/article/17/2/linux-boot-and-startup -[25]:https://en.wikipedia.org/wiki/Ext3 -[26]:https://en.wikipedia.org/wiki/Journaling_file_system -[27]:https://en.wikipedia.org/wiki/Ext4 -[28]:https://en.wikipedia.org/wiki/Year_2038_problem -[29]:https://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/ext4converting.html -[30]:https://en.wikipedia.org/wiki/Hard_link -[31]:https://opensource.com/user/14106/feed -[32]:https://opensource.com/article/17/5/introduction-ext4-filesystem#comments -[33]:https://opensource.com/users/dboth diff --git a/translated/tech/20170525 An introduction to Linux s EXT4 filesystem.md b/translated/tech/20170525 An introduction to Linux s EXT4 filesystem.md new file mode 100644 index 0000000000..25e27d187e --- /dev/null +++ b/translated/tech/20170525 An introduction to Linux s EXT4 filesystem.md @@ -0,0 +1,301 @@ +Linux 的 EXT4 文件系统简介 +============================================================ + +### 让我们大概地从 EXT4 的历史、特性以及最佳实践这几个方面来学习它和之前的所有的 EXT 文件系统有何不同。 + +![An introduction to the EXT4 filesystem](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/hard_drives.png?itok=yZWyaSO6 "An introduction to the EXT4 filesystem") +>图片来自 : [WIlliam][8][ Warby][9]. 由 [Jason Baker][10] 编辑. Creative Commons [BY-SA 2.0][11]. + +在之前关于 Linux 文件系统的文章里,我写过一篇 [an introduction to Linux filesystems][12] 和一些更高级的概念例如 [everything is a file][13]. 我想要更深入地了解 EXT 文件系统的特性的详细内容,但是首先让我们来回答一个问题,“什么样才算是一个文件系统 ?” 一个文件系统应该涵盖以下所有点: + +1. **数据存储:** 对于任何一个文件系统来说,一个最主要的功能就是能够被当作一个容器结构来存储和恢复数据。 + +2. **命名空间:** 命名空间是一个提供了命名规则和数据结构的用于命名与组织的方法学。 + +3. **安全模型:** 一个用于定义访问权限的策略。 + +4. **API:** 指的是调用了操作这个系统的对象的系统方法,这些对象诸如目录和文件。 + +5. **实现:** 能够实现以上几点的软件。 + +本文内容的讨论主要集中于上述几点中的第一项并探索为一个 EXT 文件系统的数据存储提供逻辑框架的元数据结构。 + +### EXT 文件系统历史 + +虽然 EXT 文件系统是为 Linux 编写的,但其真正起源于 Minix 操作系统和 Minix 文件系统,而 Minix 最早发布于 1987,早于 Linux 5 年。如果我们从 EXT 文件系统大家族的 Minix 起源来观察其历史与技术发展那么理解 EXT4 文件系统就会简单得多。 + +### Minix + +当 Linux Torvalds 在写最初的 Linux 内核的时候,他需要一个文件系统但是他又不想自己写一个。于是他简单地把 [Minix 文件系统][14] 加了进去,这个 Minix 文件系统是由 [Andrew S. Tanenbaum][15] 写的同时也是 Tanenbaum 的 Minix 操作系统的一部分。[Minix][16] 是一个类 Unix 风格的操作系统,最初编写它的原因是用于教育。Minx 的代码是自由可用的且经过适当的许可的,所以 Torvalds 可以把它用 Linux 的最初版本里。 + +Minix 有以下这些结构,其中的大部分位于生成文件系统的分区中: + +* [**boot 扇区**][6] 是硬盘驱动安装后的第一个扇区。这个 boot 块包含了一个非常小的 boot 记录和一个分区表。 + +* 每一个分区的第一个块都是一个包含了元数据的 **superblock** ,这些元数据定义了其他文件系统的结构并将其定位于物理硬盘的具体分区上。 + +* 一个 **inode 位图块** 决定了哪些 inode 是在使用中的,哪一些是未使用的。 + +* **inode** 在硬盘上有它们自己的空间。每一个 inode 都包含了一个文件的信息包括其所处的数据块的位置,也就是该文件所处的区域。 + +* 一个 **区位图** 用于保持追踪数据区域的使用和未使用情况。 + +* 一个 **数据区**, 这里是数据存储的地方。 + +对上述了两种位图类型来说,一个 bit 表示一个制定的数据区或者一个指定的 inode. 如果这个 bit 是 0 则表示这个数据区或者这个 inode 是可以使用的,如果是 1 则表示正在使用中。 + +那么,[inode][17] 又是什么呢 ? 就是 index-node (索引节点)的简写。 inode 是位于磁盘上的一个 256 字节的块,用于存储和该 inode 对应的文件的相关数据。这些数据包含了文件的大小、文件的所有者和所属组的用户的 ID、文件模式(即访问权限)以及三个时间戳用于指定:该文件最后的访问时间、该文件的最后修改时间和该 inode 中的数据的最后修改时间。 + +同时,这个 inode 还包含了指向了其所对应的文件的数据在硬盘中的位置。在 Minix 和 EXT1-3 文件系统中,inode 表示的是一系列的的数据区和块。Minix 文件系统的 inode 支持 9 个数据块包括 7 个直接数据块和 2 个间接数据块。如果你想要更深入的了解,这里有一个优秀的 PDF 详细地描述了 [Minix 文件系统街头][18] 。同时你也可以在维基百科上对 [inode 指针结构][19] 做一个快速的浏览。 + +### EXT + +原生的 [EXT 文件系统][20] (指经过扩展的) 是由 [Rémy Card][21] 编写并于 1992 年与 Linux 一同发行。主要是为了克服 Minix 文件系统中的一些文件大小限制的问题。其中,最主要的结构变化就是文件系统中的元数据。它基于 Unix 文件系统 (UFS),也被称为伯克利快速文件系统(FFS)。我发现只有很少一部分关于 EXT 文件系统的发行信息是可以被验证的,显然这是因为其存在着严重的问题并且它很快地被 EXT2 文件系统取代了。 + +### EXT2 + +[EXT2 文件系统][22] 就相当地成功,它在 Linux 发行版中存活了多年。它是我在 1997 年开始使用 Red Hat Linux 时认识的第一个文件系统。实际上,EXT2 文件系统有着和 EXT 文件系统基本相同的元数据结构。然而 EXT2 更高瞻远瞩,因为其元数据结构之间留有很多磁盘空间供将来使用。 + +和 Minix 类似,EXT2 也有一个[boot 扇区][23] ,它是硬盘驱动安装后的第一个扇区。它包含了少量的 boot 记录和一个分区表。接着 boot 扇区之后是一些保留的空间,它跨越引导记录和通常位于下一个柱面的硬盘驱动器上的第一个分区之间的空间。 [GRUB2] [24] - 也可能是GRUB1 - 将此空间用于其部分启动代码。 + +每个 EXT2 分区中的空间分为各柱面组,它允许更精细地管理数据空间。 根据我的经验,每一组大小通常约为8MB。 下面的图1显示了一个柱面组的基本结构。 柱面中的数据分配单元是块,通常大小为4K。 + +![cylindergroup-01_1.png](https://opensource.com/sites/default/files/images/life-uploads/cylindergroup-01_1.png) + +Figure 1: EXT 文件系统中的柱面组的结构 + +柱面组中的第一个块是一个超级块,它包含了一个定义了其他文件系统的结构并将其定位于物理硬盘的具体分区上的元数据。分区中有一些柱面组还会有备用超级块,但并不是所有的柱面组都有。我们还可以使用例如 **dd** 等磁盘工具来拷贝备用超级块的内容到主超级块上以达到更换损坏超级块的目的。虽然这种情况不会经常发生,但是在几年前我的一个超级块损坏了,我就是用这种方法来修复的。幸好,我很有先见之明地使用了 **dumpe2fs** 命令来备份了我的分区描述符信息到我的系统上。 + +以下是 **dumpe2fs** 命令的一部分输出。这部分输出主要是超级块上包含的一些元数据,同时也是文件系统上的前两个柱面组的数据。 + +``` +# dumpe2fs /dev/sda1 +Filesystem volume name: boot +Last mounted on: /boot +Filesystem UUID: 79fc5ed8-5bbc-4dfe-8359-b7b36be6eed3 +Filesystem magic number: 0xEF53 +Filesystem revision #: 1 (dynamic) +Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir nlink extra_isize +Filesystem flags: signed_directory_hash +Default mount options: user_xattr acl +Filesystem state: clean +Errors behavior: Continue +Filesystem OS type: Linux +Inode count: 122160 +Block count: 488192 +Reserved block count: 24409 +Free blocks: 376512 +Free inodes: 121690 +First block: 0 +Block size: 4096 +Fragment size: 4096 +Group descriptor size: 64 +Reserved GDT blocks: 238 +Blocks per group: 32768 +Fragments per group: 32768 +Inodes per group: 8144 +Inode blocks per group: 509 +Flex block group size: 16 +Filesystem created: Tue Feb 7 09:33:34 2017 +Last mount time: Sat Apr 29 21:42:01 2017 +Last write time: Sat Apr 29 21:42:01 2017 +Mount count: 25 +Maximum mount count: -1 +Last checked: Tue Feb 7 09:33:34 2017 +Check interval: 0 () +Lifetime writes: 594 MB +Reserved blocks uid: 0 (user root) +Reserved blocks gid: 0 (group root) +First inode: 11 +Inode size: 256 +Required extra isize: 32 +Desired extra isize: 32 +Journal inode: 8 +Default directory hash: half_md4 +Directory Hash Seed: c780bac9-d4bf-4f35-b695-0fe35e8d2d60 +Journal backup: inode blocks +Journal features: journal_64bit +Journal size: 32M +Journal length: 8192 +Journal sequence: 0x00000213 +Journal start: 0 + +Group 0: (Blocks 0-32767) + Primary superblock at 0, Group descriptors at 1-1 + Reserved GDT blocks at 2-239 + Block bitmap at 240 (+240) + Inode bitmap at 255 (+255) + Inode table at 270-778 (+270) + 24839 free blocks, 7676 free inodes, 16 directories + Free blocks: 7929-32767 + Free inodes: 440, 470-8144 +Group 1: (Blocks 32768-65535) + Backup superblock at 32768, Group descriptors at 32769-32769 + Reserved GDT blocks at 32770-33007 + Block bitmap at 241 (bg #0 + 241) + Inode bitmap at 256 (bg #0 + 256) + Inode table at 779-1287 (bg #0 + 779) + 8668 free blocks, 8142 free inodes, 2 directories + Free blocks: 33008-33283, 33332-33791, 33974-33975, 34023-34092, 34094-34104, 34526-34687, 34706-34723, 34817-35374, 35421-35844, 35935-36355, 36357-36863, 38912-39935, 39940-40570, 42620-42623, 42655, 42674-42687, 42721-42751, 42798-42815, 42847, 42875-42879, 42918-42943, 42975, 43000-43007, 43519, 43559-44031, 44042-44543, 44545-45055, 45116-45567, 45601-45631, 45658-45663, 45689-45695, 45736-45759, 45802-45823, 45857-45887, 45919, 45950-45951, 45972-45983, 46014-46015, 46057-46079, 46112-46591, 46921-47103, 49152-49395, 50027-50355, 52237-52255, 52285-52287, 52323-52351, 52383, 52450-52479, 52518-52543, 52584-52607, 52652-52671, 52734-52735, 52743-53247 + Free inodes: 8147-16288 +Group 2: (Blocks 65536-98303) + Block bitmap at 242 (bg #0 + 242) + Inode bitmap at 257 (bg #0 + 257) + Inode table at 1288-1796 (bg #0 + 1288) + 6326 free blocks, 8144 free inodes, 0 directories + Free blocks: 67042-67583, 72201-72994, 80185-80349, 81191-81919, 90112-94207 + Free inodes: 16289-24432 +Group 3: (Blocks 98304-131071) + + +``` + +每一个柱面组都有自己的 inode 位图用于判定该柱面组中的哪些 inode 是使用中的而哪些又是未被使用的。每一个柱面组的 inode 都有它们自己的空间。每一个 inode 都包含了对应的文件的相关信息,包括其位于该文件的数据块中的位置。这个块位图纪录了文件系统中的使用中和非使用中的数据块。请注意,在上面的输出中有大量关于文件系统的数据。在非常大的文件系统上,组数据可以运行到数百页的长度。 组元数据包括组中所有空闲数据块的列表。 + +EXT 文件系统实现了数据分配策略以确保产生最少的文件碎片。减少文件碎片可以提高文件系统的性能。这些策略会在下面的 EXT4 中描述到。 + +我所遇见的关于 EXT2 文件系统最大的问题是 **fsck** (文件系统检查) 程序这一环节占用了很长一段时间来定位和校准文件系统中的所有不一致性导致其共花费了数个小时来修复一个崩溃。有一次我的其中一台电脑共花费了 28 个小时在一次崩溃后重新启动时恢复磁盘上,并且是在磁盘被检测量在几百兆字节大小的情况下。 + +### EXT3 + +[EXT3 文件系统][25] 具有克服 **fsck** 程序需要完全恢复在文件更新操作期间发生的不正确关机损坏的磁盘结构所需的大量时间的单一目标。EXT 文件系统的唯一新增是 [日志][26],它将提前记录将对文件系统执行的更改。 磁盘结构的其余部分与 EXT2 中的相同。 + +作为一个先前的版本,除了直接写入数据到磁盘的数据区域外,EXT3 的日志在写入元数据时同时会也写入文件数据到磁盘上的一个指定数据区域。一旦这些数据安全地到达硬盘,它就可以几乎零丢失率地被合并或者被追加到目标文件。当这些数据被提交到磁盘上的数据区域上,这些日志就会随即更新,这样在系统发生故障之前,文件系统将保持一致状态,才能提交日志中的所有数据。在下次启动时,将检查文件系统的不一致性,然后将日志中保留的数据提交到磁盘的数据区,以完成对目标文件的更新。 + +日记功能确实降低了数据写入性能,但是有三个可用于日志的选项,允许用户在性能和数据完整性和安全性之间进行选择。 我的个人更偏向于选择安全性,因为我的环境不需要大量的磁盘写入活动。 + +日志功能减少了在从几小时(甚至几天)到几分钟之间的失败后检查硬盘驱动器所需的时间。 多年来,我遇到了很多问题导致了我的系统崩溃。要详细说的话恐怕还得再写一篇文章,但这足以说明大多数是我自己造成的,就比如不小心踢掉一个电源插头。 幸运的是,EXT日志文件系统将启动恢复时间缩短到两三分钟。 此外,自从我开始使用带日志记录的EXT3,我从来没有遇到丢失数据的问题。 + +EXT3 的日志功能可以关闭,然后作为 EXT2 文件系统。 该日志本身仍然是存在的,只是状态为空且未使用。 只需使用类型参数使用 mount 命令来 remount 到分区即可指定EXT2 \。 你可以从命令行执行此操作,但是具体还是取决于你正在使用的文件系统,但你可以更改 **/ etc / fstab** 文件中的类型说明符,然后重新启动。 我强烈建议不要将 EXT3文件系统安装为 EXT2 ,因为这会具有丢失数据和增加恢复时间的潜在可能性。 + +EXT2 文件系统可以使用如下命令来通过日志升级到 EXT3 。 + +``` +tune2fs -j /dev/sda1 +``` + + **/dev/sda1** 表示驱动和分区的标识符。同时要注意修改 **/etc/fstab** 中的文件类型标识符并 remount 分区或者重启系统以确保修改生效。 + +### EXT4 + +[EXT4 filesystem][27]主要提高了性能、可靠性和容量。位了提高可靠性,它新增了元数据和日志校验和。同时位了满足各种关键任务要求,文件系统新增了纳秒级别的时间戳。在时间戳字段中添加两个高位来延迟时间戳的 [2038 年的问题][28] ,在 EXT4 文件系统至少可达到 2446 年。 + +在 EXT4 中,数据分配从固定块更改为盘区,盘区由硬盘驱动器上的开始和结束位置来描述。这使得可以在单个 inode 指针条目中描述非常长的物理连续的文件,这可以显着减少描述大文件中所有数据的位置所需的指针数。 EXT4 中已经实施了其他分配策略,以进一步减少碎片化。 + +EXT4 通过将新创建的文件分散在磁盘上,从而使其不会全部聚集在磁盘起始位置,就像早期的PC文件系统一样,减少了碎片。文件分配算法尝试在柱面组中尽可能均匀地扩展文件,并且当需要分段时,要使不连续文件扩展区尽可能靠近同一文件中的其他文件,以尽可能减少头部搜索和旋转等待时间尽可能的当创建新文件或扩展现有文件时,使用其他策略来预分配额外的磁盘空间。这有助于确保扩展文件不会自动导致其分段。新文件不会在现有文件之后立即分配,这也可以防止现有文件的碎片化。 + +除了磁盘上数据的实际位置外,EXT4 使用诸如延迟分配的功能策略,以允许文件系统在分配空间之前收集正在写入磁盘的所有数据。这可以提高数据空间将是连续的可能性。 + +较旧的EXT文件系统(如 EXT2 和 EXT3)可以作为 EXT4 进行 mount ,以使其性能获得较小的提升。不幸的是,这需要关闭 EXT4 的一些重要的新功能,所以我建议不要这样做。 + +自 Fedora 14 以来,EXT4 一直是 Fedora 的默认文件系统。我们可以使用 Fedora 文档中描述的 [procedure ][29] 将EXT3文件系统升级到EXT4,但是由于之前仍然存留d的 EXT3 元数据结构,它的性能仍将受到影响。从 EXT3 升级到 EXT4 的最佳方法是备份目标文件系统分区上的所有数据,使用 **mkfs** 命令将空EXT4文件系统写入分区,然后从备份中恢复所有数据。 + +### Inode + +以前描述的 inode 是EXT文件系统中的元数据的关键组件。 图 2 显示了 inode 和存储在硬盘驱动器上的数据之间的关系。 该图是单个文件的目录和 inode,在这种情况下,可能会产生高度碎片。 EXT 文件系统可以积极地减少碎片,所以不太可能会看到有这么多间接数据块或扩展盘的文件。 实际上,如下所示,EXT文件系统中的碎片非常低,所以大多数 inode 只使用一个或两个直接数据指针,也不使用间接指针。 + +![inodesanddataallocation-01_0.png](https://opensource.com/sites/default/files/images/life-uploads/inodesanddataallocation-01_0.png) + +图 2 :inode 存储有关每个文件的信息,并使 EXT 文件系统能够查找属于它的所有数据。 + +inode 不包含文件的名称。通过目录条目访问文件,目录条目本身是文件的名称,并包含指向 inode 的指针。该指针的值是 inode 号。文件系统中的每个 inode 都具有唯一的 ID 号,但同一台计算机上的其他文件系统(甚至相同的硬盘驱动器)中的 inode 可以具有相同的 inode 号。这对[links][30] 存在影响,但是这个讨论超出了本文的范围。 + +inod e包含有关该文件的元数据,包括其类型和权限以及其大小。 inode 还包含 15 个指针的空格,用于描述柱面组数据部分中数据块或扩展区的位置和长度。十二个指针提供对数据扩展区的直接访问,并且应该足以处理大多数文件。然而,对于具有重大分段的文件,有必要以间接节点的形式具有一些附加功能。从技术上讲,这些不是真正的节点,所以我在这里使用这个术语“节点”来方便。 + +间接节点是文件系统中的正常数据块,它仅用于描述数据而不用于存储元数据,因此可以支持超过 15 个条目。例如,4K 的块大小可以支持 512 个 4 字节间接节点,允许单个文件的 **12(直接)+ 512(间接)= 524** 范围。还支持双重和三重间接节点支持,但我们大多数人不太可能遇到需要许多扩展的文件。 + +### 数据碎片 + +对于许多较旧的 PC 文件系统,如 FAT(及其所有变体)和 NTFS,碎片一直是导致磁盘性能下降的重大问题。 碎片整理对于其本身和一些专门的整理软件来说已经称为了一项专门的工程,其效果范围从非常有效到仅仅是微乎其微。 + +Linux 的扩展文件系统使用数据分配策略,有助于最小化硬盘驱动器上的文件碎片,并在发生碎片时减少碎片的影响。 你可以使用 EXT 文件系统上的 **fsck** 命令检查文件系统的整体碎片。 以下示例检查主工作站的主目录,只有 1.5% 的碎片。 确保使用 **- n** 参数,因为它会阻止 **fsck** 对扫描文件系统采取的任何操作。 + +``` +fsck -fn /dev/mapper/vg_01-home +``` + +我曾经进行过一些理论计算,以确定磁盘碎片整理是否会导致任何明显的性能提升。 虽然我做了一些假设,我使用的磁盘性能数据来自一个新的 300GB 的西部数字硬盘驱动器,具有 2.0ms 的追踪到追踪时间。 此示例中的文件数是在计算当天文件系统中存在的实际数。 我假设有相当大量的碎片文件(约 20%)每天都会被触动。 + +| **Total files** | **271,794** | +|--|--| +| % fragmentation | 5.00% | +| Discontinuities | 13,590 | +|   |   | +| % fragmented files touched per day | 20% (assume) | +| Number of additional seeks | 2,718 | +| Average seek time | 10.90 ms | +| Total additional seek time per day | 29.63 sec | +|   | 0.49 min | +|   |   | +| Track-to-track seek time | 2.00 ms | +| Total additional seek time per day | 5.44 sec | +|   | 0.091 min | + +表 1: 碎片对磁盘性能的理论影响 + +我对每天的全部追加寻道时间进行了两次计算,一次是单磁道寻道时间,这是由于EXT文件分配策略而导致大多数文件的可能性更大的情况,一个是平均搜索时间,我认为这将是一个公平的最坏情况。 + +从表 1 可以看出,对绝大多数应用程序而言,碎片化对具有甚至适度性能的硬盘驱动器的现代EXT文件系统的影响将是微乎其微的。您可以将您的环境中的数字插入到您自己的类似电子表格中,以了解你对性能影响的期望。这种类型的计算不一定能够代表实际的性能,但它可以提供一些洞察碎片化及其对系统的理论影响。 + +我的大部分分区的碎片率都在 1.5% 左右或 1.6%,我有一个分区有 3.3% 的碎片,但是这是一个大的 128GB 文件系统,具有少于100 个非常大的 ISO 映像文件; 多年来,我不得不扩张分区,因为它已经太满了。 + +这并不是说一些应用的环境不需要更多的保证,甚至更少的碎片。 EXT 文件系统可以由有经验和知识的管理员小心调整,管理员可以调整参数以抵消特定的工作负载类型。这个工作可以在文件系统创建的时候或稍后使用 **tune2fs** 命令时完成。每一次调整变化的结果应进行测试,精心的记录和分析,以确保目标环境的最佳性能。在最坏的情况下,如果性能不能提高到期望的水平,则其他文件系统类型可能更适合特定的工作负载。并记住,在单个主机系统上使用混合文件系统类型以匹配放在每个文件系统上的负载是常见的。 + +由于大多数 EXT 文件系统的碎片数量较少,因此无需进行碎片整理。在任何情况下,EXT 文件系统都没有安全的碎片整理工具。有几个工具允许你检查单个文件的碎片或文件系统中剩余可用空间的碎片。有一个工具,**e4defrag**,它将对剩余可用空间允许的文件,目录或文件系统进行碎片整理。顾名思义,它只适用于 EXT4 文件系统中的文件,并且它还有一其它的些限制。 + +如果有必要在 EXT 文件系统上执行完整的碎片整理,则只有一种方法能够可靠地工作。你必须将文件系统中的所有要进行碎片整理的文件在确保在安全复制到其他位置后将其删除。如果可能,你可以增加文件系统的大小,以帮助减少将来的碎片。然后将文件复制回目标文件系统。但是其实即使这样也不能保证所有文件都被完全碎片整理。 + +### 总结 + +EXT 文件系统在一些 Linux 发行版本上作为默认文件系统已经超过二十多年了。它们用最少的维护代价提供了稳定性、高可用性、可靠性和其他各种表现。我尝试过一些其它的文件系统但最终都还是回归到 EXT。每一个我在工作中使用到 Linux 的地方都使用到了 EXT 文件系统,同时发现了它们适用于任何主流的负载。毫无疑问,EXT4 文件系统应该被用于大部分的 Linux 文件系统上,除非我们有明显的使用其它文件系统的理由。 + +-------------------------------------------------------------------------------- + +作者简介: + +David Both - David Both 是一名 Linux 于开源的贡献者,目前居住在北卡罗莱纳州的罗利。他从事 IT 行业有 40 余年并在 IBM 中从事 OS/2 培训约 20 余年。在 IBM 就职期间,他在 1981 年为最早的 IBM PC 写了一个培训课程。他已经为红帽教授了 RHCE 课程,曾在 MCI Worldcom,思科和北卡罗来纳州工作。 他使用 Linux 和开源软件工作了近 20 年。 + +------------------- + +via: https://opensource.com/article/17/5/introduction-ext4-filesystem + +作者:[David Both ][a] +译者:[chenxinlong](https://github.com/chenxinlong) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/dboth +[1]:https://opensource.com/resources/what-is-linux?src=linux_resource_menu +[2]:https://opensource.com/resources/what-are-linux-containers?src=linux_resource_menu +[3]:https://developers.redhat.com/promotions/linux-cheatsheet/?intcmp=7016000000127cYAAQ +[4]:https://developers.redhat.com/cheat-sheet/advanced-linux-commands-cheatsheet?src=linux_resource_menu&intcmp=7016000000127cYAAQ +[5]:https://opensource.com/tags/linux?src=linux_resource_menu +[6]:https://en.wikipedia.org/wiki/Boot_sector +[7]:https://opensource.com/article/17/5/introduction-ext4-filesystem?rate=B4QU3W_JYmEKsIKZf5yqMpztt7CRF6uzC0wfNBidEbs +[8]:https://www.flickr.com/photos/wwarby/11644168395 +[9]:https://www.flickr.com/photos/wwarby/11644168395 +[10]:https://opensource.com/users/jason-baker +[11]:https://creativecommons.org/licenses/by/2.0/ +[12]:https://opensource.com/life/16/10/introduction-linux-filesystems +[13]:https://opensource.com/life/15/9/everything-is-a-file +[14]:https://en.wikipedia.org/wiki/MINIX_file_system +[15]:https://en.wikipedia.org/wiki/Andrew_S._Tanenbaum +[16]:https://en.wikipedia.org/wiki/MINIX +[17]:https://en.wikipedia.org/wiki/Inode +[18]:http://ohm.hgesser.de/sp-ss2012/Intro-MinixFS.pdf +[19]:https://en.wikipedia.org/wiki/Inode_pointer_structure +[20]:https://en.wikipedia.org/wiki/Extended_file_system +[21]:https://en.wikipedia.org/wiki/R%C3%A9my_Card +[22]:https://en.wikipedia.org/wiki/Ext2 +[23]:https://en.wikipedia.org/wiki/Boot_sector +[24]:https://opensource.com/article/17/2/linux-boot-and-startup +[25]:https://en.wikipedia.org/wiki/Ext3 +[26]:https://en.wikipedia.org/wiki/Journaling_file_system +[27]:https://en.wikipedia.org/wiki/Ext4 +[28]:https://en.wikipedia.org/wiki/Year_2038_problem +[29]:https://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/ext4converting.html +[30]:https://en.wikipedia.org/wiki/Hard_link +[31]:https://opensource.com/user/14106/feed +[32]:https://opensource.com/article/17/5/introduction-ext4-filesystem#comments +[33]:https://opensource.com/users/dboth From 22d6d5d67d36541c6160052a4e4a6990978a1a6d Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:03:45 +0800 Subject: [PATCH 03/25] =?UTF-8?q?20170625-1=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... guide to links in the Linux filesystem.md | 311 ++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 sources/tech/20170622 A users guide to links in the Linux filesystem.md diff --git a/sources/tech/20170622 A users guide to links in the Linux filesystem.md b/sources/tech/20170622 A users guide to links in the Linux filesystem.md new file mode 100644 index 0000000000..488557c2e7 --- /dev/null +++ b/sources/tech/20170622 A users guide to links in the Linux filesystem.md @@ -0,0 +1,311 @@ +A user's guide to links in the Linux filesystem +============================================================ + +### Learn how to use links, which make tasks easier by providing access to files from multiple locations in the Linux filesystem directory tree. + + +![A user's guide to links in the Linux filesystem](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/links.png?itok=AumNmse7 "A user's guide to links in the Linux filesystem") +Image by : [Paul Lewin][8]. Modified by Opensource.com. [CC BY-SA 2.0][9] + +In articles I have written about various aspects of Linux filesystems for Opensource.com, including [An introduction to Linux's EXT4 filesystem][10]; [Managing devices in Linux][11]; [An introduction to Linux filesystems][12]; and [A Linux user's guide to Logical Volume Management][13], I have briefly mentioned an interesting feature of Linux filesystems that can make some tasks easier by providing access to files from multiple locations in the filesystem directory tree. + +There are two types of Linux filesystem links: hard and soft. The difference between the two types of links is significant, but both types are used to solve similar problems. They both provide multiple directory entries (or references) to a single file, but they do it quite differently. Links are powerful and add flexibility to Linux filesystems because [everything is a file][14]. + +More Linux resources + +* [What is Linux?][1] + +* [What are Linux containers?][2] + +* [Download Now: Linux commands cheat sheet][3] + +* [Advanced Linux commands cheat sheet][4] + +* [Our latest Linux articles][5] + +I have found, for instance, that some programs required a particular version of a library. When a library upgrade replaced the old version, the program would crash with an error specifying the name of the old, now-missing library. Usually, the only change in the library name was the version number. Acting on a hunch, I simply added a link to the new library but named the link after the old library name. I tried the program again and it worked perfectly. And, okay, the program was a game, and everyone knows the lengths that gamers will go to in order to keep their games running. + +In fact, almost all applications are linked to libraries using a generic name with only a major version number in the link name, while the link points to the actual library file that also has a minor version number. In other instances, required files have been moved from one directory to another to comply with the Linux file specification, and there are links in the old directories for backwards compatibility with those programs that have not yet caught up with the new locations. If you do a long listing of the **/lib64** directory, you can find many examples of both. + +``` +lrwxrwxrwx. 1 root root 36 Dec 8 2016 cracklib_dict.hwm -> ../../usr/share/cracklib/pw_dict.hwm +lrwxrwxrwx. 1 root root 36 Dec 8 2016 cracklib_dict.pwd -> ../../usr/share/cracklib/pw_dict.pwd +lrwxrwxrwx. 1 root root 36 Dec 8 2016 cracklib_dict.pwi -> ../../usr/share/cracklib/pw_dict.pwi +lrwxrwxrwx. 1 root root 27 Jun 9 2016 libaccountsservice.so.0 -> libaccountsservice.so.0.0.0 +-rwxr-xr-x. 1 root root 288456 Jun 9 2016 libaccountsservice.so.0.0.0 +lrwxrwxrwx 1 root root 15 May 17 11:47 libacl.so.1 -> libacl.so.1.1.0 +-rwxr-xr-x 1 root root 36472 May 17 11:47 libacl.so.1.1.0 +lrwxrwxrwx. 1 root root 15 Feb 4 2016 libaio.so.1 -> libaio.so.1.0.1 +-rwxr-xr-x. 1 root root 6224 Feb 4 2016 libaio.so.1.0.0 +-rwxr-xr-x. 1 root root 6224 Feb 4 2016 libaio.so.1.0.1 +lrwxrwxrwx. 1 root root 30 Jan 16 16:39 libakonadi-calendar.so.4 -> libakonadi-calendar.so.4.14.26 +-rwxr-xr-x. 1 root root 816160 Jan 16 16:39 libakonadi-calendar.so.4.14.26 +lrwxrwxrwx. 1 root root 29 Jan 16 16:39 libakonadi-contact.so.4 -> libakonadi-contact.so.4.14.26 +``` + +A few of the links in the **/lib64** directory + +The long listing of the **/lib64** directory above shows that the first character in the filemode is the letter "l," which means that each is a soft or symbolic link. + +### Hard links + +In [An introduction to Linux's EXT4 filesystem][15], I discussed the fact that each file has one inode that contains information about that file, including the location of the data belonging to that file. [Figure 2][16] in that article shows a single directory entry that points to the inode. Every file must have at least one directory entry that points to the inode that describes the file. The directory entry is a hard link, thus every file has at least one hard link. + +In Figure 1 below, multiple directory entries point to a single inode. These are all hard links. I have abbreviated the locations of three of the directory entries using the tilde (**~**) convention for the home directory, so that **~** is equivalent to **/home/user** in this example. Note that the fourth directory entry is in a completely different directory, **/home/shared**, which might be a location for sharing files between users of the computer. + +![fig1directory_entries.png](https://opensource.com/sites/default/files/images/life/fig1directory_entries.png) +Figure 1 + +Hard links are limited to files contained within a single filesystem. "Filesystem" is used here in the sense of a partition or logical volume (LV) that is mounted on a specified mount point, in this case **/home**. This is because inode numbers are unique only within each filesystem, and a different filesystem, for example, **/var**or **/opt**, will have inodes with the same number as the inode for our file. + +Because all the hard links point to the single inode that contains the metadata about the file, all of these attributes are part of the file, such as ownerships, permissions, and the total number of hard links to the inode, and cannot be different for each hard link. It is one file with one set of attributes. The only attribute that can be different is the file name, which is not contained in the inode. Hard links to a single **file/inode** located in the same directory must have different names, due to the fact that there can be no duplicate file names within a single directory. + +The number of hard links for a file is displayed with the **ls -l** command. If you want to display the actual inode numbers, the command **ls -li** does that. + +### Symbolic (soft) links + +The difference between a hard link and a soft link, also known as a symbolic link (or symlink), is that, while hard links point directly to the inode belonging to the file, soft links point to a directory entry, i.e., one of the hard links. Because soft links point to a hard link for the file and not the inode, they are not dependent upon the inode number and can work across filesystems, spanning partitions and LVs. + +The downside to this is: If the hard link to which the symlink points is deleted or renamed, the symlink is broken. The symlink is still there, but it points to a hard link that no longer exists. Fortunately, the **ls** command highlights broken links with flashing white text on a red background in a long listing. + +### Lab project: experimenting with links + +I think the easiest way to understand the use of and differences between hard and soft links is with a lab project that you can do. This project should be done in an empty directory as a  _non-root user_ . I created the **~/temp** directory for this project, and you should, too. It creates a safe place to do the project and provides a new, empty directory to work in so that only files associated with this project will be located there. + +### **Initial setup** + +First, create the temporary directory in which you will perform the tasks needed for this project. Ensure that the present working directory (PWD) is your home directory, then enter the following command. + +``` +mkdir temp +``` + +Change into **~/temp** to make it the PWD with this command. + +``` +cd temp +``` + +To get started, we need to create a file we can link to. The following command does that and provides some content as well. + +``` +du -h > main.file.txt +``` + +Use the **ls -l** long list to verify that the file was created correctly. It should look similar to my results. Note that the file size is only 7 bytes, but yours may vary by a byte or two. + +``` +[dboth@david temp]$ ls -l +total 4 +-rw-rw-r-- 1 dboth dboth 7 Jun 13 07:34 main.file.txt +``` + +Notice the number "1" following the file mode in the listing. That number represents the number of hard links that exist for the file. For now, it should be 1 because we have not created any additional links to our test file. + +### **Experimenting with hard links** + +Hard links create a new directory entry pointing to the same inode, so when hard links are added to a file, you will see the number of links increase. Ensure that the PWD is still **~/temp**. Create a hard link to the file **main.file.txt**, then do another long list of the directory. + +``` +[dboth@david temp]$ ln main.file.txt link1.file.txt +[dboth@david temp]$ ls -l +total 8 +-rw-rw-r-- 2 dboth dboth 7 Jun 13 07:34 link1.file.txt +-rw-rw-r-- 2 dboth dboth 7 Jun 13 07:34 main.file.txt +``` + +Notice that both files have two links and are exactly the same size. The date stamp is also the same. This is really one file with one inode and two links, i.e., directory entries to it. Create a second hard link to this file and list the directory contents. You can create the link to either of the existing ones: **link1.file.txt** or **main.file.txt**. + +``` +[dboth@david temp]$ ln link1.file.txt link2.file.txt ; ls -l +total 16 +-rw-rw-r-- 3 dboth dboth 7 Jun 13 07:34 link1.file.txt +-rw-rw-r-- 3 dboth dboth 7 Jun 13 07:34 link2.file.txt +-rw-rw-r-- 3 dboth dboth 7 Jun 13 07:34 main.file.txt +``` + +Notice that each new hard link in this directory must have a different name because two files—really directory entries—cannot have the same name within the same directory. Try to create another link with a target name the same as one of the existing ones. + +``` +[dboth@david temp]$ ln main.file.txt link2.file.txt +ln: failed to create hard link 'link2.file.txt': File exists +``` + +Clearly that does not work, because **link2.file.txt** already exists. So far, we have created only hard links in the same directory. So, create a link in your home directory, the parent of the temp directory in which we have been working so far. + +``` +[dboth@david temp]$ ln main.file.txt ../main.file.txt ; ls -l ../main* +-rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 main.file.txt +``` + +The **ls** command in the above listing shows that the **main.file.txt** file does exist in the home directory with the same name as the file in the temp directory. Of course, these are not different files; they are the same file with multiple links—directory entries—to the same inode. To help illustrate the next point, add a file that is not a link. + +``` +[dboth@david temp]$ touch unlinked.file ; ls -l +total 12 +-rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 link1.file.txt +-rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 link2.file.txt +-rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 main.file.txt +-rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +Look at the inode number of the hard links and that of the new file using the **-i**option to the **ls** command. + +``` +[dboth@david temp]$ ls -li +total 12 +657024 -rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 link1.file.txt +657024 -rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 link2.file.txt +657024 -rw-rw-r-- 4 dboth dboth 7 Jun 13 07:34 main.file.txt +657863 -rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +Notice the number **657024** to the left of the file mode in the example above. That is the inode number, and all three file links point to the same inode. You can use the **-i** option to view the inode number for the link we created in the home directory as well, and that will also show the same value. The inode number of the file that has only one link is different from the others. Note that the inode numbers will be different on your system. + +Let's change the size of one of the hard-linked files. + +``` +[dboth@david temp]$ df -h > link2.file.txt ; ls -li +total 12 +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 link1.file.txt +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 link2.file.txt +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 main.file.txt +657863 -rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +The file size of all the hard-linked files is now larger than before. That is because there is really only one file that is linked to by multiple directory entries. + +I know this next experiment will work on my computer because my **/tmp**directory is on a separate LV. If you have a separate LV or a filesystem on a different partition (if you're not using LVs), determine whether or not you have access to that LV or partition. If you don't, you can try to insert a USB memory stick and mount it. If one of those options works for you, you can do this experiment. + +Try to create a link to one of the files in your **~/temp** directory in **/tmp** (or wherever your different filesystem directory is located). + +``` +[dboth@david temp]$ ln link2.file.txt /tmp/link3.file.txt +ln: failed to create hard link '/tmp/link3.file.txt' => 'link2.file.txt': +Invalid cross-device link +``` + +Why does this error occur? The reason is each separate mountable filesystem has its own set of inode numbers. Simply referring to a file by an inode number across the entire Linux directory structure can result in confusion because the same inode number can exist in each mounted filesystem. + +There may be a time when you will want to locate all the hard links that belong to a single inode. You can find the inode number using the **ls -li** command. Then you can use the **find** command to locate all links with that inode number. + +``` +[dboth@david temp]$ find . -inum 657024 +./main.file.txt +./link1.file.txt +./link2.file.txt +``` + +Note that the **find** command did not find all four of the hard links to this inode because we started at the current directory of **~/temp**. The **find** command only finds files in the PWD and its subdirectories. To find all the links, we can use the following command, which specifies your home directory as the starting place for the search. + +``` +[dboth@david temp]$ find ~ -samefile main.file.txt +/home/dboth/temp/main.file.txt +/home/dboth/temp/link1.file.txt +/home/dboth/temp/link2.file.txt +/home/dboth/main.file.txt +``` + +You may see error messages if you do not have permissions as a non-root user. This command also uses the **-samefile** option instead of specifying the inode number. This works the same as using the inode number and can be easier if you know the name of one of the hard links. + +### **Experimenting with soft links** + +As you have just seen, creating hard links is not possible across filesystem boundaries; that is, from a filesystem on one LV or partition to a filesystem on another. Soft links are a means to answer that problem with hard links. Although they can accomplish the same end, they are very different, and knowing these differences is important. + +Let's start by creating a symlink in our **~/temp** directory to start our exploration. + +``` +[dboth@david temp]$ ln -s link2.file.txt link3.file.txt ; ls -li +total 12 +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 link1.file.txt +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 link2.file.txt +658270 lrwxrwxrwx 1 dboth dboth 14 Jun 14 15:21 link3.file.txt -> +link2.file.txt +657024 -rw-rw-r-- 4 dboth dboth 1157 Jun 14 14:14 main.file.txt +657863 -rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +The hard links, those that have the inode number **657024**, are unchanged, and the number of hard links shown for each has not changed. The newly created symlink has a different inode, number **658270**. The soft link named **link3.file.txt**points to **link2.file.txt**. Use the **cat** command to display the contents of **link3.file.txt**. The file mode information for the symlink starts with the letter "**l**" which indicates that this file is actually a symbolic link. + +The size of the symlink **link3.file.txt** is only 14 bytes in the example above. That is the size of the text **link3.file.txt -> link2.file.txt**, which is the actual content of the directory entry. The directory entry **link3.file.txt** does not point to an inode; it points to another directory entry, which makes it useful for creating links that span file system boundaries. So, let's create that link we tried before from the **/tmp** directory. + +``` +[dboth@david temp]$ ln -s /home/dboth/temp/link2.file.txt +/tmp/link3.file.txt ; ls -l /tmp/link* +lrwxrwxrwx 1 dboth dboth 31 Jun 14 21:53 /tmp/link3.file.txt -> +/home/dboth/temp/link2.file.txt +``` + +### **Deleting links** + +There are some other things that you should consider when you need to delete links or the files to which they point. + +First, let's delete the link **main.file.txt**. Remember that every directory entry that points to an inode is simply a hard link. + +``` +[dboth@david temp]$ rm main.file.txt ; ls -li +total 8 +657024 -rw-rw-r-- 3 dboth dboth 1157 Jun 14 14:14 link1.file.txt +657024 -rw-rw-r-- 3 dboth dboth 1157 Jun 14 14:14 link2.file.txt +658270 lrwxrwxrwx 1 dboth dboth 14 Jun 14 15:21 link3.file.txt -> +link2.file.txt +657863 -rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +The link **main.file.txt** was the first link created when the file was created. Deleting it now still leaves the original file and its data on the hard drive along with all the remaining hard links. To delete the file and its data, you would have to delete all the remaining hard links. + +Now delete the **link2.file.txt** hard link. + +``` +[dboth@david temp]$ rm link2.file.txt ; ls -li +total 8 +657024 -rw-rw-r-- 3 dboth dboth 1157 Jun 14 14:14 link1.file.txt +658270 lrwxrwxrwx 1 dboth dboth 14 Jun 14 15:21 link3.file.txt -> +link2.file.txt +657024 -rw-rw-r-- 3 dboth dboth 1157 Jun 14 14:14 main.file.txt +657863 -rw-rw-r-- 1 dboth dboth 0 Jun 14 08:18 unlinked.file +``` + +Notice what happens to the soft link. Deleting the hard link to which the soft link points leaves a broken link. On my system, the broken link is highlighted in colors and the target hard link is flashing. If the broken link needs to be fixed, you can create another hard link in the same directory with the same name as the old one, so long as not all the hard links have been deleted. You could also recreate the link itself, with the link maintaining the same name but pointing to one of the remaining hard links. Of course, if the soft link is no longer needed, it can be deleted with the **rm** command. + +The **unlink** command can also be used to delete files and links. It is very simple and has no options, as the **rm** command does. It does, however, more accurately reflect the underlying process of deletion, in that it removes the link—the directory entry—to the file being deleted. + +### Final thoughts + +I worked with both types of links for a long time before I began to understand their capabilities and idiosyncrasies. It took writing a lab project for a Linux class I taught to fully appreciate how links work. This article is a simplification of what I taught in that class, and I hope it speeds your learning curve. + +-------------------------------------------------------------------------------- + +作者简介: + +David Both - David Both is a Linux and Open Source advocate who resides in Raleigh, North Carolina. He has been in the IT industry for over forty years and taught OS/2 for IBM where he worked for over 20 years. While at IBM, he wrote the first training course for the original IBM PC in 1981. He has taught RHCE classes for Red Hat and has worked at MCI Worldcom, Cisco, and the State of North Carolina. He has been working with Linux and Open Source Software for almost 20 years. + +--------------------------------- + +via: https://opensource.com/article/17/6/linking-linux-filesystem + +作者:[David Both ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/dboth +[1]:https://opensource.com/resources/what-is-linux?src=linux_resource_menu +[2]:https://opensource.com/resources/what-are-linux-containers?src=linux_resource_menu +[3]:https://developers.redhat.com/promotions/linux-cheatsheet/?intcmp=7016000000127cYAAQ +[4]:https://developers.redhat.com/cheat-sheet/advanced-linux-commands-cheatsheet?src=linux_resource_menu&intcmp=7016000000127cYAAQ +[5]:https://opensource.com/tags/linux?src=linux_resource_menu +[6]:https://opensource.com/article/17/6/linking-linux-filesystem?rate=YebHxA-zgNopDQKKOyX3_r25hGvnZms_33sYBUq-SMM +[7]:https://opensource.com/user/14106/feed +[8]:https://www.flickr.com/photos/digypho/7905320090 +[9]:https://creativecommons.org/licenses/by/2.0/ +[10]:https://opensource.com/article/17/5/introduction-ext4-filesystem +[11]:https://opensource.com/article/16/11/managing-devices-linux +[12]:https://opensource.com/life/16/10/introduction-linux-filesystems +[13]:https://opensource.com/business/16/9/linux-users-guide-lvm +[14]:https://opensource.com/life/15/9/everything-is-a-file +[15]:https://opensource.com/article/17/5/introduction-ext4-filesystem +[16]:https://opensource.com/article/17/5/introduction-ext4-filesystem#fig2 +[17]:https://opensource.com/users/dboth +[18]:https://opensource.com/article/17/6/linking-linux-filesystem#comments From 36a4294cc897728245289939e441813fda7eabd6 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:09:00 +0800 Subject: [PATCH 04/25] =?UTF-8?q?20170625-2=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...Linux Still Surprises and Motivates Him.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 sources/talk/20170622 Linus Torvalds Explains How Linux Still Surprises and Motivates Him.md diff --git a/sources/talk/20170622 Linus Torvalds Explains How Linux Still Surprises and Motivates Him.md b/sources/talk/20170622 Linus Torvalds Explains How Linux Still Surprises and Motivates Him.md new file mode 100644 index 0000000000..6d2013d845 --- /dev/null +++ b/sources/talk/20170622 Linus Torvalds Explains How Linux Still Surprises and Motivates Him.md @@ -0,0 +1,58 @@ +Linus Torvalds Explains How Linux Still Surprises and Motivates Him +============================================================ + +![Linus Torvalds](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/linus-torvalds-lc3.jpg?itok=lzZupevU "Linus Torvalds") +Linux Torvalds spoke with Dirk Hohndel in one of their famous “fireside chats” this week at LinuxCon China.[The Linux Foundation][1] + +Linus Torvalds took to the stage in China for the first time Monday at [LinuxCon + ContainerCon + CloudOpen China in Beijing][3]. In front of a crowd of nearly 2,000, Torvalds spoke with VMware Head of Open Source Dirk Hohndel in one of their famous “fireside chats” about what motivates and surprises him and how aspiring open source developers can get started. Here are some highlights of their talk. + +**What’s surprising about Linux development** + +“What I find interesting is code that I thought was stable continually gets improved. There are things we haven’t touched for many years, then someone comes along and improves them or makes bug reports in something I thought no one used. We have new hardware, new features that are developed, but after 25 years, we still have old, very basic things that people care about and still improve.” + +**What motivates him** + +“I really like what I’m doing. I like waking up and having a job that is technically interesting and challenging without being too stressful so I can do it for long stretches; something where I feel I am making a real difference and doing something meaningful not just for me.” + +“I occasionally have taken breaks from my job. The 2-3 weeks I worked on Git to get that started for example. But every time I take a longer break, I get bored. When I go diving for a week, I look forward to getting back. I never had the feeling that I need to take a longer break.” + +**The future of Linux leadership** + +“Our processes have not only worked for 25 years, we still have a very strong maintainer group. We complain that we don’t have enough maintainers – which is true, we only have tens of top maintainers who do the daily work of merging stuff. That’s a strong team for an open source project. And as these maintainers get older and fatter, we have new people coming in. It takes years to go from a new developer to a top maintainer, so I don’t feel that we should necessarily worry about the process and Linux for the next 20 years.” + +**Will Linux be replaced** + +“Maybe some new aggressive project will come along and show they can do what we do better, but I don’t worry about that. There have been lots of very successful forks of Linux. What makes people not think of them as forks is that they are harmonious. If someone says they want to do this and change everything and make the kernel so much better, my feeling is do it, prove yourself. I may think it’s a bad idea, but you can prove me wrong.” + +**Thoughts on Git** + +“I’m very surprised about how widely Git has spread. I’m pleased obviously, and it validates my notion of doing distributed development. At the same time, looking at most source control versions, it tends to be a huge slog and difficult to introduce a new software control version. I expected it to be limited mostly to the kernel -- as it’s tailored to what we do.” + +“For the first 3 to 4 years, the complaint about Git was it was so different and hard to use. About 5 years ago something changed. Enough projects and developers had started using Git that it wasn’t different anymore; it was what people were used to. They started taking advantage of the development model and the feeling of security that using Git meant nothing would be corrupted or lost.” + +“In certain circles, Git is more well known than Linux. Linux is often hidden – on an Android phone you’re running Linux, but you don’t think about it. With Git, you know you are using Git.” + +**Forking Linux** + +“When I sat down and wrote Git, a prime principle was that you should be able to fork and go off on your own and do something on your own. If you have forks that are friendly -- the type that prove me wrong and do something interesting that improves the kernel -- in that situation, someone can come back and say they actually improved the kernel and there are no bad feelings. I’ll take your improved code and merge it back. That’s why you should encourage forks. You also want to make it easy to take back the good ones.” + +**How to get started as an open source developer** + +“For me, I was always self-motivated and knew what I wanted to do. I was never told what I should look at doing. I’m not sure my example is the right thing for people to follow. There are a ton of open source projects and, if you are a beginning programmer, find something you’re interested in that you can follow for more than just a few weeks. Get to know the code so well that you get to the point where you are an expert on a code piece. It doesn’t need to be the whole project. No one is an expert on the whole kernel, but you can know an area well.   + +If you can be part of a community and set up patches, it’s not just about the coding, but about the social aspect of open source. You make connections and improve yourself as a programmer. You are basically showing off – I made these improvements, I’m capable of going far in my community or job. You’ll have to spend a certain amount of time to learn a project, but there’s a huge upside -- not just from a career aspect, but having an amazing project in your life.” + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/event/lc3-china/20176/6/linus-torvalds-explains-how-linux-still-surprises-and-motivates-him + +作者:[ THE LINUX FOUNDATION][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/lfadmin +[1]:https://www.linux.com/licenses/category/linux-foundation +[2]:https://www.linux.com/files/images/linus-torvalds-lc3jpg +[3]:https://www.lfasiallc.com/linuxcon-containercon-cloudopen-china From 088e8b0435ad0625fc5482b94bd65e85cba32a28 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:10:53 +0800 Subject: [PATCH 05/25] =?UTF-8?q?20170625-3=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...te to open source when you have no time.md | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 sources/tech/20170622 8 ways to contribute to open source when you have no time.md diff --git a/sources/tech/20170622 8 ways to contribute to open source when you have no time.md b/sources/tech/20170622 8 ways to contribute to open source when you have no time.md new file mode 100644 index 0000000000..a5b52f6da9 --- /dev/null +++ b/sources/tech/20170622 8 ways to contribute to open source when you have no time.md @@ -0,0 +1,95 @@ +8 ways to contribute to open source when you have no time +============================================================ + +### Find the time in your busy life to give back to the projects you care about. + +![8 ways to contribute to open source when you have no time](https://opensource.com/sites/default/files/styles/image-full-size/public/images/law/LAW-patent_reform_520x292_10136657_1012_dc.png?itok=zLMswcrw "8 ways to contribute to open source when you have no time") +Image by : opensource.com + +One of the [most common reasons][3] people give for not contributing (or not contributing more) to open source is a lack of time. I get it; life is challenging, and there are so many priorities vying for your limited attention. So how can you find the time in your busy life to contribute to the open source projects you care about? + +In the interest of full disclosure, I should warn you that I was late getting this article to the editors because I couldn't find the time to work on it. Take my advice at your own risk. + +### Figure out what you care about + +The first step in contributing is to figure out what exactly you're making time for. Do you have a project of your own that you want to work on? Is there a specific project that you use that you want to help with? Do you just want to do  _something_ ? Figuring out what you're making time for will help you decide where in your life's priorities it belongs. + +### Find alternate ways to contribute + +Writing a new feature can take many hours of design, coding, and testing. It's not always easy to work on that for a few minutes, step away, and then pick up where you left off. If you never get more than 30 minutes of uninterrupted effort, you might find yourself pretty frustrated if you try to take on a big task. + +But there are other ways to contribute that might satisfy your need to give back within the time you have available. Some of them can be done in quick spurts from a smartphone, which means you can take the time you used to spend avoiding people on your commute and put it toward your open source contributions. Here's a list of some things that can be done in small chunks: + +* **Bug triage:** Do all of the bug reports have the information necessary to diagnose and resolve them? Are they properly filed (to the right area, with the right severity, etc.)? + +* **Mailing list support:** Are users or other contributors asking questions on the mailing list? Maybe you can help. + +* **Documentation patches:** Documentation can often (but not always) be worked on in smaller chunks than code. Maybe there are a few places you can fill in. Or maybe it's time to run through the docs and make sure they're still accurate. + +* **Marketing:** Talk about your project or community on social media. Write a quick blog post. Vote and comment on news aggregators. + +### Talk to your boss + +You might think you can't work on open source projects during the workday, but have you  _asked_ ? Particularly if the project somehow relates to your day job, you might be able to sell your boss on letting you make contributions while at work. Note that there may be some intellectual property issues (e.g., who owns the rights to the code you contribute during working hours), so do your research first and get the conditions in writing. + +### Set deadlines + +The best time management advice I ever received can be summarized with two rules: + +1. If it's going to get done, it has to have a deadline + +2. It's okay to change a deadline + +This article had a deadline. There's no particular time sensitivity to it, but a deadline meant that I defined when I wanted to get it done and gave the editors a sense of when it might be submitted. And yes, as I said above, I missed the deadline. You know what happened? I set a new deadline (second time's a charm!). + +If something  _is_  time-sensitive, set the deadline well ahead to give yourself some space if you need to push it back a time or two. + +### Put it on your calendar + +If you use a calendar to schedule the rest of your life, scheduling some time to work on your open source project may be the only way to get it done. How much time you schedule is up to you, but even if you block off only one hour once a week as open source time, that still gives you an hour a week of open source time. + +And here's a secret: It's okay to cancel on yourself sometimes if you need the time to do something else—or do nothing at all. + +### Reclaim unused time + +Are you bored on your commute? Are you having trouble falling asleep at night? Maybe you can use that time to contribute. Now I happen to think the "work 169 hours a week at full tilt" lifestyle is a terrible, terrible thing. That said, some nights you just can't fall asleep. Instead of lying in bed, seeing what your Twitter friends on the other side of the world are up to (which I do), maybe you can work on that contribution you've been meaning to get around to. Just don't make a habit out of forgoing sleep. + +### Stop + +Sometimes the best way to contribute is to not contribute for a little bit. You're a busy person and no matter how awesome you are, you can't avoid your physiological and psychological needs. They will catch up to you. Taking a little time to refresh yourself might improve your productivity enough that you get stuff done faster, and suddenly there's time for you to make those open source contributions you've been meaning to get around to. + +### Say "no" + +I am bad at this. So very bad. But none of us can do everything we'd like to do. Sometimes the best thing you can do to contribute is to stop contributing in the same way you have been—or not contribute at all (see above). + +Several years ago, I led the Fedora documentation team. The team's tradition was that the leader would offer to step aside at the end of each release. I had done that a time or two and nobody stepped up, so I remained in the role. But after my second or third release, I made it clear that I would not be continuing as the team lead. I still enjoyed the work, but I was working full time, in graduate school half time, and my wife was pregnant with our first child. There was no way I could consistently give the level of effort that was required, so I stepped aside. I continued to contribute, but in a less-demanding capacity. + +If you're getting to the point where you struggle to find the time to meet your obligations (self-imposed or not), then perhaps it's time to reconsider your role. This can be especially hard with a project that you founded or have made a considerable investment in. But sometimes you have to—for your own good and that of the project. + +### What else? + +How do you find time to make your contributions? Let us know in the comments. + +-------------------------------------------------------------------------------- + +作者简介: + +Ben Cotton - Ben Cotton is a meteorologist by training and a high-performance computing engineer by trade. Ben works as a technical evangelist at Cycle Computing. He is a Fedora user and contributor, co-founded a local open source meetup group, and is a member of the Open Source Initiative and a supporter of Software Freedom Conservancy. Find him on Twitter (@FunnelFiasco) or at + + +---------- + +via: https://opensource.com/article/17/6/find-time-contribute + +作者:[Ben Cotton ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/bcotton +[1]:https://opensource.com/article/17/6/find-time-contribute?rate=qWRgPXlhEZchh_vXEplj6jLXd7P0QCwzxZFWYkqawCc +[2]:https://opensource.com/user/30131/feed +[3]:http://naramore.net/blog/why-people-don-t-contribute-to-os-projects-and-what-we-can-do-about-it +[4]:https://opensource.com/users/bcotton +[5]:https://opensource.com/article/17/6/find-time-contribute#comments From 7512f734da479b29e33740390ca08ceb92935350 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:12:21 +0800 Subject: [PATCH 06/25] =?UTF-8?q?20170625-4=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...oduction to creating documents in LaTeX.md | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 sources/tech/20170623 A introduction to creating documents in LaTeX.md diff --git a/sources/tech/20170623 A introduction to creating documents in LaTeX.md b/sources/tech/20170623 A introduction to creating documents in LaTeX.md new file mode 100644 index 0000000000..498c0f45ce --- /dev/null +++ b/sources/tech/20170623 A introduction to creating documents in LaTeX.md @@ -0,0 +1,149 @@ +A introduction to creating documents in LaTeX +============================================================ + +### Learn to typeset documents in the LaTeX text markup language. + +![A introduction to creating documents in LaTeX](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/idea_innovation_kid_education.png?itok=jpetC9wJ "A introduction to creating documents in LaTeX") +Image by : opensource.com + +LaTeX (pronounced  _lay-tech_ ) is a method of creating documents using plain text, stylized using markup tags, similar to HTML/CSS or Markdown. LaTeX is most commonly used to create documents for academia, such as academic journals. In LaTeX, the author doesn't stylize the document directly, like in a word processor such as Microsoft Word, LibreOffice Writer, or Apple Pages; instead they write code in plain text that must be compiled to produce a PDF document. + +### [intro.png][1] + +![computer screen with LaTeX markup language](https://opensource.com/sites/default/files/u128651/intro.png "computer screen with LaTeX markup language") + +### How to get started + +To write in LaTeX, you'll need to install a LaTeX editor. I use a piece of free and open source software (FOSS) popular with academics called [TexStudio][8], which runs on Windows, Unix/Linux, BSD, and Mac OS X. You'll also need to install a distribution of the **Tex** typesetting system. I am writing on MacOS, so I use a distribution called [MacTex or BasicTex][9]. For Windows you can use [MiKTex][10], and Linux users should be able to find it in their repository. + +Once you have downloaded TexStudio and a distribution of LaTeX, you should be ready to start typesetting your documents. + +### Create your first document + +In this short tutorial, we'll create a simple article with a headline, a subhead, and two paragraphs. + +After you launch TexStudio, save your new document. (I called mine **helloworld.tex**, since I'm writing this tutorial in the Hello, World! tradition from programming.) Next, you need to add some boilerplate code at the top of your **.tex** file that specifies the type and size of your document. This is similar to the boilerplate code used in HTML5 documents. + +My code (below) sets the page size to A4 and the text size to 12pt. You can put this code into TexStudio and edit it with your own page size, font size, name, title, and other details: + +``` +\documentclass[a4paper,12pt]{article} +\begin{document} +\title{Hello World! My first LaTeX document} +\author{Aaron Cocker} +\date{\today} +\maketitle + +content will go here + +\end{document} +``` + +Next, click on the large green arrow to compile the document. That's the middle button in the screenshot below. + +### [compile.png][2] + +![compile button in TexStudio](https://opensource.com/sites/default/files/u128651/compile.png "compile button in TexStudio") + +If there are any errors, they'll appear in the dialog box at the bottom. + +After you compile the document, you can see what it will look like by viewing a PDF within the program as a sort of WYSIWYG preview. Remember it must be recompiled whenever you make a change to the code, as you would when programming in C++, for example. + +To view your document, click on **Tools > Commands > View PDF**, as shown in the screenshot below. + +### [view_as_pdf.png][3] + +![Menu to view a PDF](https://opensource.com/sites/default/files/u128651/view_as_pdf.png "Menu to view a PDF") + +The PDF output will be shown on the right, like this: + +### [pdf_output.png][4] + +![Viewing the LaTeX code as PDF](https://opensource.com/sites/default/files/u128651/pdf_output.png "Viewing the LaTeX code as PDF") + +Now you can add a paragraph. First give it a subhead by using the **\section{}**command. Type the subhead title between the curly braces of the command; I called my subhead **Introduction**. + +``` +\section{Introduction} +``` + +Now that you have labeled the paragraph with its subhead, it's time to write the paragraph. For this example, I used the Lipsum [lorem ipsum generator][11]. To create the paragraph, type the **\paragraph{}** command, then add your text  _underneath_ ,  _NOT within_ , the curly braces, inserted between **\maketitle** and **\end{document}**. + +This is what my paragraph code looks like: + +``` +\section{Introduction} + +\paragraph{} +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas sollicitudin. + +\paragraph{} +Mauris efficitur vitae ex id egestas. Vestibulum ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non elementum leo. Nullam molestie congue placerat. Phasellus tempor et libero maximus commodo. +``` + +Your document is now finished, so you can export and save it as a PDF file by using **Save As** (just as you would with most programs). + +Here's what my finished document and the corresponding code look like: + +### [finished_document.png][5] + +![The finished document with code and the PDF output side-by-side](https://opensource.com/sites/default/files/u128651/finished_document.png "The finished document with code and the PDF output side-by-side") + +All my code from this tutorial is available below: + +``` +\documentclass[a4paper,12pt]{article} +\begin{document} +\title{Hello World! My first LaTeX document} +\author{Aaron Cocker} +\date{\today} +\maketitle + +\section{Introduction} + +\paragraph{} +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas sollicitudin. + +\paragraph{} +Mauris efficitur vitae ex id egestas. Vestibulum ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non elementum leo. Nullam molestie congue placerat. Phasellus tempor et libero maximus commodo. + +\end{document} +``` + +### Learn more + +Among the thousands of excellent resources on writing in LaTeX are the guides produced by most universities, which are indexable and can be found on Google search. [Princeton University][12] offers a good extended tutorial, and for a deeper dive, the Princeton guide's creator, Donald Knuth, offers [The TexBook][13], the ultimate guide to LaTeX. + +-------------------------------------------------------------------------------- + +作者简介: + +Aaron Cocker - BSc Computing student attending university in the UK. I am an aspiring Data Scientist. My favourite language is Python. Feel free to contact me at aaron@aaroncocker.org.uk or visit my personal website: https://aaroncocker.org.uk + + +--------------- + +via: https://opensource.com/article/17/6/introduction-latex + +作者:[ Aaron Cocker][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/aaroncocker +[1]:https://opensource.com/file/356521 +[2]:https://opensource.com/file/356526 +[3]:https://opensource.com/file/356541 +[4]:https://opensource.com/file/356536 +[5]:https://opensource.com/file/356531 +[6]:https://opensource.com/article/17/6/introduction-latex?rate=n5CmhY55ZhQRMjd6n5-f2p9f7iGg0nAWh_Bi6jqMMyc +[7]:https://opensource.com/user/123226/feed +[8]:http://www.texstudio.org/ +[9]:https://www.tug.org/mactex/morepackages.html +[10]:https://miktex.org/download +[11]:http://www.lipsum.com/feed/html +[12]:https://www.cs.princeton.edu/courses/archive/spr10/cos433/Latex/latex-guide.pdf +[13]:http://www.ctex.org/documents/shredder/src/texbook.pdf +[14]:https://opensource.com/users/aaroncocker +[15]:https://opensource.com/article/17/6/introduction-latex#comments From 7ac8060f4160d71316e533b2fa210f4ea8a9aa2e Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:13:37 +0800 Subject: [PATCH 07/25] =?UTF-8?q?20170625-5=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...o avoid when learning to code in Python.md | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 sources/tech/20170623 3 mistakes to avoid when learning to code in Python.md diff --git a/sources/tech/20170623 3 mistakes to avoid when learning to code in Python.md b/sources/tech/20170623 3 mistakes to avoid when learning to code in Python.md new file mode 100644 index 0000000000..3588fa07fd --- /dev/null +++ b/sources/tech/20170623 3 mistakes to avoid when learning to code in Python.md @@ -0,0 +1,225 @@ +3 mistakes to avoid when learning to code in Python +============================================================ + +### These errors created big problems that took hours to solve. + +![3 mistakes to avoid when learning to code in Python](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/blocks_building.png?itok=q0_Wo8Tr "3 mistakes to avoid when learning to code in Python") +Image by : opensource.com + +It's never easy to admit when you do things wrong, but making errors is part of any learning process, from learning to walk to learning a new programming language, such as Python. + +Here's a list of three things I got wrong when I was learning Python, presented so that newer Python programmers can avoid making the same mistakes. These are errors that either I got away with for a long time or that that created big problems that took hours to solve. + +Take heed young coders, some of these mistakes are afternoon wasters! + +### 1\. Mutable data types as default arguments in function definitions + +It makes sense right? You have a little function that, let's say, searches for links on a current page and optionally appends it to another supplied list. + +``` +def search_for_links(page, add_to=[]): +    new_links = page.search_for_links() +    add_to.extend(new_links) +    return add_to +``` + +On the face of it, this looks like perfectly normal Python, and indeed it is. It works. But there are issues with it. If we supply a list for the **add_to** parameter, it works as expected. If, however, we let it use the default, something interesting happens. + +Try the following code: + +``` +def fn(var1, var2=[]): +    var2.append(var1) +    print var2 + +fn(3) +fn(4) +fn(5) +``` + +You may expect that we would see: + +**[3] +[4] +[5]** + +But we actually see this: + +**[3] +[3, 4] +[3, 4, 5]** + +Why? Well, you see, the same list is used each time. In Python, when we write the function like this, the list is instantiated as part of the function's definition. It is not instantiated each time the function is run. This means that the function keeps using the exact same list object again and again, unless of course we supply another one: + +``` +fn(3, [4]) +``` + +**[4, 3]** + +Just as expected. The correct way to achieve the desired result is: + +``` +def fn(var1, var2=None): +    if not var2: +        var2 = [] +    var2.append(var1) +``` + +Or, in our first example: + +``` +def search_for_links(page, add_to=None): +    if not add_to: +        add_to = [] +    new_links = page.search_for_links() +    add_to.extend(new_links) +    return add_to +``` + +This moves the instantiation from module load time so that it happens every time the function runs. Note that for immutable data types, like [**tuples**][7], [**strings**][8], or [**ints**][9], this is not necessary. That means it is perfectly fine to do something like: + +``` +def func(message="my message"): +    print message +``` + +### 2\. Mutable data types as class variables + +Hot on the heels of the last error is one that is very similar. Consider the following: + +``` +class URLCatcher(object): +    urls = [] + +    def add_url(self, url): +        self.urls.append(url) +``` + +This code looks perfectly normal. We have an object with a storage of URLs. When we call the **add_url** method, it adds a given URL to the store. Perfect right? Let's see it in action: + +``` +a = URLCatcher() +a.add_url('http://www.google.') +b = URLCatcher() +b.add_url('http://www.bbc.co.') +``` + +**b.urls +['[http://www.google.com][2]', '[http://www.bbc.co.uk][3]']** + +**a.urls +['[http://www.google.com][4]', '[http://www.bbc.co.uk][5]']** + +Wait, what?! We didn't expect that. We instantiated two separate objects, **a** and **b**. **A** was given one URL and **b** the other. How is it that both objects have both URLs? + +Turns out it's kinda the same problem as in the first example. The URLs list is instantiated when the class definition is created. All instances of that class use the same list. Now, there are some cases where this is advantageous, but the majority of the time you don't want to do this. You want each object to have a separate store. To do that, we would modify the code like: + +``` +class URLCatcher(object): +    def __init__(self): +        self.urls = [] + +    def add_url(self, url): +        self.urls.append(url) +``` + +Now the URLs list is instantiated when the object is created. When we instantiate two separate objects, they will be using two separate lists. + +### 3\. Mutable assignment errors + +This one confused me for a while. Let's change gears a little and use another mutable datatype, the [**dict**][10]. + +``` +a = {'1': "one", '2': 'two'} +``` + +Now let's assume we want to take that **dict** and use it someplace else, leaving the original intact. + +``` +b = a + +b['3'] = 'three' +``` + +Simple eh? + +Now let's look at our original dict, **a**, the one we didn't want to modify: + +``` +{'1': "one", '2': 'two', '3': 'three'} +``` + +Whoa, hold on a minute. What does **b** look like then? + +``` +{'1': "one", '2': 'two', '3': 'three'} +``` + +Wait what? But… let's step back and see what happens with our other immutable types, a **tuple** for instance: + +``` +c = (2, 3) +d = c +d = (4, 5) +``` + +Now **c** is: +**(2, 3)** + +While **d** is: +**(4, 5)** + +That functions as expected. So what happened in our example? When using mutable types, we get something that behaves a little more like a pointer from C. When we said **b = a** in the code above, what we really meant was: **b** is now also a reference to **a**. They both point to the same object in Python's memory. Sound familiar? That's because it's similar to the previous problems. In fact, this post should really have been called, "The Trouble with Mutables." + +Does the same thing happen with lists? Yes. So how do we get around it? Well, we have to be very careful. If we really need to copy a list for processing, we can do so like: + +``` +b = a[:] +``` + +This will go through and copy a reference to each item in the list and place it in a new list. But be warned: If any objects in the list are mutable, we will again get references to those, rather than complete copies. + +Imagine having a list on a piece of paper. In the original example, Person A and Person B are looking at the same piece of paper. If someone changes that list, both people will see the same changes. When we copy the references, each person now has their own list. But let's suppose that this list contains places to search for food. If "fridge" is first on the list, even when it is copied, both entries in both lists point to the same fridge. So if the fridge is modified by Person A, by say eating a large gateaux, Person B will also see that the gateaux is missing. There is no easy way around this. It is just something that you need to remember and code in a way that will not cause an issue. + +Dicts function in the same way, and you can create this expensive copy by doing: + +``` +b = a.copy() +``` + +Again, this will only create a new dictionary pointing to the same entries that were present in the original. Thus, if we have two lists that are identical and we modify a mutable object that is pointed to by a key from dict 'a', the dict object present in dict 'b' will also see those changes. + +The trouble with mutable data types is that they are powerful. None of the above are real problems; they are things to keep in mind to prevent issues. The expensive copy operations presented as solutions in the third item are unnecessary 99% of the time. Your program can and probably should be modified so that those copies are not even required in the first place. + + _Happy coding! And feel free to ask questions in the comments._ + +-------------------------------------------------------------------------------- + +作者简介: + +Pete Savage - Peter is a passionate Open Source enthusiast who has been promoting and using Open Source products for the last 10 years. He has volunteered in many different areas, starting in the Ubuntu community, before moving off into the realms of audio production and later into writing. Career wise he spent much of his early years managing and building datacenters as a sysadmin, before ending up working for Red Hat as a Principal Quailty Engineer for the CloudForms product. He occasionally pops out a + +----------------- + +via: https://opensource.com/article/17/6/3-things-i-did-wrong-learning-python + +作者:[Pete Savage ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/psav +[1]:https://opensource.com/article/17/6/3-things-i-did-wrong-learning-python?rate=SfClhaQ6tQsJdKM8-YTNG00w53fsncvsNWafwuJbtqs +[2]:http://www.google.com/ +[3]:http://www.bbc.co.uk/ +[4]:http://www.google.com/ +[5]:http://www.bbc.co.uk/ +[6]:https://opensource.com/user/36026/feed +[7]:https://docs.python.org/2/library/functions.html?highlight=tuple#tuple +[8]:https://docs.python.org/2/library/string.html +[9]:https://docs.python.org/2/library/functions.html#int +[10]:https://docs.python.org/2/library/stdtypes.html?highlight=dict#dict +[11]:https://opensource.com/users/psav +[12]:https://opensource.com/article/17/6/3-things-i-did-wrong-learning-python#comments From a2c8e0ecba5b279d8b37c86e74695b315e679d6d Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:15:51 +0800 Subject: [PATCH 08/25] =?UTF-8?q?20170625-6=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LC3 --- ...dump for examining Linux Kernel crashes.md | 313 ++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 sources/tech/20170621 Using Kdump for examining Linux Kernel crashes.md diff --git a/sources/tech/20170621 Using Kdump for examining Linux Kernel crashes.md b/sources/tech/20170621 Using Kdump for examining Linux Kernel crashes.md new file mode 100644 index 0000000000..d22db18362 --- /dev/null +++ b/sources/tech/20170621 Using Kdump for examining Linux Kernel crashes.md @@ -0,0 +1,313 @@ +Using Kdump for examining Linux Kernel crashes +============================================================ + +### Let's examine the basics of kdump usage and look at the internals of kdump/kexec kernel implementation. + +![Using Kdump for examining Linux Kernel crashes](https://opensource.com/sites/default/files/styles/image-full-size/public/images/life/linux_boot.png?itok=pSGmf8Ca "Using Kdump for examining Linux Kernel crashes") +Image by :  + +[Penguin][13], [Boot][14]. Modified by Opensource.com. [CC BY-SA 4.0][15]. + +[Kdump][16] is a way to acquire a crashed Linux kernel dump, but finding documents that explain its usage and internals can be challenging. In this article, I'll examine the basics of kdump usage and look at the internals of kdump/kexec kernel implementation. + +[Kexec][17] is a Linux kernel-to-kernel boot loader that helps to boot the second kernel from the context of first kernel. Kexec shuts down the first kernel, bypasses the BIOS or firmware stage, and jumps to second kernel. Thus, reboots become faster in absence of the BIOS stage. + +Kdump can be used with the kexec application—for example, when the second kernel is booted when the first kernel panics, the second kernel is used to copy the memory dump of first kernel, which can be analyzed with tools such as gdb and crash to determine the panic reasons. (In this article, I'll use the terms  _first kernel_  for the currently running kernel,  _second kernel_  for the kernel run using kexec, and  _capture kernel_  for kernel run when current kernel panics.) + +More Linux resources + +* [What is Linux?][1] + +* [What are Linux containers?][2] + +* [Download Now: Linux commands cheat sheet][3] + +* [Advanced Linux commands cheat sheet][4] + +* [Our latest Linux articles][5] + +The kexec mechanism has components in the kernel as well as in user space. The kernel provides few system calls for kexec reboot functionality. A user space tool called kexec-tools uses those calls and provides an executable to load and boot the second kernel. Sometimes a distribution also adds wrappers on top of kexec-tools, which helps capture and save the dump for various dump target configurations. In this article, I will use the name  _distro-kexec-tools_  to avoid confusion between upstream kexec-tools and distro-specific kexec-tools code. My example will use the Fedora Linux distribution. + +### Fedora kexec-tools + +**dnf install kexec-tools** installs fedora-kexec-tools on Fedora machines. The kdump service can be started by executing **systemctl start kdump** after installation of fedora-kexec-tools. When this service starts, it creates a root file system (initramfs) that contains resources to mount the target for saving vmcore, and a command to copy/dump vmcore to the target. This service then loads the kernel and initramfs at the suitable location within the crash kernel region so that they can be executed upon kernel panic. + +Fedora wrapper provides two user configuration files: + +1. **/etc/kdump.conf** specifies configuration parameters whose modification requires rebuild of the initramfs. For example, if you change the dump target from a local disk to an NFS-mounted disk, you will need NFS-related kernel modules to be loaded by the capture kernel. + +2. **/etc/sysconfig/kdump** specifies configuration parameters whose modification do not require rebuild of the initramfs. For example, you do not need to rebuild the initramfs if you only need to modify command-line arguments passed to the capture kernel. + +If the kernel panics after the kdump service starts, then the capture kernel is executed, which further executes the vmcore save process from initramfs and reboots to a stable kernel afterward. + +### kexec-tools + +Compilation of kexec-tools source code provides an executable called **kexec**. The same executable can be used to load and execute a second kernel or to load a capture kernel, which can be executed upon kernel panic. + +A typical command to load a second kernel: + +``` +# kexec -l kernel.img --initrd=initramfs-image.img –reuse-cmdline +``` + +**--reuse-command** line says to use the same command line as that of first kernel. Pass initramfs using **--initrd**. **-l** says that you are loading the second kernel, which can be executed by the kexec application itself (**kexec -e**). A kernel loaded using **-l** cannot be executed at kernel panic. You must pass **-p**instead of **-l** to load the capture kernel that can be executed upon kernel panic. + +A typical command to load a capture kernel: + +``` +# kexec -p kernel.img --initrd=initramfs-image.img –reuse-cmdline +``` + +**echo c > /pros/sysrq-trigger** can be used to crash the kernel for test purposes. See **man kexec** for detail about options provided by kexec-tools. Before moving to the next section, which focuses on internal implementation, watch this kexec_dump demo: + + ** 此处有iframe,请手动处理 ** + +### Kdump: End-to-end flow + +Figure 1 shows a flow diagram. Crashkernel memory must be reserved for the capture kernel during booting of the first kernel. You can pass **crashkernel=Y@X** in the kernel command line, where **@X** is optional. **crashkernel=256M** works with most of the x86_64 systems; however, selecting a right amount of memory for the crash kernel is dependent on many factors, such as kernel size and initramfs, as well as runtime memory requirement of modules and applications included in initramfs. See the [kernel-parameters documentation][18] for more ways to pass crash kernel arguments. + +![pratyush_f1.png](https://opensource.com/sites/default/files/images/life/pratyush_f1.png) + +You can pass kernel and initramfs images to a **kexec** executable as shown in the typical command of section (**kexec-tools**). The capture kernel can be the same as the first kernel or can be different. Typically, keep it the same. Initramfs can be optional; for example, when the kernel is compiled with **CONFIG_INITRAMFS_SOURCE**, you do not need it. Typically, you keep a different capture initramfs from the first initramfs, because automating a copy of vmcore in capture initramfs is better. When **kexec** is executed, it also loads **elfcorehdr** data and the purgatory executable. **elfcorehdr** has information about the system RAM memory organization, and purgatory is a binary that executes before the capture kernel executes and verifies that the second stage binary/data have the correct SHA. Purgatory can be made optional as well. + +When the first kernel panics, it does a minimal necessary exit process and switches to purgatory if it exists. Purgatory verifies SHA256 of loaded binaries and, if those are correct, then it passes control to the capture kernel. The capture kernel creates vmcore per the system RAM information received from **elfcorehdr**. Thus, you will see a dump of the first kernel in /proc/vmcore after the capture kernel boots. Depending on the initramfs you have used, you can now analyze the dump, copy it to any disk, or there can be an automated copy followed by reboot to a stable kernel. + +### Kernel system calls + +The kernel provides two system calls—**kexec_load()** and **kexec_file_load()**, which can be used to load the second kernel when **kexec -l** is executed. It also provides an extra flag for the **reboot()** system call, which can be used to boot into second kernel using **kexec -e**. + +**kexec_load()**: The **kexec_load()** system call loads a new kernel that can be executed later by **reboot()**. Its prototype is defined as follows: + +``` +long kexec_load(unsigned long entry, unsigned long nr_segments, +struct kexec_segment *segments, unsigned long flags); +``` + +User space needs to pass segments for different components, such as kernel, initramfs, etc. Thus, the **kexec** executable helps in preparing these segments. The structure of **kexec_segment** looks like as follows: + +``` +struct kexec_segment { + void *buf; + /* Buffer in user space */ + size_t bufsz; + /* Buffer length in user space */ + void *mem; + /* Physical address of kernel */ + size_t memsz; + /* Physical address length */ +}; +``` + +When **reboot()** is called with **LINUX_REBOOT_CMD_KEXEC**, it boots into a kernel loaded by **kexec_load()**. If a flag **KEXEC_ON_CRASH** is passed to **kexec_load()**, then the loaded kernel will not be executed with **reboot(LINUX_REBOOT_CMD_KEXEC)**; rather, that will be executed on kernel panic. **CONFIG_KEXEC** must be defined to use kexec and **CONFIG_CRASH_DUMP** should be defined for kdump. + +**kexec_file_load()**: As a user you pass only two arguments (i.e., kernel and initramfs) to the **kexec** executable. **kexec** then reads data from sysfs or other kernel information source and creates all segments. So, **kexec_file_load()**gives you simplification in user space, where you pass only file descriptors of kernel and initramfs. The rest of the all segment preparation is done by the kernel itself. **CONFIG_KEXEC_FILE** should be enabled to use this system call. Its prototype looks like: + +``` +long kexec_file_load(int kernel_fd, int initrd_fd, unsigned long +cmdline_len, const char __user * cmdline_ptr, unsigned long +flags); +``` + +Notice that **kexec_file_load()** also accepts the command line, whereas **kexec_load()** did not. The kernel has different architecture-specific ways to accept the command line. Therefore, **kexec-tools** passes the command-line through one of the segments (like in **dtb** or **ELF boot notes**, etc.) in case of **kexec_load()**. + +Currently, **kexec_file_load()** is supported for x86 and PowerPC only. + +### What happens when the kernel crashes + +When the first kernel panics, before control is passed to the purgatory or capture kernel it does the following: + +* prepares CPU registers (see **crash_setup_regs()** in kernel code); + +* updates vmcoreinfo note (see **crash_save_vmcoreinfo()**); + +* shuts down non-crashing CPUs and saves the prepared registers (see **machine_crash_shutdown()** and **crash_save_cpu()**); + +* you also might need to disable the interrupt controller here; + +* and at the end, it performs the kexec reboot (see **machine_kexec()**), which loads/flushes kexec segments to memory and passes control to the execution of entry segment. Entry segment could be purgatory or start address of next kernel. + +### ELF program headers + +Most of the dump cores involved in kdump are in ELF format. Thus, understanding ELF Program headers is important, especially if you want to find issues with vmcore preparation. Each ELF file has a program header that: + +* is read by the system loader, + +* describes how the program should be loaded into memory, + +* and one can use **Objdump -p elf_file** to look into program headers. + +An example of ELF program headers of a vmcore: + +``` +# objdump -p vmcore +vmcore: +file format elf64-littleaarch64 +Program Header: +NOTE off 0x0000000000010000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0 filesz +0x00000000000013e8 memsz 0x00000000000013e8 flags --- +LOAD off 0x0000000000020000 vaddr 0xffff000008080000 paddr 0x0000004000280000 align 2**0 filesz +0x0000000001460000 memsz 0x0000000001460000 flags rwx +LOAD off 0x0000000001480000 vaddr 0xffff800000200000 paddr 0x0000004000200000 align 2**0 filesz +0x000000007fc00000 memsz 0x000000007fc00000 flags rwx +LOAD off 0x0000000081080000 vaddr 0xffff8000ffe00000 paddr 0x00000040ffe00000 align 2**0 filesz +0x00000002fa7a0000 memsz 0x00000002fa7a0000 flags rwx +LOAD off 0x000000037b820000 vaddr 0xffff8003fa9e0000 paddr 0x00000043fa9e0000 align 2**0 filesz +0x0000000004fc0000 memsz 0x0000000004fc0000 flags rwx +LOAD off 0x00000003807e0000 vaddr 0xffff8003ff9b0000 paddr 0x00000043ff9b0000 align 2**0 filesz +0x0000000000010000 memsz 0x0000000000010000 flags rwx +LOAD off 0x00000003807f0000 vaddr 0xffff8003ff9f0000 paddr 0x00000043ff9f0000 align 2**0 filesz +0x0000000000610000 memsz 0x0000000000610000 flags rwx +``` + +In this example, there is one note section and the rest are load sections. The note section has information about CPU notes and load sections have information about copied system RAM components. + +Vmcore starts with **elfcorehdr**, which has the same structure as that of a an ELF program header. See the representation of **elfcorehdr** in Figure 2: + +![pratyush_f2.png](https://opensource.com/sites/default/files/images/life/pratyush_f2.png) + +**kexec-tools** reads /sys/devices/system/cpu/cpu%d/crash_notes and prepares headers for **CPU PT_NOTE**. Similarly, it reads **/sys/kernel/vmcoreinfo** and prepares headers for **vmcoreinfo PT_NOTE**, and reads system RAM values from **/proc/iomem** and prepares memory **PT_LOAD** headers. When the capture kernel receives **elfcorehdr**, it appends data from addresses mentioned in the header and prepares vmcore. + +### Crash notes + +Crash notes is a per-CPU area for storing CPU states in case of a system crash; it has information about current PID and CPU registers. + +### vmcoreinfo + +This note section has various kernel debug information, such as struct size, symbol values, page size, etc. Values are parsed by capture kernel and embedded into **/proc/vmcore**. **vmcoreinfo** is used mainly by the **makedumpfile** application. **include/linux/kexec.h** in the Linux kernel has macros to define a new **vmcoreinfo**. Some of the example macros are like these: + +* **VMCOREINFO_PAGESIZE()** + +* **VMCOREINFO_SYMBOL()** + +* **VMCOREINFO_SIZE()** + +* **VMCOREINFO_STRUCT_SIZE()** + +### makedumpfile + +Much information (such as free pages) in a vmcore is not useful. Makedumpfile is an application that excludes unnecessary pages, such as: + +* pages filled with zeroes, + +* cache pages without private flag (non-private cache); + +* cache pages with private flag (private cache); + +* user process data pages; + +* free pages. + +Additionally, makedumpfile compresses **/proc/vmcore** data while copying. It can also erase sensitive symbol information from dump; however, it first needs kernel's debug information to do that. This debug information comes from either **VMLINUX** or **vmcoreinfo**, and its output either can be in ELF format or kdump-compressed format. + +Typical usage: + +``` +# makedumpfile -l --message-level 1 -d 31 /proc/vmcore makedumpfilecore +``` + +See **man makedumpfile** for detail. + +### Debugging kdump issues + +Issues that new kdump users might have: + +### _Kexec -p kernel_image_  did not succeed + +* Check whether crash memory is allocated. + +* **cat /sys/kernel/kexec_crash_size** should have no zero value. + +* **cat /proc/iomem | grep "Crash kernel"** should have an allocated range. + +* If not allocated, then pass the proper **crashkernel=** argument in the command line. + +* If nothing shows up, then pass **-d** in the **kexec** command and share the debug output with the kexec-tools mailing list. + +### Do not see anything on console after last message from first kernel (such as "bye") + +* Check whether **kexec -l kernel_image** followed by **kexec -e** works. + +* Might be missing architecture- or machine-specific options. + +* Might have purgatory SHA verification failed. If your architecture does not support a console in purgatory, then it is difficult to debug. + +* Might have second kernel crashed early. + +* Pass **earlycon**/**earlyprintk** option for your system to the second kernel command line. + +* Share **dmesg** log of both the first and capture kernel with kexec-tools mailing list. + +### Resources + +#### fedora-kexec-tools + +* Repository: **git://pkgs.fedoraproject.org/kexec-tools** + +* Mailing list: [kexec@lists.fedoraproject.org][7] + +* Description: Specs file and scripts to provide user-friendly command/services so that **kexec-tools** can be automated in different user scenarios. + +#### kexec-tools + +* Repository: git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git + +* Mailing list: [kexec@lists.infradead.org][8] + +* Description: Uses kernel system calls and provides a user command **kexec**. + +#### Linux kernel + +* Repository: **git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git** + +* Mailing list: [kexec@lists.infradead.org][9] + +* Description: Implements **kexec_load()**, **kexec_file_load()**, and **reboot()**system call and architecture-specific code, such as **machine_kexec()** and **machine_crash_shutdown()**, etc. + +#### Makedumpfile + +* Repository: **git://git.code.sf.net/p/makedumpfile/code** + +* Mailing list: [kexec@lists.infradead.org][10] + +* Description: Compresses and filters unnecessary component from the dumpfile. + + _Learn more in Pratyush Anand's [KDUMP: Usage and Internals][11] talk at LinuxCon ContainerCon CloudOpen China on June 20, 2017._ + +-------------------------------------------------------------------------------- + + +作者简介: + +Pratyush Anand - Pratyush is working with Red Hat as a Linux Kernel Generalist. Primarily, he takes care of several kexec/kdump issues being faced by Red Hat product and upstream. He also handles other kernel debugging/tracing/performance issues around Red Hat supported ARM64 platforms. Apart from Linux Kernel, he has also contributed in upstream kexec-tools and makedumpfile project. He is an open source enthusiast and delivers volunteer lectures in educational institutes for the promotion of FOSS. + +------- + + +via: https://opensource.com/article/17/6/kdump-usage-and-internals + +作者:[Pratyush Anand ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/pratyushanand +[1]:https://opensource.com/resources/what-is-linux?src=linux_resource_menu +[2]:https://opensource.com/resources/what-are-linux-containers?src=linux_resource_menu +[3]:https://developers.redhat.com/promotions/linux-cheatsheet/?intcmp=7016000000127cYAAQ +[4]:https://developers.redhat.com/cheat-sheet/advanced-linux-commands-cheatsheet?src=linux_resource_menu&intcmp=7016000000127cYAAQ +[5]:https://opensource.com/tags/linux?src=linux_resource_menu +[6]:https://opensource.com/article/17/6/kdump-usage-and-internals?rate=7i_-TnAGi8Q9GR7fhULKlQUNJw8KWgzadgMY9TDuiAY +[7]:mailto:kexec@lists.fedoraproject.org +[8]:mailto:kexec@lists.infradead.org +[9]:mailto:kexec@lists.infradead.org +[10]:mailto:kexec@lists.infradead.org +[11]:http://sched.co/AVB4 +[12]:https://opensource.com/user/143191/feed +[13]:https://pixabay.com/en/penguins-emperor-antarctic-life-429136/ +[14]:https://pixabay.com/en/shoe-boots-home-boots-house-1519804/ +[15]:https://creativecommons.org/licenses/by-sa/4.0/ +[16]:https://www.kernel.org/doc/Documentation/kdump/kdump.txt +[17]:https://linux.die.net/man/8/kexec +[18]:https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/kernel-parameters.txt +[19]:https://opensource.com/users/pratyushanand From 79a5070e167183b227c813fce2f46afa386693c9 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:17:16 +0800 Subject: [PATCH 09/25] =?UTF-8?q?20170625-7=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ecting and mapping Twitter data using R.md | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 sources/tech/20170620 A beginners guide to collecting and mapping Twitter data using R.md diff --git a/sources/tech/20170620 A beginners guide to collecting and mapping Twitter data using R.md b/sources/tech/20170620 A beginners guide to collecting and mapping Twitter data using R.md new file mode 100644 index 0000000000..ec00ced6f3 --- /dev/null +++ b/sources/tech/20170620 A beginners guide to collecting and mapping Twitter data using R.md @@ -0,0 +1,178 @@ +A beginner's guide to collecting and mapping Twitter data using R +============================================================ + +### Learn to use R's twitteR and leaflet packages, which allow you to map the location of tweets on any topic. + +![A beginner's guide to collecting and mapping Twitter data using R](https://opensource.com/sites/default/files/styles/image-full-size/public/images/business/cloud-globe.png?itok=H4f-RAz_ "A beginner's guide to collecting and mapping Twitter data using R") +Image by :  + +[Jason Baker][14]. [CC BY-SA 4.0][15]. Source: [Cloud][16], [Globe][17]. Both [CC0][18]. + +When I started learning R, I also needed to learn how to collect Twitter data and map it for research purposes. Despite the wealth of information on the internet about this topic, I found it difficult to understand what was involved in collecting and mapping Twitter data. Not only was I was a novice to R, but I was also unfamiliar with the technical terms in the various tutorials. Despite these barriers, I was successful! In this tutorial, I will break down how to collect Twitter data and display it on a map in a way that even novice coders can understand. + +Programming and development + +* [New Python content][1] + +* [Our latest JavaScript articles][2] + +* [Recent Perl posts][3] + +* [Red Hat Developers Blog][4] + +### Create the app + +If you don't have a Twitter account, the first thing you need to do is to [create one][19]. After that, go to [apps.twitter.com][20] to create an app that allows you to collect Twitter data. Don't worry, creating the app is extremely easy. The app you create will connect to the Twitter application program interface (API). Think of an API as an electronic personal assistant of sorts. You will be using the API to ask another program to do something for you. In this case, you will be connecting to the Twitter API and asking it to collect data. Just make sure you don't ask too much, because there is a [limit][21] on how many times you can request Twitter data. + +There are two APIs that you can use to collect tweets. If you want to do a one-time collection of tweets, then you'll use the **REST API**. If you want to do a continuous collection of tweets for a specific time period, you'll use the **streaming API**. In this tutorial, I'll focus on using the REST API. + +After you create your app, go to the **Keys and Access Tokens** tab. You will need the Consumer Key (API key), Consumer Secret (API secret), Access Token, and Access Token Secret to access your app in R. + +### Collect the Twitter data + +The next step is to open R and get ready to write code. For beginners, I recommend using [RStudio][22], the integrated development environment (IDE) for R. I find using RStudio helpful when I am troubleshooting or testing code. R has a package to access the REST API called **[twitteR][8]**. + +Open RStudio and create a new RScript. Once you have done this, you will need to install and load the **twitteR** package: + +``` +install.packages("twitteR") +#installs TwitteR +library (twitteR) +#loads TwitteR +``` + +Once you've installed and loaded the **twitteR** package, you will need to enter the your app's API information from the section above: + +``` +api_key <- "" + #in the quotes, put your API key +api_secret <- "" + #in the quotes, put your API secret token +token <- "" + #in the quotes, put your token +token_secret <- "" + #in the quotes, put your token secret +``` + +Next, connect to Twitter to access the API: + +``` +setup_twitter_oauth(api_key, api_secret, token, token_secret) +``` + +Let's try doing a Twitter search about community gardens and farmers markets: + +``` +tweets <- searchTwitter("community garden OR #communitygarden OR farmers market OR #farmersmarket", n = 200, lang = "en") +``` + +This code simply says to search for the first 200 tweets **(n = 200)** in English **(lang = "en")**, which contain the terms **community garden** or **farmers market**or any hashtag mentioning these terms. + +After you have done your Twitter search, save your results in a data frame: + +``` +tweets.df <-twListToDF(tweets) +``` + +To create a map with your tweets, you will need to export what you collected into a **.csv** file: + +``` +write.csv(tweets.df, "C:\Users\YourName\Documents\ApptoMap\tweets.csv") + #an example of a file extension of the folder in which you want to save the .csv file. +``` + +Make sure you save your **R** code before running it and moving on to the next step. + +### Create the map + +Now that you have data, you can display it in a map. For this tutorial, we will make a basic app using the R package **[Leaflet][9]**, a popular JavaScript library for making interactive maps. Leaflet uses the [**magrittr**][23] pipe operator (**%>%**), which makes it easier to write code because the syntax is more natural. It might seem strange at first, but it does cut down on the amount of work you have to do when writing code. + +For the sake of clarity, open a new R script in RStudio and install these packages: + +``` +install.packages("leaflet") +install.packages("maps") +library(leaflet) +library(maps) +``` + +Now you need a way for Leaflet to access your data: + +``` +read.csv("C:\Users\YourName\Documents\ApptoMap\tweets.csv", stringsAsFactors = FALSE) +``` + +**stringAsFactors = FALSE** means to keep the information as it is and not convert it into factors. (For information about factors, read the article ["stringsAsFactors: An unauthorized biography"][24], by Roger Peng.) + +It's time to make your Leaflet map. You are going to use the **OpenStreetMap**base map for your map: + +``` +m <- leaflet(mymap) %>% addTiles() +``` + +Let's add circles to the base map. For **lng** and **lat**, enter the name of the columns that contain the latitude and longitude of your tweets followed by **~**. The **~longitude** and **~latitude** refer to the name of the columns in your **.csv** file: + +``` +m %>% addCircles(lng = ~longitude, lat = ~latitude, popup = mymap$type, weight = 8, radius = 40, color = "#fb3004", stroke = TRUE, fillOpacity = 0.8) +``` + +Run your code. A web browser should pop up and display your map. Here is a map of the tweets that I collected in the previous section: + +### [leafletmap.jpg][6] + +![Map of tweets by location](https://opensource.com/sites/default/files/leafletmap.jpg "Map of tweets by location") + +Map of tweets by location, Leaflet and OpenStreetMap, [CC-BY-SA][5] + + + +Although you might be surprised with the small number of tweets on the map, typically only 1% of tweets are geocoded. I collected a total of 366 tweets, but only 10 (around 3% of total tweets) were geocoded. If you are having trouble getting geocoded tweets, change your search terms to see if you get a better result. + +### Wrapping up + +For beginners, putting all the pieces together to create a Leaflet map from Twitter data can be overwhelming. This tutorial is based on my experiences doing this task, and I hope it makes the learning process easier for you. + + _Dorris Scott will present this topic in a workshop, [From App to Map: Collecting and Mapping Social Media Data using R][10], at the [We Rise][11] Women in Tech Conference ([#WeRiseTech][12]) June 23-24 in Atlanta._ + +-------------------------------------------------------------------------------- + +作者简介: + +Dorris Scott - Dorris Scott is a PhD student in geography at the University of Georgia. Her research emphases are in Geographic Information Systems (GIS), geographic data science, visualization, and public health. Her dissertation is on combining traditional and non-traditional data about Veteran’s Affairs hospitals in a GIS interface to help patients make more informed decisions regarding their healthcare. + + +----------------- +via: https://opensource.com/article/17/6/collecting-and-mapping-twitter-data-using-r + +作者:[Dorris Scott ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://opensource.com/users/dorrisscott +[1]:https://opensource.com/tags/python?src=programming_resource_menu +[2]:https://opensource.com/tags/javascript?src=programming_resource_menu +[3]:https://opensource.com/tags/perl?src=programming_resource_menu +[4]:https://developers.redhat.com/?intcmp=7016000000127cYAAQ&src=programming_resource_menu +[5]:https://creativecommons.org/licenses/by-sa/2.0/ +[6]:https://opensource.com/file/356071 +[7]:https://opensource.com/article/17/6/collecting-and-mapping-twitter-data-using-r?rate=Rnu6Lf0Eqvepznw75VioNPWIaJQH39pZETBfu2ZI3P0 +[8]:https://cran.r-project.org/web/packages/twitteR/twitteR.pdf +[9]:https://rstudio.github.io/leaflet +[10]:https://werise.tech/sessions/2017/4/16/from-app-to-map-collecting-and-mapping-social-media-data-using-r?rq=social%20mapping +[11]:https://werise.tech/ +[12]:https://twitter.com/search?q=%23WeRiseTech&src=typd +[13]:https://opensource.com/user/145006/feed +[14]:https://opensource.com/users/jason-baker +[15]:https://creativecommons.org/licenses/by-sa/4.0/ +[16]:https://pixabay.com/en/clouds-sky-cloud-dark-clouds-1473311/ +[17]:https://pixabay.com/en/globe-planet-earth-world-1015311/ +[18]:https://creativecommons.org/publicdomain/zero/1.0/ +[19]:https://twitter.com/signup +[20]:https://apps.twitter.com/ +[21]:https://dev.twitter.com/rest/public/rate-limiting +[22]:https://www.rstudio.com/ +[23]:https://github.com/smbache/magrittr +[24]:http://simplystatistics.org/2015/07/24/stringsasfactors-an-unauthorized-biography/ +[25]:https://opensource.com/users/dorrisscott From 244ad74a9a251fc9ce22d63b881f096c5c125b99 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:36:50 +0800 Subject: [PATCH 10/25] =?UTF-8?q?20170625-8=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20170617 Top 8 IDEs for Raspberry Pi.md | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 sources/tech/20170617 Top 8 IDEs for Raspberry Pi.md diff --git a/sources/tech/20170617 Top 8 IDEs for Raspberry Pi.md b/sources/tech/20170617 Top 8 IDEs for Raspberry Pi.md new file mode 100644 index 0000000000..8091a1e04a --- /dev/null +++ b/sources/tech/20170617 Top 8 IDEs for Raspberry Pi.md @@ -0,0 +1,241 @@ +Top 8 IDEs for Raspberry Pi +============================================================ + + + _![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/LEGO_brick_robot_05.jpg?resize=700%2C479)_ + + _The Raspberry Pi, a tiny single-board computer, has revolutionised the way in which computer science is being taught in schools. It has also turned out to be a boon for software developers. Currently, it has gained popularity much beyond its target market and is being used in robotics projects._ + +Raspberry Pi, a small development board minicomputer that runs the Linux operating system, was developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools in the UK and in developing countries. Raspberry Pi has USB sockets, which support various peripheral plug-and-play devices like the keyboard, the mouse, the printer, etc. It contains ports like HDMI (High Definition Multimedia Interface) to provide users with video output. Its credit-card-like size makes it extremely portable and affordable. It requires just a 5V micro-USB power supply, similar to the one used to charge a mobile phone. + +Over the years, the Raspberry Pi Foundation has released a few different versions of the Pi board. The first version was Raspberry Pi 1 Model B, which was followed by a simple and cheap Model A. In 2014, the Foundation released a significant and improved version of the board —Raspberry Pi 1 Model B+. In 2015, the Foundation revolutionised the design of the board by releasing a small form factor edition costing US$ 5 (about ` 323) called Raspberry Pi Zero. + +In February 2016, Raspberry Pi 3 Model B was launched, which is currently the main product available. In 2017, the Foundation released the updated model of Raspberry Pi Zero named Raspberry Pi Zero W (W = wireless). + +In the near future, a model that has improved technical specifications will arrive, offering a robust platform for embedded systems enthusiasts, researchers, hobbyists and engineers to use it in multi-functional ways to develop real-time applications. + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-1-8.jpg?resize=350%2C198)][3] + +Figure 1: Raspberry Pi + +**Raspberry Pi as an efficient programming device** + +After getting the Pi powered up and the LXDE WM up and running, the user gets a full-fledged Linux box running a Debian based operating system, i.e., Raspbian. The Raspbian operating system comes with tons of free and open source utilities for users, covering programming, gaming, applications and even education. + +The official programming language of Raspberry Pi is Python, which comes preloaded with the Raspbian operating system. The combination of Raspberry Pi and IDLE3, a Python integrated development environment, enables programmers to develop all sorts of Python based programs. + +In addition to Python, various other languages are supported by Raspberry Pi. A number of IDEs (integrated development environments) that are free and open source are also available. These allow programmers, developers and application engineers to develop programs and applications on Pi. + + [![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-2-6.jpg?resize=350%2C230)][4] + +Figure 2: The BlueJ GUI interface + + [![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-3-3.jpg?resize=350%2C288)][5] + +Figure 3: The Geany IDE GUI interface + +**Best IDEs for Raspberry Pi** + +As a programmer and developer, the first thing you require is an IDE, which is regarded as a comprehensive software suite that integrates the basic tools that developers and programmers require to write, compile and test their software. An IDE contains a code editor, a compiler or interpreter and a debugger, which the developer can access via a graphical user interface (GUI). One of the main aims of an IDE is to reduce the configuration necessary to piece together multiple development utilities, and provide the same set of capabilities as a cohesive unit. + +An IDE’s user interface is similar to that of a word processor, for which tools in the toolbar support colour-coding, formatting of source code, error diagnostics, reporting and intelligent code completion. IDEs are designed to integrate with third-party version control libraries like GitHub or Apache Subversion. Some IDEs are dedicated to a particular programming language, allowing a feature set that matches the programming language, while some support multiple languages. + +Raspberry Pi has a wide range of IDEs that provide programmers with good interfaces to develop source code, applications and system programs. + +Let’s explore the top IDEs for Raspberry Pi. + + [![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-4-3.jpg?resize=350%2C216)][6] + +Figure 4: The Adafruit WebIDE GUI interface + +**BlueJ** + +BlueJ is an IDE that is dedicated to the Java Programming Language and was mainly developed for educational purposes. It also supports short software development projects. Michael Kolling and John Rosenburg at Monash University, Australia, started BlueJ development in 2000 as a powerful successor to the Blue system, and BlueJ became free and open source in March 2009. + +BlueJ provides an efficient way for learning object-oriented programming concepts and the GUI provides a class structure for applications like UML diagram. Every OOPS based concept, like class, objects and function calling, can be represented via interaction based design. + + _**Features**_ + +* _Simple and interactive interface:_  The user interface is simple and easy to learn as compared to other professional interfaces like NetBeans or Eclipse. Developers can focus mainly on programming rather than the environment. + +* _Portable:_  BlueJ supports multiple platforms like Windows, Linux and Mac OS X, and can even run without any installation. + +* _New innovations:_  BlueJ IDE is filled with innovations in terms of the object bench, code pad and scope colouring, which makes development fun even for newbies. + +* _Strong technical support:_  BlueJ has a hard-core functioning team that responds to queries and offers solutions to all sorts of developer problems within 24 hours. + +**Latest version:** 4.0.1 + +**Geany IDE** + +Geany IDE is regarded as a very lightweight GUI based text editor that uses Scintilla and GTK+ with IDE environment support. The unique thing about Geany is that it is designed to be independent of a special desktop environment and requires only a few dependencies on other packages. It only requires GTK2 runtime libraries for execution. Geany IDE supports tons of programming languages like C, C++, C#, Java, HTML, PHP, Python, Perl, Ruby, Erlang and even LaTeX. + + _**Features**_ + +* Auto-completion of code and simple code navigation. + +* Efficient syntax highlighting and code folding. + +* Supports embedded terminal emulator, and is highly extensible and feature-rich since lots of plugins are available for free download. + +* Simple project management and supports multiple file types, which include C, Java, PHP, HTML, Python, Perl, and many more. + +* Highly customised interface for adding or removing options, bars and windows. + +**Latest version:** 1.30.1 + + [![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-5-2.jpg?resize=350%2C252)][7] + +Figure 5: The AlgoIDE GUI interface + + [![](https://i1.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-6-1.jpg?resize=350%2C378)][8] + +Figure 6: The Ninja IDE GUI interface + +**Adafruit WebIDE** + +Adafruit WebIDE provides a Web based interface for Raspberry Pi users to perform programming functions, and allows developers to compile the source code of various languages like Python, Ruby, JavaScript and many others. + +Adafruit IDE allows developers to put the code in a GIT repository, which can be accessed anywhere via GitHub. + + _**Features**_ + +* Can be accessed via Web browser on ports 8080 or 80. + +* Supports the easy compilation and running of source code. + +* Bundled with a debugger and visualiser for proper tracking, the navigation of code and to test source code. + +**AlgoIDE** + +AlgoIDE is a combination of a scripting language and an IDE environment, designed to function together to take programming to the next paradigm. It incorporates a powerful debugger, real-time scope explorer and executes the code, step by step. It is basically designed for all age groups to design programs and do extensive research on algorithms. +It supports various types of languages like C, C++, Python, Java, Smalltalk, Objective C, ActionScript, and many more. + + _**Features**_ + +* Automatic indentation and completion of source code. + +* Effective syntax highlighting and error management. + +* Contains a debugger, scope explorer and dynamic help system. + +* Supports GUI and traditional Logo programming language Turtle for the development of source code. + +**Latest version:** 2016-12-08 (when it was last updated) + +**Ninja IDE** + +Ninja IDE (Not Just Another IDE), which was designed by Diego Sarmentero, Horacio Duranm Gabriel Acosta, Pedro Mourelle and Jose Rostango, is written purely in Python and supports multiple platforms like Linux, Mac OS X and Windows, for execution. It is regarded as a cross-platform IDE software, especially designed to build Python based applications. + +Ninja IDE is very lightweight and performs various functions like file handling, code locating, going to lines, tabs, automatic indentation of code and editor zoom. Apart from Python, several other languages are supported by this IDE. + + _**Features**_ + +* _An efficient code editor:_  Ninja-IDE is regarded as the most efficient code editor as it performs various functions like code completion and code indentation, and functions as an assistant. + +* _Errors and PEP8 finder:_  It highlights static and PEP8 errors in the file. + +* _Code locator:_  With this feature, quick and direct access to a file can be made. The user can just make use of the ‘CTRL+K’ shortcut to type anything, and the IDE will locate the specific text. + +* Its unique project management features and tons of plugins make Ninja-IDE highly extensible. + +**Latest version:** 2.3 + + [![](https://i1.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-7.jpg?resize=350%2C306)][9] + +Figure 7: The Lazarus IDE GUI interface + +**Lazarus IDE** + +Lazarus IDE was developed by Cliff Baeseman, Shane Miller and Michael A. Hess in February 1999\. It is regarded as a cross-platform GUI based IDE for rapid application development, and it uses the Free Pascal Compiler. It inherits three primary features—compilation speed, execution speed and cross-compilation. Applications can be cross-compiled from Windows to other operating systems like Linux, Mac OS X, etc. + +This IDE consists of the Lazarus component library, which provides varied facilities to developers in the form of a single and unified interface with different platform-specific implementations. It supports the principle of ‘Write once and compile anywhere’. + + _**Features**_ + +* Powerful and fast enough to handle any sort of source code, and supports performance testing. + +* Easy to use GUI, which supports drag-and-drop components. Additional components can be added to the IDE through Lazarus package files. + +* Makes use of Free Pascal, which is highly enhanced with new features and is even used in Android app development. + +* Highly extensible, open source and supports various frameworks to compile additional languages. + +**Latest version:** 1.6.4 + +**Codeblock IDE** + +Codeblock IDE was written in C++ using wxWidgets as a GUI toolkit and was released in 2005\. It is a free, open source and cross-platform IDE supporting multiple compilers like GCC, Clang and Visual C++. + +Codeblock IDE is highly intelligent and performs various functions like Syntax highlighting, code folding, code completion and indentation, and has a number of external plugins for varied customisations. It can run on Windows, Mac OS X and Linux operating systems. + + _**Features**_ + +* Supports multiple compilers like GCC, Visual C++, Borland C++, Watcom, Intel C++ and many more. Basically designed for C++, but today supports many languages. + +* Intelligent debugger, which allows users to debug programs via access to the local function symbol and argument display, user defined watches, call stack, custom memory dump, thread switching and GNU debugger interface. + +* Supports varied features for migrating code from Dev-C++, Visual C++ and others. + +* Makes use of custom-built systems and stores information in XML extension files. + +**Latest version:** 16.01 + + [![](https://i2.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-8.jpg?resize=350%2C289)][10] + +Figure 8: Codeblock IDE interface + + [![](https://i1.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-9.jpg?resize=350%2C236)][11] + +Figure 9: Greenfoot IDE interface + +**Greenfoot IDE** + +Greenfoot IDE was designed by Michael Kolling at the University of Kent. It is a cross-platform Java based IDE basically designed for educational purposes for high schools and undergraduate students. The Greenfoot IDE features project management, automatic code completion and syntax highlighting, and has an easy GUI interface. + +Greenfoot IDE programming consists of sub-classing of two main classes — World and Actor. World represents the class where the main execution occurs. Actors are objects that exist and act in World. + + _**Features**_ + +* Simple and easy-to-use GUI, which is more interactive than BlueJ and other IDEs. + +* Easy to use even for newbies and beginners. + +* Highly powerful in executing Java code. + +* Supports GNOME/KDE/X11 graphical environments. + +* Other features include project management, auto-completion, syntax highlighting and auto-correction of errors. + +**Latest version:** 3.1.0 + +-------------------------------------------------------------------------------- + +作者简介: + +Anand Nayyar + +The author is assistant professor in Department of Computer Applications & IT at KCL Institute of Management and Technology, Jalandhar, Punjab. He loves to work on Open Source technologies, embedded systems, cloud computing, wireless sensor networks and simulators. He can be reached at anand_nayyar@yahoo.co.in. + +-------------------- + +via: http://opensourceforu.com/2017/06/top-ides-raspberry-pi/ + +作者:[Anand Nayyar ][a] +译者:[译者ID](https://github.com/译者ID) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://opensourceforu.com/author/anand-nayyar/ +[1]:http://opensourceforu.com/2017/06/top-ides-raspberry-pi/#disqus_thread +[2]:http://opensourceforu.com/author/anand-nayyar/ +[3]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-1-8.jpg +[4]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-2-6.jpg +[5]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-3-3.jpg +[6]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-4-3.jpg +[7]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-5-2.jpg +[8]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-6-1.jpg +[9]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-7.jpg +[10]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-8.jpg +[11]:http://opensourceforu.com/wp-content/uploads/2017/05/Figure-9.jpg From 8b073322b3b0e65f06e9fca94d6c4711240be361 Mon Sep 17 00:00:00 2001 From: Ezio Date: Sun, 25 Jun 2017 10:40:16 +0800 Subject: [PATCH 11/25] =?UTF-8?q?20170625-9=20=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7 What all you need to know about HTML5.md | 272 ++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 sources/tech/20170617 What all you need to know about HTML5.md diff --git a/sources/tech/20170617 What all you need to know about HTML5.md b/sources/tech/20170617 What all you need to know about HTML5.md new file mode 100644 index 0000000000..b5adee5fb2 --- /dev/null +++ b/sources/tech/20170617 What all you need to know about HTML5.md @@ -0,0 +1,272 @@ +What all you need to know about HTML5 +============================================================ + + + _![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/handwritten-html5-peter-booth-e-plus-getty-images-56a6faec5f9b58b7d0e5d1cf.jpg?resize=700%2C467)_ + + _HTML5, the fifth and current version of the HTML standard, is a markup language used to structure and present content on the World Wide Web. This article will help readers get acquainted with it._ + +HTML5 has evolved through the cooperation between the W3C and the Web Hypertext Application Technology Working Group. It is a higher version of HTML, and its many new elements make your pages more semantic and dynamic. It was developed to provide a greater Web experience for everyone. HTML5 offers great features that make the Web more dynamic and interactive. + +The new features of HTML5 are: + +* New sets of tags such as
and
+ +* element for 2D drawing + +* Local storage + +* New form controls like calendar, date and time + +* New media functionality + +* Geo-location + +HTML5 is not an official standard as yet; hence, not all browsers support it or some of its features. One of the most important reasons behind developing HTML5 was to prevent users from having to download and install multiple plugins like Silverlight and Flash. + +**New tags and elements** + +**Semantic elements:** Figure 1 displays a few useful semantic elements. +**Form elements:** The form elements present in HTML5 are shown in Figure 2. +**Graphic elements:** The graphic elements in HTML5 can be seen in Figure 3. +**Media elements:** The new media elements in HTML5 are listed in Figure 4. + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-1-7.jpg?resize=350%2C277)][3] + +Figure 1: Semantic elements + + [![](https://i1.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-2-5.jpg?resize=350%2C108)][4] + +Figure 2: Form elements + +**Advanced features of HTML5** + +**Geo-location** + +It is an HTML5 API that is used to get the geographical location of a website’s user, who has to first permit the site to fetch his or her location. This usually happens via a button and/or browser popup. All the latest versions of Chrome, Firefox, IE, Safari and Opera can use the geo-location feature of HTML5. + +Some uses of geo-location are: + +* Public transportation websites + +* Taxi and other transportation websites + +* To calculate shipping costs on an e-commerce site + +* Travel agency websites + +* Real estate websites + +* Movie theatre websites can find movies playing nearby + +* Online gaming + +* For sites to feature local headlines and weather on their front page + +* Job postings can automatically include commute times + +**How it works:** Geo-location works by scanning common sources of location information, which include the following: + +* Global Positioning System (GPS), which is the most accurate + +* Network signals—IP address, RFID, Wi-Fi and Bluetooth MAC addresses + +* GSM/CDMA cell IDs + +* User inputs + +The API offers a very handy function to detect geo-location support in browsers: + +| `if` `(navigator.geolocation) {``//` `do` `stuff``}` | + +The  _getCurrentPosition_  API is the main method for using geo-location. It retrieves the current geographic location of the user’s device. The location is described as a set of geographic coordinates along with the heading and speed. The location information is returned as a position object. + +The syntax is: + +`getCurrentPosition(showLocation, ErrorHandler, options);` + +* _showLocation:_  This defines the callback method that retrieves location information. + +* _ErrorHandler(Optional):_  This defines the callback method that is invoked when an error occurs in processing the asynchronous call. + +* _options (Optional):_  This defines a set of options for retrieving the location information. + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-3-2.jpg?resize=350%2C72)][5] + +Figure 3: Graphic elements + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure-4-2.jpg?resize=350%2C144)][6] + +Figure 4: Media elements + +Figure 5 incorporates the set of properties returned by a position object. + +We can present location information to the user in two ways—geodetic and civil: + +1\. The geodetic way of describing a position refers directly to the latitude and longitude. +2\. The civic representation of location data is readable and easily understood by humans. + +As shown in Table 1, each attribute/parameter has both a geodetic representation and a civic representation. + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/table-1.jpg?resize=350%2C132)][7] + +**Web storage** + +In HTML, to store user data on a local machine, we were using JavaScript cookies. To avoid that, HTML5 has introduced Web storage, with which websites themselves store user data on a local machine. + +The advantages of Web storage, as compared to cookies, are: + +* More secure + +* Faster + +* Stores a larger amount of data + +* The stored data is not sent with every server request. It is only included when asked for. This is a big advantage of HTML5 Web storage over cookies. + +There are two types of Web storage objects: + +1) Local – this stores data with no expiration date. +2) Session – this stores data for one session only. + +**How it works:** The  _localStorage_  and  _sessionStorage_  objects create a  _key = value pair._ + +An example is: _ key=“Name”,_   _value=“Palak”_ + +These are stored as strings but can be converted, if required, by using JavaScript functions like  _parseInt()_  and  _parseFloat()_ . + +Given below is the syntax for using Web storage objects: + + `Storing a Value:``• localStorage.setItem(“key1”, “value1”);``• localStorage[“key1”] = “value1”;``Getting a Value:``• alert(localStorage.getItem(“key1”));``• alert(localStorage[“key1”]);``Remove a Value:``• removeItem(“key1”);``Remove All Values:``• localStorage.``clear``();` + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/Figure5-1.jpg?resize=350%2C202)][8] + +Figure 5: Position object properties + +**Application Cache (AppCache)** + +Using HTML5 Apache, we can make a Web application work offline without an Internet connection. All browsers, besides IE, can use  _AppCache_  (at this point in time). + +The advantages of Application Cache are: + +* Enables browsing Web pages offline + +* Pages load faster + +* Results in less load for servers + +The  _cache manifest_  file is a simple text file that lists the resources the browser should cache for offline access. The  _manifest_  attribute can be included on the document’s HTML tag, as follows: + +```...``<``/html``>` + +It should be on all the pages that you want to cache. + +The application pages that are cached will remain unless: + +1\. The user clears them out. +2\. The manifest has been modified. +3\. The cache is updated. + +**Video** + +Until HTML5 was launched, there was no uniform standard for showing video on Web pages. Most of the videos were shown through different plugins like Flash. But HTML5 specifies a standard way to show the video on a Web page by using a video element. + +Currently, it supports three video formats for the video element, as shown in Table 2. + + [![](https://i0.wp.com/opensourceforu.com/wp-content/uploads/2017/05/table-2.jpg?resize=350%2C115)][9] +The example given below shows the use of this video element: + ```````