打造自己的Linux系统:从零开始学习Linux from Scratc (linux from scrath)

h

Linux是目前更流行的操作系统之一,它是一种基于Unix的开放源代码操作系统,可以运行在各种设备上,如个人电脑、服务器、智能手机、平板电脑和嵌入式系统等。对于很多技术爱好者来说,学习Linux是入门的必经之路。在这篇文章中,我们将从零开始学习Linux,打造出一个完全属于自己的Linux系统。

一、了解Linux的基本概念

在开始学习Linux之前,我们需要了解一些基本概念。Linux是一个开源系统,这意味着它的源代码是公开的,任何人都可以使用、学习和修改它。Linux是一个多用户、多任务的操作系统,这意味着它可以同时支持多个用户和程序的运行。Linux系统是由内核、外壳、工具和应用程序等组成的。

二、安装Linux

接下来,我们需要安装Linux系统。在这里,我们可以选择安装一个现成的Linux发行版,如Ubuntu、Debian、Fedora、CentOS等。这些发行版已经包括了必要的软件包和驱动程序,可以让我们直接开始使用操作系统。不过,在本文中,我们将选择安装一个从头开始编写的Linux系统。

三、编写Linux内核

为了编写自己的Linux系统,我们需要从零开始编写内核。内核是操作系统的核心部分,负责管理计算机的所有资源,如CPU、内存、I/O设备等。在开始编写内核之前,我们需要了解一些基本的操作系统原理和编程知识。

我们需要选择一个合适的开发环境。在Linux系统中,我们可以使用GNU工具链,其中包括GCC编译器、GDB调试器和Make构建工具等。使用这些工具可以帮助我们编写、调试和构建内核代码。

我们需要了解一些内核相关的概念和数据结构。这包括进程、线程、文件系统、内存管理等。我们需要深入了解每个概念和数据结构的工作原理和实现方式,这样才能更好地编写内核代码。

我们需要阅读内核源代码,了解内核的组成和功能。内核源代码通常存储在/usr/src/linux目录下,我们可以使用文本编辑器打开它们,并逐一阅读每个文件,了解其功能和实现。

四、编写外壳和工具链

在内核编写完成之后,我们需要编写外壳和工具链。外壳是操作系统的用户界面,通过它我们可以与系统进行交互,并执行命令和程序等。在Linux系统中,最常用的外壳是Bash外壳,它是由GNU工具链提供的。我们可以使用文本编辑器编写Bash脚本,并通过Shell解释器执行它们。

工具链是操作系统的一部分,它包括所有必要的工具和库,如编译器、调试器、构建工具、标准库等。我们需要选择一个合适的工具链,并对其进行配置和优化,以便在开发和部署时能够更好地工作。

五、编写应用程序

我们需要编写一些应用程序,以便测试和验证我们的Linux系统。可以编写一些基本的命令行工具,如ls、cd、cat等,或者更复杂的应用程序,如Web服务器、数据库、游戏等。

编写应用程序需要使用适当的编程语言和开发工具。在Linux系统中,C和C++是最常用的编程语言,可以使用GCC编译器和GDB调试器来开发和调试应用程序。

在编写应用程序之前,我们需要了解一些Linux系统API和库的使用方法。这些API和库提供了访问系统资源和进行通信的接口,如文件系统、网络、进程管理等。

六、

学习Linux系统需要大量的时间和精力,但这也是一个非常有价值的过程。通过学习Linux,我们可以更好地了解操作系统的工作原理和实现方式,提高我们的编程技能和思维能力。同时,Linux系统还是一个非常强大的工具,可以用于各种用途,如开发、服务器、网络等。希望这篇文章可以激发大家对Linux的兴趣和学习热情。

相关问题拓展阅读:

lfs是什么意思,不是游戏的那总意思!

-a 的意思带源地址ping。因为路由器上有多个接口时,ping的时候会选择最短路径的接口ip地址为源地址ping。而某些测试时,这个源地址是另一个接口ip地址时。才使用-a 参数

192.168.8.x 是源地址,此地址必须是路由器的接口ip地址或者loopback接口地址。

192.168.4.x是目的地址。

例:

路由器有2个接口。wan-ip:10.0.0.2 对端地址为10.0.0.1 lan-ip:192.168.1.1

