linux的一些有关DevOps的东西
地址:https://www.iteye.com/blog/lobin-2040270
linux: Guide
地址:https://www.iteye.com/blog/lobin-2512870
C部分和汇编部分
汇编部分如bootloader等采用GNU AS实现,老版本ru linux 1.0, 1.x, 2.0 采用的是as86,ld86实现。
gnulib
参考资料:http://www.gnu.org/software/gnulib/manual/html_node/index.html
>git clone git://git.savannah.gnu.org/gnulib.git gnulib
$ gnulib-tool --create-testdir --source-base=lib --dir=/tmp/posixlib `posix-modules`
一张有关io的图片
一张有关io的图片
主引导程序
# dd if=/dev/sda of=mbr.bin bs=512 count=1
# od -xa mbr.bin
# od -A x -t x1 mbr.bin
000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00
000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75
000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 03 02
000040 80 00 00 80 ee 49 08 00 00 08 fa 90 90 f6 c2 80
000050 75 02 b2 80 ea 59 7c 00 00 31 c0 8e d8 8e d0 bc
000060 00 20 fb a0 40 7c 3c ff 74 02 88 c2 52 f6 c2 80
000070 74 54 b4 41 bb aa 55 cd 13 5a 52 72 49 81 fb 55
000080 aa 75 43 a0 41 7c 84 c0 75 05 83 e1 01 74 37 66
000090 8b 4c 10 be 05 7c c6 44 ff 01 66 8b 1e 44 7c c7
0000a0 04 10 00 c7 44 02 01 00 66 89 5c 08 c7 44 06 00
0000b0 70 66 31 c0 89 44 04 66 89 44 0c b4 42 cd 13 72
0000c0 05 bb 00 70 eb 7d b4 08 cd 13 73 0a f6 c2 80 0f
0000d0 84 f0 00 e9 8d 00 be 05 7c c6 44 ff 00 66 31 c0
0000e0 88 f0 40 66 89 44 04 31 d2 88 ca c1 e2 02 88 e8
0000f0 88 f4 40 89 44 08 31 c0 88 d0 c0 e8 02 66 89 04
000100 66 a1 44 7c 66 31 d2 66 f7 34 88 54 0a 66 31 d2
000110 66 f7 74 04 88 54 0b 89 44 0c 3b 44 08 7d 3c 8a
000120 54 0d c0 e2 06 8a 4c 0a fe c1 08 d1 8a 6c 0c 5a
000130 8a 74 0b bb 00 70 8e c3 31 db b8 01 02 cd 13 72
000140 2a 8c c3 8e 06 48 7c 60 1e b9 00 01 8e db 31 f6
000150 31 ff fc f3 a5 1f 61 ff 26 42 7c be 7f 7d e8 40
000160 00 eb 0e be 84 7d e8 38 00 eb 06 be 8e 7d e8 30
000170 00 be 93 7d e8 2a 00 eb fe 47 52 55 42 20 00 47
000180 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 65
000190 61 64 00 20 45 72 72 6f 72 00 bb 01 00 b4 0e cd
0001a0 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 00 00 00
0001b0 00 00 00 00 00 00 00 00 c4 15 0a 00 00 00 80 20
0001c0 21 00 83 dd 1e 3f 00 08 00 00 00 a0 0f 00 00 dd
0001d0 1f 3f 8e fe ff ff 00 a8 0f 00 00 58 70 02 00 00
0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa
OS如果有多重引导,还有个多重引导程序的概念。
linux 1.0 主引导程序
引导段(BOOTSEG)
初始段(INITSEG)
装载段(SETUPSEG)
系统段(SYSSEG)
bootsect.S
setup.S
head.S
linux 1.3.0 主引导程序
bootsect.S
编译链接
gcc -D__KERNEL__ -I/cygdrive/d/home/admin/workstation/linux/linux-1.3.0/linux/include -E -traditional -DSVGA_MODE=NORMAL_VGA -DRAMDISK=512 bootsect.S -o bootsect.asm
as86 -0 -a -o bootsect.o bootsect.asm
ld86 -0 -s -o bootsect bootsect.o
在linux下编译链接是没问题的。
我找到as86,ld86的源代码在cygwin下安装,安装没问题,编译链接都能通过,但生成的bootsect文件大小为544字节,不是512字节,这就有问题了。
linux 2.6.0 主引导程序
SETUPSECTS = 4 /* default nr of setup-sectors */ BOOTSEG = 0x07C0 /* original address of boot-sector */ INITSEG = 0x9000 /* we move boot here - out of the way */ SETUPSEG = 0x9020 /* setup starts here */ SYSSEG = 0x1000 /* system loaded at 0x10000 (65536) */ SYSSIZE = 0x7F00 /* system size: # of 16-byte clicks */ /* to be loaded */ ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */ SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */ .code16 .text .global _start _start: # Normalize the start address jmpl $BOOTSEG, $start2 start2: movw %cs, %ax movw %ax, %ds movw %ax, %es movw %ax, %ss movw $0x7c00, %sp sti cld movw $bugger_off_msg, %si msg_loop: lodsb andb %al, %al jz die movb $0xe, %ah movw $7, %bx int $0x10 jmp msg_loop die: # Allow the user to press a key, then reboot xorw %ax, %ax int $0x16 int $0x19 # int 0x19 should never return. In case it does anyway, # invoke the BIOS reset code... ljmp $0xf000,$0xfff0 bugger_off_msg: .ascii "Direct booting from floppy is no longer supported.\r\n" .ascii "Please use a boot loader program instead.\r\n" .ascii "\n" .ascii "Remove disk and press any key to reboot . . .\r\n" .byte 0 # Kernel attributes; used by setup .org 497 setup_sects: .byte SETUPSECTS root_flags: .word 1 syssize: .word SYSSIZE swap_dev: .word SWAP_DEV ram_size: .word 0 vid_mode: .word 0xfffd root_dev: .word ROOT_DEV boot_flag: .word 0xAA55
>as boot_test.asm -o boot_test.o
>objcopy -O binary boot_test.o boot_test.bin
>bximage
Please choose one [0] 1
Please type hd or fd. [hd] fd
Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M.
[1.44M] 1.44M
What should be the name of the image?
[a.img] boot_test.asm.img
>dd if=boot_test.bin of=boot_test.asm.img bs=512 count=1 conv=notrunc
内存管理
进程管理
进程管理
linux 当前进程(current)
static inline struct task_struct * get_current(void) { return current_thread_info()->task; } #define current get_current()
/* how to get the thread information struct from C */ static inline struct thread_info *current_thread_info(void) { struct thread_info *ti; __asm__("andl %%esp,%0; ":"=r" (ti) : "0" (~8191UL)); return ti; }
struct thread_info { struct task_struct *task; /* main task structure */ struct exec_domain *exec_domain; /* execution domain */ unsigned long flags; /* low level flags */ unsigned long status; /* thread-synchronous flags */ __u32 cpu; /* current CPU */ __s32 preempt_count; /* 0 => preemptable, <0 => BUG */ mm_segment_t addr_limit; /* thread address space: 0-0xBFFFFFFF for user-thead 0-0xFFFFFFFF for kernel-thread */ struct restart_block restart_block; __u8 supervisor_stack[0]; };
task_struct结构
\include\linux\sched.h
struct task_struct { volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ struct thread_info *thread_info; atomic_t usage; unsigned long flags; /* per process flags, defined below */ unsigned long ptrace; int lock_depth; /* Lock depth */ int prio, static_prio; struct list_head run_list; prio_array_t *array; unsigned long sleep_avg; long interactive_credit; unsigned long long timestamp; int activated; unsigned long policy; cpumask_t cpus_allowed; unsigned int time_slice, first_time_slice; struct list_head tasks; struct list_head ptrace_children; struct list_head ptrace_list; struct mm_struct *mm, *active_mm; /* task state */ struct linux_binfmt *binfmt; int exit_code, exit_signal; int pdeath_signal; /* The signal sent when the parent dies */ /* ??? */ unsigned long personality; int did_exec:1; pid_t pid; pid_t __pgrp; /* Accessed via process_group() */ pid_t tty_old_pgrp; pid_t session; pid_t tgid; /* boolean value for session group leader */ int leader; /* * pointers to (original) parent process, youngest child, younger sibling, * older sibling, respectively. (p->father can be replaced with * p->parent->pid) */ struct task_struct *real_parent; /* real parent process (when being debugged) */ struct task_struct *parent; /* parent process */ struct list_head children; /* list of my children */ struct list_head sibling; /* linkage in my parent's children list */ struct task_struct *group_leader; /* threadgroup leader */ /* PID/PID hash table linkage. */ struct pid_link pids[PIDTYPE_MAX]; wait_queue_head_t wait_chldexit; /* for wait4() */ struct completion *vfork_done; /* for vfork() */ int __user *set_child_tid; /* CLONE_CHILD_SETTID */ int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */ unsigned long rt_priority; unsigned long it_real_value, it_prof_value, it_virt_value; unsigned long it_real_incr, it_prof_incr, it_virt_incr; struct timer_list real_timer; struct list_head posix_timers; /* POSIX.1b Interval Timers */ unsigned long utime, stime, cutime, cstime; unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; /* context switch counts */ u64 start_time; /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */ unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap; /* process credentials */ uid_t uid,euid,suid,fsuid; gid_t gid,egid,sgid,fsgid; int ngroups; gid_t groups[NGROUPS]; kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1; struct user_struct *user; /* limits */ struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; char comm[16]; /* file system info */ int link_count, total_link_count; struct tty_struct *tty; /* NULL if no tty */ /* ipc stuff */ struct sysv_sem sysvsem; /* CPU-specific state of this task */ struct thread_struct thread; /* filesystem information */ struct fs_struct *fs; /* open file information */ struct files_struct *files; /* namespace */ struct namespace *namespace; /* signal handlers */ struct signal_struct *signal; struct sighand_struct *sighand; sigset_t blocked, real_blocked; struct sigpending pending; unsigned long sas_ss_sp; size_t sas_ss_size; int (*notifier)(void *priv); void *notifier_data; sigset_t *notifier_mask; void *security; /* Thread group tracking */ u32 parent_exec_id; u32 self_exec_id; /* Protection of (de-)allocation: mm, files, fs, tty */ spinlock_t alloc_lock; /* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */ spinlock_t proc_lock; /* context-switch lock */ spinlock_t switch_lock; /* journalling filesystem info */ void *journal_info; /* VM state */ struct reclaim_state *reclaim_state; struct dentry *proc_dentry; struct backing_dev_info *backing_dev_info; struct io_context *io_context; unsigned long ptrace_message; siginfo_t *last_siginfo; /* For ptrace use. */ };
初始化
\arch\x86_64\kernel\init_task.c
/* * Initial task structure. * * All other task structs will be allocated on slabs in fork.c */ struct task_struct init_task = INIT_TASK(init_task);INIT_TASK(init_task):
/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB) */ #define INIT_TASK(tsk) \ { \ .state = 0, \ .thread_info = &init_thread_info, \ .usage = ATOMIC_INIT(2), \ .flags = 0, \ .lock_depth = -1, \ .prio = MAX_PRIO-20, \ .static_prio = MAX_PRIO-20, \ .policy = SCHED_NORMAL, \ .cpus_allowed = CPU_MASK_ALL, \ .mm = NULL, \ .active_mm = &init_mm, \ .run_list = LIST_HEAD_INIT(tsk.run_list), \ .time_slice = HZ, \ .tasks = LIST_HEAD_INIT(tsk.tasks), \ .ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children), \ .ptrace_list = LIST_HEAD_INIT(tsk.ptrace_list), \ .real_parent = &tsk, \ .parent = &tsk, \ .children = LIST_HEAD_INIT(tsk.children), \ .sibling = LIST_HEAD_INIT(tsk.sibling), \ .group_leader = &tsk, \ .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\ .real_timer = { \ .function = it_real_fn \ }, \ .cap_effective = CAP_INIT_EFF_SET, \ .cap_inheritable = CAP_INIT_INH_SET, \ .cap_permitted = CAP_FULL_SET, \ .keep_capabilities = 0, \ .rlim = INIT_RLIMITS, \ .user = INIT_USER, \ .comm = "swapper", \ .thread = INIT_THREAD, \ .fs = &init_fs, \ .files = &init_files, \ .signal = &init_signals, \ .sighand = &init_sighand, \ .pending = { \ .list = LIST_HEAD_INIT(tsk.pending.list), \ .signal = {{0}}}, \ .blocked = {{0}}, \ .posix_timers = LIST_HEAD_INIT(tsk.posix_timers), \ .alloc_lock = SPIN_LOCK_UNLOCKED, \ .proc_lock = SPIN_LOCK_UNLOCKED, \ .switch_lock = SPIN_LOCK_UNLOCKED, \ .journal_info = NULL, \ }
pthread
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
文件系统
linux使用的是ext文件系统。ext文件系统现在已经有好几个版本,包括ext2,ext3以及ext4。实际上还存在ext 0.x,1.x,2.x,3.x,4.x等版本。
linux同时支持其他很多文件系统格式,如fat,fat32,vfx,xfx等。
关于ext文件系统
参考另一篇文章:https://www.iteye.com/blog/lobin-2311779
linux提供了一些工具来格式化生成ext格式的文件系统
后面在通过源代码来分析ext文件系统之前,可以先通过这些工具来格式化生成ext文件系统进行分析。
ext2
ext2超级块
\include\linux\ext2_fs.h
/* * Structure of the super block */ struct ext2_super_block { __u32 s_inodes_count; /* Inodes count */ __u32 s_blocks_count; /* Blocks count */ __u32 s_r_blocks_count; /* Reserved blocks count */ __u32 s_free_blocks_count; /* Free blocks count */ __u32 s_free_inodes_count; /* Free inodes count */ __u32 s_first_data_block; /* First Data Block */ __u32 s_log_block_size; /* Block size */ __s32 s_log_frag_size; /* Fragment size */ __u32 s_blocks_per_group; /* # Blocks per group */ __u32 s_frags_per_group; /* # Fragments per group */ __u32 s_inodes_per_group; /* # Inodes per group */ __u32 s_mtime; /* Mount time */ __u32 s_wtime; /* Write time */ __u16 s_mnt_count; /* Mount count */ __s16 s_max_mnt_count; /* Maximal mount count */ __u16 s_magic; /* Magic signature */ __u16 s_state; /* File system state */ __u16 s_errors; /* Behaviour when detecting errors */ __u16 s_minor_rev_level; /* minor revision level */ __u32 s_lastcheck; /* time of last check */ __u32 s_checkinterval; /* max. time between checks */ __u32 s_creator_os; /* OS */ __u32 s_rev_level; /* Revision level */ __u16 s_def_resuid; /* Default uid for reserved blocks */ __u16 s_def_resgid; /* Default gid for reserved blocks */ /* * These fields are for EXT2_DYNAMIC_REV superblocks only. * * Note: the difference between the compatible feature set and * the incompatible feature set is that if there is a bit set * in the incompatible feature set that the kernel doesn't * know about, it should refuse to mount the filesystem. * * e2fsck's requirements are more strict; if it doesn't know * about a feature in either the compatible or incompatible * feature set, it must abort and not try to meddle with * things it doesn't understand... */ __u32 s_first_ino; /* First non-reserved inode */ __u16 s_inode_size; /* size of inode structure */ __u16 s_block_group_nr; /* block group # of this superblock */ __u32 s_feature_compat; /* compatible feature set */ __u32 s_feature_incompat; /* incompatible feature set */ __u32 s_feature_ro_compat; /* readonly-compatible feature set */ __u8 s_uuid[16]; /* 128-bit uuid for volume */ char s_volume_name[16]; /* volume name */ char s_last_mounted[64]; /* directory where last mounted */ __u32 s_algorithm_usage_bitmap; /* For compression */ /* * Performance hints. Directory preallocation should only * happen if the EXT2_COMPAT_PREALLOC flag is on. */ __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ __u16 s_padding1; /* * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set. */ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ __u32 s_journal_inum; /* inode number of journal file */ __u32 s_journal_dev; /* device number of journal file */ __u32 s_last_orphan; /* start of list of inodes to delete */ __u32 s_hash_seed[4]; /* HTREE hash seed */ __u8 s_def_hash_version; /* Default hash version to use */ __u8 s_reserved_char_pad; __u16 s_reserved_word_pad; __u32 s_default_mount_opts; __u32 s_first_meta_bg; /* First metablock block group */ __u32 s_reserved[190]; /* Padding to the end of the block */ };
相关推荐
util-linux-ng-2.17源码(含fdisk) Here is a list of all documented files with brief descriptions: util-linux-ng-2.17.2/disk-utils/blockdev.c [code] util-linux-ng-2.17.2/disk-utils/cramfs.h [code] ...
Linux 2.6.11.12内核源码注释是一份极其珍贵的资料,它涵盖了Linux内核的多个关键组件,包括同步机制、信号处理、内存管理、进程调度、文件系统以及网络系统。这些是Linux内核运行的核心组成部分,对于理解Linux操作...
jdk1.7_linux Linux版零积分jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk1.7_linux Linux版零积分免费下载jdk...
Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络通信)Linux网络调试助手(网络...
主要包括Linux的基本概念和操作,Linux的树型结构,Linux的文本编辑,Linux的安装和启动,用户管理,Shell编程技术,进程管理,C编译器,系统扩充,维护与监视,Linux的图形界面,网络的基本概念与设置,Linux在网络...
### Linux内核源代码情景分析知识点总结 #### 第1章 预备知识 - **1.1 Linux内核简介** - Linux是由Linus Torvalds在1991年开始开发的操作系统内核,其设计思想受到Unix的影响,但并不直接继承Unix的任何代码。 -...
【大学生攻克Linux系统教程】 本教程专为对Linux操作系统感兴趣的初学者设计,旨在提供一个从零开始学习Linux的全面指南。教程内容涵盖了Linux系统的安装、基本操作、文本编辑器VI的使用、调试工具GDB的基础知识,...
linux
首先启动虚拟机软件VM(虚拟Linux系统 rhel4 已经安装完毕) 1.设置VMware的cd-rom→ Use ISO image → 本文件(linux.iso) 2.启动虚拟机 3.用超级用户root登录 4.登录成功后,Ctrl+Alt ,取出鼠标,点选菜单栏,vm → ...
这是半年来,在看ULA的过程中,针对Linux 2.6.24内核顺手做的一点注释。内容不多,个人觉得文件系统和USB这两个模块的注释还有一点意思。 所有注释都是中文,您可以与标准2.6.24内核进行比较,看看具体的注释内容。 ...
在Linux系统中,设备驱动程序是操作系统与硬件设备之间的桥梁,它们使得操作系统能够高效地管理和控制硬件资源。这里我们主要探讨的是与嵌入式开发相关的Linux设备驱动程序,特别是针对ARM架构,如6410处理器的开发...
Linux操作系统入门书,比较全面 目录 0 前言 0.1 什么是Linux? 0.2 本手册概述 0.3 速查信息 0.4 从以前版本的Red Hat Linux升级 0.5 开发者的话 0.6 编者的话 1 Red Hat Linux 5.1新特性 1.1 安装性能的...
基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版的聊天室基于Linux 下qt改版...
linux 0.11 源码下载 本代码是目前能够找到的最早的Linux的内核版本,Linux 0.11内核是Linux内核的早期版本,于1991年由Linus Torvalds编写并发布。作为一个基于UNIX的操作系统内核,它的源代码包含了核心代码和一些...
Linux C函数库参考手册是一套Linux C函数使用手册,这里还提供了LinuxC函数手册chm,帮助大家查找。在Linux下,使用到的C语言函数中文手册,全都有实例,如果你是大神,完全不需要,如果你对英文的手册感到头疼,...
在Linux系统中,由于默认不支持Microsoft Internet Explorer(简称IE),因此如果需要在Linux环境下运行IE,就需要借助一些工具来实现。本篇文章将详细介绍在Linux系统下安装IE所需的三个关键包:Wine、CabExtract和...
Linux,在今天的广大电脑爱好者心中已经不再是那个遥不可及的新东西了,如果说几年前的 Linux 是星星之火的话,如今 Linux 不仅在服务器领域的应用取得较大进展,而且在桌面应用领域也有越来越多的人选择使用。Linux...
标题中的“PL2303 Linux驱动”指的是用于Linux操作系统中的PL2303 USB转串口芯片的驱动程序。PL2303是Prolific Technology公司生产的一款广泛使用的USB到UART桥接器,它允许计算机通过USB接口与各种串行设备进行通信...
《Linux设备驱动开发详解-基于最新的Linux4.0内核》是一本深入探讨Linux设备驱动程序开发的专业书籍,其源码提供了丰富的实践示例,帮助读者理解如何在Linux操作系统下编写和调试驱动程序。该书涵盖了从基础概念到...
Linux入门教程是一个Linux入门精华基础版,包含常见的linux命令应用,linux 入门必备哦!深入浅出介绍linux知识,针对初学者的linux教程,也可作为程序员必备工具书。需要的朋友可下载试试! 内容 第一章Linux入门...