自制Linux操作系统
自制Linux操作系统
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.添加一块新的磁盘设备
1>.将虚拟机关机,点击"编辑虚拟机设置"
2>.点击"添加"按钮
3>.选择添加虚拟硬件的类型为"硬盘"并点击下一步
4>.点击下一步
5>.点击下一步
6>.点击"将虚拟磁盘存储为单个文件"并点击下一步
7>.自定义新硬盘的名称
8>.点击保存按钮
9>.启动虚拟机
二.分区并创建文件系统
1>.查看硬盘资源
[root@yinzhengjie ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 : .7G rom
sda : 500G disk
├─sda1 : 500M part /boot
└─sda2 : .5G part
├─vg_node200-lv_root (dm-) : 50G lvm /
├─vg_node200-lv_swap (dm-) : .9G lvm [SWAP]
└─vg_node200-lv_home (dm-) : .7G lvm /home
sdb : 20G disk
[root@yinzhengjie ~]#
2>.使用fdisk命令对sdb硬盘进行分区操作
[root@yinzhengjie ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 : .7G rom
sda : 500G disk
├─sda1 : 500M part /boot
└─sda2 : .5G part
├─vg_node200-lv_root (dm-) : 50G lvm /
├─vg_node200-lv_swap (dm-) : .9G lvm [SWAP]
└─vg_node200-lv_home (dm-) : .7G lvm /home
sdb : 20G disk
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xbebd0e26.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xbebd0e26 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +10G Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xbebd0e26 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +2G Command (m for help): t
Partition number (-):
Hex code (type L to list codes):
Changed system type of partition to (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0xbebd0e26 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux swap / Solaris Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 : .7G rom
sda : 500G disk
├─sda1 : 500M part /boot
└─sda2 : .5G part
├─vg_node200-lv_root (dm-) : 50G lvm /
├─vg_node200-lv_swap (dm-) : .9G lvm [SWAP]
└─vg_node200-lv_home (dm-) : .7G lvm /home
sdb : 20G disk
├─sdb1 : 1G part
├─sdb2 : 10G part
└─sdb3 : 2G part
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fdisk /dev/sdb
3>.对分区的磁盘进行格式化操作
[root@yinzhengjie ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 : .7G rom
sda : 500G disk
├─sda1 : 500M part /boot
└─sda2 : .5G part
├─vg_node200-lv_root (dm-) : 50G lvm /
├─vg_node200-lv_swap (dm-) : .9G lvm [SWAP]
└─vg_node200-lv_home (dm-) : .7G lvm /home
sdb : 20G disk
├─sdb1 : 1G part
├─sdb2 : 10G part
└─sdb3 : 2G part
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkfs.ext4 /dev/sdb1
[root@yinzhengjie ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkfs.ext4 /dev/sdb2
[root@yinzhengjie ~]# mkswap /dev/sdb3
Setting up swapspace version , size = KiB
no label, UUID=7cfded20-b58a---23c4842c7dca
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkswap /dev/sdb3
[root@yinzhengjie ~]# blkid
/dev/mapper/vg_node200-lv_root: UUID="fb2cc473-bcf1-4e0d-9fff-71f7aa018cc6" TYPE="ext4"
/dev/sda1: UUID="6148dc57-76a2-4214-b4d5-5af9c5b40576" TYPE="ext4"
/dev/sda2: UUID="MS8oog-4gRp-iB4D-bpwh-G9R0-BQ2R-U2wseb" TYPE="LVM2_member"
/dev/sdb1: UUID="fa9f112f-de3c-49e0-a14f-f33213047bb2" TYPE="ext4"
/dev/sdb2: UUID="6c60d0e6-5cca-443a-8123-c163f3523ce0" TYPE="ext4"
/dev/sdb3: UUID="7cfded20-b58a-4131-9055-23c4842c7dca" TYPE="swap"
/dev/mapper/vg_node200-lv_swap: UUID="a0fd4399-0a45-48ac-817a-3b6c830f63b4" TYPE="swap"
/dev/mapper/vg_node200-lv_home: UUID="12c57023-efb5-4f61-8c90-c672a3a24dcc" TYPE="ext4"
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
三.挂载boot
1>.创建挂载点(注意, 子目录必须为boot哟~)
[root@yinzhengjie ~]# mkdir /mylinux/boot -pv
mkdir: created directory `/mylinux'
mkdir: created directory `/mylinux/boot'
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
2>.将规划的boot分区挂载到咱们创建的挂载点上
[root@yinzhengjie ~]# mount /dev/sdb1 /mylinux/boot/
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll /mylinux/boot/
total
drwx------ root root Dec : lost+found
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
3>.安装grub
[root@yinzhengjie ~]# ll /mylinux/boot/
total
drwx------ root root Dec : lost+found
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# grub-install --root-directory=/mylinux/ /dev/sdb
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mylinux//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
(hd1) /dev/sdb
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll /mylinux/boot/
total
drwxr-xr-x root root Dec : grub
drwx------ root root Dec : lost+found
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ls /mylinux/boot/grub/
device.map fat_stage1_5 iso9660_stage1_5 minix_stage1_5 stage1 ufs2_stage1_5 xfs_stage1_5
e2fs_stage1_5 ffs_stage1_5 jfs_stage1_5 reiserfs_stage1_5 stage2 vstafs_stage1_5
[root@yinzhengjie ~]#
4>.恢复内核和initramfs文件(即安装内核文件,我这里直接从系统拷贝就懒得挂载光盘安装啦)
[root@yinzhengjie ~]# cp /boot/vmlinuz-2.6.-.el6.x86_64 /mylinux/boot/vmlinuz
[root@yinzhengjie ~]# cp /boot/initramfs-2.6.-.el6.x86_64.img /mylinux/boot/initramfs.img
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll /mylinux/boot/
total
drwxr-xr-x root root Dec : grub
-rw------- root root Dec : initramfs.img
drwx------ root root Dec : lost+found
-rwxr-xr-x root root Dec : vmlinuz
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# vim /mylinux/boot/grub/grub.conf
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# cat /mylinux/boot/grub/grub.conf #自定义grub.conf配置文件
default=
timeout=
title mylinux
kernel /vmlinuz root=/dev/sda2 selinux= init=/bin/bash
initrd /initramfs.img
[root@yinzhengjie ~]#
四.复制bash,常用命令和相关库文件
1>.创建一级目录
[root@yinzhengjie ~]# mkdir /mylinux/sysroot
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount /dev/sdb2 /mylinux/sysroot/
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkdir -pv /mylinux/sysroot/{etc,lib,lib64,bin,sbin,tmp,var,usr,sys,proc,opt,home,root,boot,dev,mnt,media}
mkdir: created directory `/mylinux/sysroot/etc'
mkdir: created directory `/mylinux/sysroot/lib'
mkdir: created directory `/mylinux/sysroot/lib64'
mkdir: created directory `/mylinux/sysroot/bin'
mkdir: created directory `/mylinux/sysroot/sbin'
mkdir: created directory `/mylinux/sysroot/tmp'
mkdir: created directory `/mylinux/sysroot/var'
mkdir: created directory `/mylinux/sysroot/usr'
mkdir: created directory `/mylinux/sysroot/sys'
mkdir: created directory `/mylinux/sysroot/proc'
mkdir: created directory `/mylinux/sysroot/opt'
mkdir: created directory `/mylinux/sysroot/home'
mkdir: created directory `/mylinux/sysroot/root'
mkdir: created directory `/mylinux/sysroot/boot'
mkdir: created directory `/mylinux/sysroot/dev'
mkdir: created directory `/mylinux/sysroot/mnt'
mkdir: created directory `/mylinux/sysroot/media'
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll /mylinux/sysroot/
total
drwxr-xr-x root root Dec : bin
drwxr-xr-x root root Dec : boot
drwxr-xr-x root root Dec : dev
drwxr-xr-x root root Dec : etc
drwxr-xr-x root root Dec : home
drwxr-xr-x root root Dec : lib
drwxr-xr-x root root Dec : lib64
drwx------ root root Dec : lost+found
drwxr-xr-x root root Dec : media
drwxr-xr-x root root Dec : mnt
drwxr-xr-x root root Dec : opt
drwxr-xr-x root root Dec : proc
drwxr-xr-x root root Dec : root
drwxr-xr-x root root Dec : sbin
drwxr-xr-x root root Dec : sys
drwxr-xr-x root root Dec : tmp
drwxr-xr-x root root Dec : usr
drwxr-xr-x root root Dec : var
[root@yinzhengjie ~]#
2>.复制bash,常用命令和相关库文件
[root@yinzhengjie ~]# cat copycmd.sh
#!/bin/bash
#********************************************************************
#Author: yinzhengjie
#QQ:
#Date: --
#FileName: copycmd
#URL: http://www.cnblogs.com/yinzhengjie
#Description: Copy command and script of dependent Library
#Copyright notice: original works, no reprint! Otherwise, legal liability will be investigated.
#******************************************************************** read -t -p "Plesea input sysroot:>>> " ch_root [ ! -d $ch_root ] && mkdir $ch_root bincopy() {
if which $ &>/dev/null; then local cmd_path=`which --skip-alias $`
local bin_dir=`dirname $cmd_path`
[ -d ${ch_root}${bin_dir} ] || mkdir -p ${ch_root}${bin_dir}
[ -f ${ch_root}${cmd_path} ] || cp $cmd_path ${ch_root}${bin_dir}
return
else
echo "Command not found."
return
fi
} libcopy() {
local lib_list=$(ldd `which --skip-alias $` | grep -Eo '/[^[:space:]]+')
for loop in $lib_list;do
local lib_dir=`dirname $loop`
[ -d ${ch_root}${lib_dir} ] || mkdir -p ${ch_root}${lib_dir}
[ -f ${ch_root}${loop} ] || cp $loop ${ch_root}${lib_dir}
done
} read -p "Please input a command: " command while [ "$command" != "quit" ];do
if bincopy $command ;then
libcopy $command
fi
read -p "Please input a command or quit: " command
done
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# cat copycmd.sh
[root@yinzhengjie ~]# bash copycmd.sh
Plesea input sysroot:>>> /mylinux/sysroot
Please input a command: bash
Please input a command or quit: modprobe
Please input a command or quit: ifconfig
Please input a command or quit: ls
Please input a command or quit: mount
Please input a command or quit: ping
Please input a command or quit: cat
Please input a command or quit: vim
Please input a command or quit: blkid
Please input a command or quit: cp
Please input a command or quit: mv
Please input a command or quit: df
Please input a command or quit: insmod
Please input a command or quit: quit
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# locate e1000
/lib/modules/2.6.-.el6.x86_64/kernel/drivers/net/e1000
/lib/modules/2.6.-.el6.x86_64/kernel/drivers/net/e1000e
/lib/modules/2.6.-.el6.x86_64/kernel/drivers/net/e1000/e1000.ko
/lib/modules/2.6.-.el6.x86_64/kernel/drivers/net/e1000e/e1000e.ko
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# cp /lib/modules/2.6.-.el6.x86_64/kernel/drivers/net/e1000/e1000.ko /mylinux/sysroot/lib #拷贝网卡驱动
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# tree /mylinux/sysroot/
/mylinux/sysroot/
├── bin
│ ├── bash
│ ├── cat
│ ├── cp
│ ├── df
│ ├── ls
│ ├── mount
│ ├── mv
│ └── ping
├── boot
├── dev
├── etc
├── home
├── lib
│ └── e1000.ko
├── lib64
│ ├── ld-linux-x86-.so.
│ ├── libacl.so.
│ ├── libattr.so.
│ ├── libblkid.so.
│ ├── libcap.so.
│ ├── libcrypt.so.
│ ├── libc.so.
│ ├── libdl.so.
│ ├── libfreebl3.so
│ ├── libidn.so.
│ ├── libm.so.
│ ├── libnsl.so.
│ ├── libpthread.so.
│ ├── libresolv.so.
│ ├── librt.so.
│ ├── libselinux.so.
│ ├── libsepol.so.
│ ├── libtinfo.so.
│ ├── libutil.so.
│ └── libuuid.so.
├── lost+found
├── media
├── mnt
├── opt
├── proc
├── root
├── sbin
│ ├── blkid
│ ├── ifconfig
│ ├── insmod
│ └── modprobe
├── sys
├── tmp
├── usr
│ ├── bin
│ │ └── vim
│ └── lib64
│ ├── libgpm.so.
│ └── perl5
│ └── CORE
│ └── libperl.so
└── var directories, files
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# tree /mylinux/sysroot/
五.将硬盘放在另外一台虚拟机中使用
1>.将我们制作好的虚拟机硬盘拷贝出来
2>.在新的虚拟机中删除其自带的硬盘并添加一块新硬盘,选择"使用现有虚拟磁盘"并点击"下一步"
3>.点击完成后,启动操作系统
4>.启动虚拟机,发现这个菜单是咱们自定义的
5>.按一下回车键盘就会进入到一个bash中
6>.安装网卡驱动
7>自制的Linux操作系统总结
其实本篇博客案例的所制作的linux系统压根就不能在生产环境中使用,即使使用也是测试环境,这个这是告诉大家一个如何制作Linux的方案而已。 有了上面的操作基础我们大致明白了制作操作系统的方法和步骤,根据根据咱们的需求来定制化咱们需要的软件环境。一般情况下官方发布的标准版已经够咱们自己使用了。 博主推荐阅读:
http://www.linuxfromscratch.org/lfs/download.html
http://www.linuxfromscratch.org/lfs/downloads/stable/LFS-BOOK-9.0.pdf
自制Linux操作系统的更多相关文章
- 小白自制Linux开发板 二. u-boot移植
上一篇:小白自制Linux开发板 一. 瞎抄原理图与乱画PCB 中我们做了一个小型而没用的开发板,用的是Licheepi Nano的镜像,那从本篇开始我们开始自己构建它的灵魂吧. 我们都知道,PC在 ...
- Linux操作系统备份之三:通过二进制拷贝(dd)方式实现Linux操作系统数据的备份
前面有两篇文章,<Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份>和<Linux操作系统备份之二:通过tar拷贝分区实现Linux操作数据的在线备份& ...
- Linux操作系统备份之二:通过tar拷贝分区实现Linux操作数据的在线备份
http://www.tektea.com/archives/2163.html. 在<Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份>文章中,我们介绍了使 ...
- 安装linux操作系统
安装双操作系统; 1 0. 介绍: 1 1 实验环境: 2 2. 实验准备: 2 3.开始安装: 2 1 制作U盘启动工具: 2 2.安装LinuxOS. 3 2.1在windowOS中划分60G空间 ...
- 在Linux操作系统下备份恢复技术的应用 转自https://yq.aliyun.com/articles/50205?spm=5176.100239.blogcont24250.9.CfBYE9
摘要: 安全防护:在Linux操作系统下备份恢复技术的应用 原文参见:http://linux.chinaunix.net/techdoc/system/2005/12/19/925898.shtm ...
- 献给初学者:谈谈如何学习Linux操作系统
本文出自 “技术成就梦想” 博客,请务必保留此出处http://ixdba.blog.51cto.com/2895551/569329. 为了能把这篇不错的文章分享给大家.所以请允许我暂时用原创的形式 ...
- Linux操作系统备份之一:使用LVM快照实现Linux操作系统数据的在线备份
这里我们讨论Linux操作系统的备份. 在生产环境,客户都会要求做全系统的数据备份,用于系统崩溃后的一种恢复手段.这其中就包含操作系统数据的备份恢复. 由于是生产环境,客户都会要求备份不中断业务,也就 ...
- 安装Kali Linux操作系统Kali Linux无线网络渗透
安装Kali Linux操作系统Kali Linux无线网络渗透 Kali Linux是一个基于Debian的Linux发行版,它的前身是BackTrack Linux发行版.在该操作系统中,自带了大 ...
- 使用 /proc 文件系统来访问 linux操作系统 内核的内容 && 虚拟文件系统vfs及proc详解
http://blog.163.com/he_junwei/blog/static/19793764620152743325659/ http://www.01yun.com/other/201304 ...
随机推荐
- js之juery
目录 JQuery 属性选择器: 操作标签 文本操作 属性操作 文档处理 事件 JQuery 属性选择器: 属性选择器: [attribute] [attribute=value]// 属性等于 [a ...
- nuxt中localstorage的替代方案
采用异步的方式进行存储数据,更高效快速,使用localforage是你最好的选择 具体转载自博客 Heap Stack Blog(pingbook.top) Nuxt storage data in ...
- zabbix监控之zabbix-agent被动变为主动,搭建Proxy代理
1.Agent被动变为主动:环境设定 base2 172.25.78.12 zabbix-serverbase3 172.25.78.13 zabbix-agent开启服务 # 在服务端[root@b ...
- 【计算机视觉】stitching_detail算法介绍
已经不负责图像拼接相关工作,有技术问题请自己解决,谢谢. 一.stitching_detail程序运行流程 1.命令行调用程序,输入源图像以及程序的参数 2.特征点检测,判断是使用surf还是orb, ...
- C++ getline()的两种用法
getline():用于读入一整行的数据.在C++中,有两种getline函数.第一种定义在头文件<istream>中,是istream类的成员函数:第二种定义在头文件<string ...
- Lambda表达式和方法引用
1 , 为什么用lambda表达式 将重复固定的代码写法简单化 2 ,lambda表达式的实质 对函数式接口的实现(一个接口中只有一个抽象方法的接口被称为函数式接口) package com.mo ...
- [转帖]美团在Redis上踩过的一些坑-2.bgrewriteaof问题
美团在Redis上踩过的一些坑-2.bgrewriteaof问题 博客分类: redis 运维 aofaof rewrite 转载请注明出处哈:http://carlosfu.iteye.com/b ...
- FreeSWITCH 总体架构
[1]总体结构 [2]代码结构目录 [3]模块简介 Applications应用 mod_abstraction – 提供了一个抽象的API调用(未来有更多功能)Provides an abstrac ...
- Java计算工作日的工具类
有时候需要根据工作日计算指定的日期,也就是需要排除周六日. 1. 初版代码如下: package cn.xm.exam.utils; import java.util.Calendar; impor ...
- maven系列:deploy项目发布和上传repo仓库
在使用maven过程中,我们在开发阶段经常性的会有很多公共库处于不稳定状态,随时需要修改并发布,可能一天就要发布一次,遇到bug时,甚至一天要发布N次. 我们知道,maven的依赖管理是基于版本管理的 ...