当你在路由器上做了nat后。可使用-a命令正裤测试nat是否正确。

ping 10.0.0.1 时。路由器会自动选择更优ip地址10.0.0.2为源地庆基址,此时ping的话,只能测试外网线路是否正常

而 ping -a 192.168.1.1 10.0.0.1 。带有源地址ping,模拟内网用户192.168.1.1ping 10.0.0.1 如果能ping通说明nat设置正确。如果不通,举差简可能是路由不正确或者nat设置错误。

还有很多时候使用-a 参数的

你可在 ping ? 查看支持的命令及注释

H3C和cisco的命令都不是通用的。

LFS──Linux from Scratch,就是一种从网上直接下载源码,从头编译LINUX的安装方式。它不是发行版,只是一个菜谱,告诉你到哪里去买菜(下载源空梁岩码),怎么把斗御这些生东西( raw code) 作成符合自己口味的菜肴──个性化的linux,不单单是个性的桌面。Linux From Scratch项目简称LFS,它提供具体的步骤、特定的补丁、必须的脚本,从而提供一个简便的创建Linux发行版的途径。LFS并不是一渣培个发行版,但是它可以作为制作初级发行版的良好练习。

LFS──Linux from Scratch,就是世拆一种从网上直接下载源码,从头编译LINUX的安装方式。它不是发行版,只是一个菜谱,告诉你到哪里去买菜(下载源码),知返悔怎么把这些生东西( raw code) 作成符合自己搭正口味的菜肴──个性化的linux,不单单是个性的桌面。

如何定制小型的linux系统,具体的步骤,谢谢了

参考LFS的文档,就是要求每个包都尽可能编译小的二进制程序。同败丛等功能的包选兆蔽用一些比小巧的包。

内核也得族枯州精简

系统启动过程

1、加电自检(POST代码)

2、boot loader

GRUB -- /boot/grub/grub.conf

kernel

initrd.img

3、INIT

/in/init/etc/inittab

/etc/rc.d/rc.sysinit

/渗卖etc/rc.d/rc RUNLEVEL

/etc/rc$runlevel.d/S* start

/etc/丛橡逗rc$runlevel.d/K* stop

/etc/X11/prefdm

4、登录

文本 login

图形 gdm/kdm

自制一个U盘系统

准备工作:在真实机中把yum配置好

# ls /mnt/Server/ 这是软件包所处的目录

# cd /如桐etc/yum.repos.d/

# ls

rhel-debuginfo.repo

# cp rhel-debuginfo.repo pg.repo

# vim pg.repo

# cat pg.repo

name=Red Hat Enterprise Linux

baseurl=

enabled=1

gpgcheck=1

gpgkey=

1、准备U盘,并分区,格式化成ext3(可选)文件系统# fdisk -l

# fdisk -l

Disk /dev/sda: 4003 MB,bytes

84 heads, 20 sectors/track, 4654 cylinders

Units = cylinders of 1680 * 512 =bytes

Device Boot Start End Blocks Id System

/dev/sda1 *0 c W95 FAT32 (LBA)

# fdisk /dev/sda

The number of cylinders for this disk is set to 4654.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): d

Selected partition 1

Command (m for help): p

Disk /dev/sda: 4003 MB,bytes

84 heads, 20 sectors/track, 4654 cylinders

Units = cylinders of 1680 * 512 =bytes

Device Boot Start End Blocks Id System

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-4654, default 1):

Using default value 1

Last cylind# mount -t ext3 /dev/sda1 /neter or +size or +sizeM or +sizeK (1-4654, default 4654):

Using default value 4654

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

# partprobe /dev/sda

# ls /dev/sda1

/dev/sda1

--------------

# mkfs.ext3 /dev/sda1

2、挂载U盘,并把相关文件拷到U盘中

# mount -t ext3 /dev/sda1 /net

把/目录树结构在u盘创建好

># yum –installroot=/net -y install filesystem

/boot

这个目录应该有vmlinuz-x.x.x initrd-x.x.x.img

/boot/grub

这个目录中应该有grub的相关文件

grub还要安装到u盘的首扇区中(grub-install)

/bin /in /lib /usr/lib

这些个目录下应该有一些命令和库文件

bash ls cp mv

mount

ifconfig

fdisk

mkfs.ext3

基本上你需要的程序比较多,大概有以下一些常用的:

coreutils setup grub vim-enhanced

vim-common gpm perl iptables

openssh openssh-clients

module-init-tools iputils grep awk sed

procps tar bash gcc make rp-pppoe

passwd libuser e2fsprogs util-linux

net-tools SysVinit kernel

-----------------------

a.关于vmlinuz文件:

># cp /boot/vmlinuz-2.6.18-194.el5 /net/boot/

b.关于initrd.img文件: 为了包含u盘的驱动,需要手动生成initrd.img(包含u-storage)

># modinfo -F filename u-storage

># mkinitrd –with=u-storage /net/boot/initrd-u-2.6.18-194.img `uname -r`

c. 使用此命令grub-install将grub安装到u盘的首扇区中

grub-install 需要安装grub软件包生成

># yum –installroot=/net -y install grub

># grub-install /dev/sda 最后执行这一步,还有一些必要工作没做

d. ># cat /net/boot/grub/grub.conf

default=0

timeout=5

title RHEL5U5 u linux for pg

root (hd0,0)

kernel /boot/vmlinuz-2.6.18-194.el5 ro root=/dev/sda1

initrd /boot/initrd-u-2.6.18-194.img

e. 为了生成以下这些常用的命令,装包

bash ls cp mv

mount

ifconfig

fdisk

mkfs.ext3

yum bash ls cp mv

mount

ifconfig

fdisk

mkfs.ext3

yum –installroot=/net -y install coreutils setup grub vim-enhanced vim-common gpm perl iptables openssh openssh-clients module-init-tools iputils grep awk sed procps tar bash gcc make rp-pppoe passwd libuser e2fsprogs util-linux net-tools SysVinit kernel pam

f.在U盘系统启动的时候,需要读fstab文件,挂载文件系统

># cp /etc/fstab /net/etc

># vim /net/etc/fstab

># cat /net/etc/fstab

/dev/sda1 / ext3 defaults 0 0

开始安装GRUB程序

># chroot /net/

bash-3.2#

># chroot /net/

bash-3.2# grub-install /dev/sda

Probing devices to guess BIOS drives. This may take a long time.

No suitable drive was found in the generated device map. 这个错误意味着需要去写devices.map文件

bash-3.2# ls /dev/sda

ls: /dev/sda: 没有那个文件或目录

bash-3.2# ls /dev/sda1

ls: /dev/sda1: 没有那个文件或目录

bash-3.2# mknod /dev/sda b 8 0

bash-3.2# mknod /dev/sda1 b 8 1

bash-3.2# cat /etc/mtab

/dev/sda1 / ext3 rw 0 0

bash-3.2# cat /boot/grub/device.map

(fd0) /dev/fd0

(hd0) /dev/sda

bash-3.2# grub-install /dev/sda

Could not find device for /dev/mapper/*

Could not find device for /dev/mapper/*

Could not find device for /dev/mapper/*

Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.

Check if this is correct or not. If any of the lines is incorrect,

fix it and re-run the script `grub-install’.

(fd0) /dev/fd0

(hd0) /dev/sda

># chroot /net/

bash-3.2# passwd root 修改密码不成功,将导致 u盘系统启动后,用root登录不成功。

Changing password for user root.

passwd: Authentication token manipulation error

解决方法:

vim /net/etc/passwd

root:*:0:0:root:/root:/bin/bash

root:x:0:0:root:/root:/bin/bash

这样再把root密码设置为你想要的!

检查 以下过程是否正确:

/boot/grub/grub.conf

/etc/inittab —默认运行级别应该是3

/etc/fstab

/etc/passwd

/etc/shadow

pam程序包做验证的

ls /dev/sda /dev/sda1

># chroot /net/

bash-3.2# passwd root 这一步必须能成功

# rpm -q kernel-doc

kernel-doc-2.6.18-194.el5

# gedit /usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt

不太明白你说的定制小型linux系统是什么意思。。。。

LFS,具猜前体的看激贺文档穗铅清吧.

关于linux from scrath的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » 打造自己的Linux系统:从零开始学习Linux from Scratc (linux from scrath)