DIY Linux operating system

Source: Internet
Author: User
Tags network function uuid

DIY Linux operating system

Self-made Linux system

Overview of the steps:

1, create a new hard disk
2, create two partitions on the new hard disk, one when the boot partition, one when/partition
3, format and mount two partitions
4, installing grub to the target disk
5, providing configuration files for Grub
6, copying kernel files and initrd files
7, creating the target host root file system
8, porting bash commands and their library files to the root file system
9, load module, realize network function
Ten, start the test

specific The procedure is as follows:

1) Add a new hard drive to the CentOS 6 system, and then start the demo as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/47/wKioL1fanDvzxq6sABaUN8GC7PE230.gif "title=" 2.gif " alt= "Wkiol1fandvzxq6sabaun8gc7pe230.gif"/>

 2) View the newly added hard disk and create a file system for the added disk partition;

[[EMAIL PROTECTED] ~]# FDISK -L /DEV/SD[A-Z]DISK /DEV/SDA: 85.9 GB,  85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersunits =  cylinders of 16065 * 512 = 8225280 bytesSector size  ( logical/physical): 512 bytes / 512 bytesi/o size  (minimum/optimal):  512 bytes / 512 bytesdisk identifier: 0x0007eba7   device  boot      start         end       Blocks   Id  System/dev/sda1   *            1           26      204800   83  linuxpartition 1  does not end on cylinder boundary./dev/sda2               26        7859    62914560    8e  Linux LVM/dev/sda3             7860        9165    10490445    83  Linux/dev/sda4             9166       10443    10265535     5  Extended/dev/sda5             9166        9819     5253223+  83   linuxdisk /dev/sdb: 21.5 gb, 21474836480 bytes   # You can see the newly added hard disk  sdb255 heads, 63 sectors/track, 2610 cylindersunits = cylinders of 16065 *  512 = 8225280 bytesSector size  (logical/physical):  512 bytes /  512 bytesI/O size  (minimum/optimal):  512 bytes / 512 bytesdisk  identifier: 0x00000000

divided into three primary partitions, respectively, as the root partition, swap partition and boot partition, and create the corresponding file system, operation as follows :

[Email protected] ~]# fdisk/dev/sdb #创建分区, #创建文件系统如下命令: [[email protected] ~]# Mkfs.ext4/dev/sdb1[[email protected] ~]# m Kswap/dev/sdb2[[email protected] ~]# mkfs.ext4/dev/sdb3# view created partition [[email protected] ~]# blkid/dev/sdb1:uuid= " f4921d76-f089-4cb6-8f47-aff34711cb7a "type=" Ext4 "/dev/sdb2:uuid=" 3eaa649e-a5c0-4f9c-8887-453368419238 "TYPE=" Swap "/dev/sdb3:uuid=" 286c857d-8f52-465f-9ed6-8eeaa3363743 "type=" Ext4 "

  3 "Create a boot directory , and mount the boot partition (SDB1) on ;

[[email protected] ~]# mkdir /mnt/boot[[email protected] ~]# mount / dev/sdb1 /mnt/boot[[email protected] ~]# dffilesystem            1k-blocks    used available use% mounted  on/dev/mapper/vg0-root  20511356 1112808  18349972   6% / tmpfs                    502068       0    502068   0 % /dev/shm/dev/sda1                194241   34199    149802  19% /boot/dev/mapper/vg0-usr    10190136 2473060   7192788  26% /usr/dev/mapper/vg0-var    20511356  489148  18973632   3% /var/dev/sda5               5039592   10352   4766580    1% /home/dev/sdb1                104769    1550     97598    2% /mnt/boot  #  Mounted Equipment SDB1

  4) create grub and view;

[[email protected] ~]# ls /mnt/boot/lost+found[[email protected] ~]#  grub-install --root-directory=/mnt /dev/sdb  #创建grubProbing  devices to guess  bios drives. this may take a long time. Installation finished. no error reported. This is the contents of the device map /mnt/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[[email protected] ~]#  ls /mnt/boot/grub   lost+found[[email protected] ~]#  ls /mnt/boot/grub/device.map      fat_stage1_5  iso9660_stage1_5  minix_stage1_5      stage1&nbsP; ufs2_stage1_5    xfs_stage1_5e2fs_stage1_5  ffs_stage1_5  jfs_ Stage1_5      reiserfs_stage1_5  stage2  vstafs_stage1_5

     5 "to be a real system, you need a kernel file, INITRD and grub/grub.conf these files;

[[email protected] ~]# cp /boot/ vmlinuz-2.6.32-642.el6.x86_64 /mnt/boot/vmlinuz[[email protected] ~]# cp /boot/ Initramfs-2.6.32-642.el6.x86_64.img /mnt/boot/initramfs.img[[email protected] ~]# vim  /mnt/boot/grub/grub.conf   #手动编写配置文件  default=0 timeout=5 title CentOS  (Express)          root  (hd0,0)  #  under current The second disk should be (HD1, 0), but if used from other devices (hd0,0)      kernel /vmlinuz ro root=/dev/sda3    #加载的根目录所在的分区 because the first disk on other devices is  /dev/sda3     initrd /initramfs.img   #内核匹配的ramfs文件 

  6 "as a root file system, You need to mount and create a subdirectory under the root filesystem that you want to correspond to:

[[email protected] ~]# mkdir /mnt/sysroot[[email protected] ~]# mount  /dev/sdb3 /mnt/sysroot/[[email protected] ~]# cd /mnt/sysroot/[[email protected]  sysroot]# lslost+found[[email protected] sysroot]# mkdir -pv etc bin  sbin lib lib64 dev proc sys mnt var usr home root  tmp mediamkdir: created directory  ' etc ' mkdir: created directory  ' bin ' mkdir: created directory  ' sbin ' mkdir: created directory  ' Lib ' mkdir: created  directory  ' lib64 ' mkdir: created directory  ' Dev ' mkdir: created directory   ' proc ' mkdir: created directory  ' sys ' mkdir: created directory  ' mnt ' mkdir:  created directory  ' var ' mkdir: created directory  ' usr ' mkdir: created  directory  ' Home ' mkdir: created directory  ' root ' mkdir: created directory  ' tmp ' mkdir: created  directory  ' media ' [[email protected] sysroot]# lsbin  dev  etc   home  lib  lib64  lost+found  media  mnt   proc  root  sbin  sys  tmp  usr  var

  7 "The directory for the root filesystem is there, But it also requires a program to run, bash, and a dynamically compiled shared library file

[[email protected] sysroot]# cp /bin/bash /mnt/ sysroot/bin   #复制bash [[email protected] sysroot]# ldd /bin/bash #  View library files linux-vdso.so.1 =>   (0x00007ffd127d9000) libtinfo.so.5 => /lib64/ libtinfo.so.5  (0x0000003278e00000) libdl.so.2 => /lib64/libdl.so.2  (0x000000326f200000) libc.so.6 => /lib64/libc.so.6  (0x000000326f600000)/lib64/ld-linux-x86-64.so.2  ( 0x000000326ee00000)  #  Copy the files in the shared library to the lib64 created in the root directory [[email protected] sysroot]# cp / lib64/libtinfo.so.5 /mnt/sysroot/lib64[[email protected] sysroot]# cp /lib64/ libdl.so.2 /mnt/sysroot/lib64[[email protected] sysroot]# cp /lib64/libc.so.6 / mnt/sysroot/lib64[[email protected] sysroot]# cp /lib64/ld-linux-x86-64.so.2 /mnt/ Sysroot/lib64 

8) As above, the basic operation has been completed, using chroot to switch the root, to test, as follows:

[[email protected] sysroot]# chroot/mnt/sysroot/# Toggle root bash-4.1# bash-4.1# bash-4.1# ls # because there is no copy command, you can only use the built-in command if you need to use an external command, you can copy the commands and the libraries that depend on them. Bash:ls:command not foundbash-4.1# pwd/bash-4.1# exitexit

9) Finally, we are editing the configuration file/mnt/boot/grub/grub.conf

[[email protected] ~]# vim/mnt/boot/grub/grub.confdefault=0timeout=5title CentOS (Express) root (hd0,0) kernel /vmlinuz ro Root=/dev/sda3 Init=/bin/bash # indicates that the requirement to run a qualifying operation is/bin/bash instead of/sbin/init so the office uses bash as the first process of user space directly initrd/i Nitramfs.img

10) Last Sync

[[Email protected] ~]# Sync

11) We create a new virtual machine, change the hard drive to the newly created disk, test system can be started?

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/4B/wKiom1fbXj3BezK9AACC8PyI_Jc126.png "title=" 1.png " alt= "Wkiom1fbxj3bezk9aacc8pyi_jc126.png"/>

Start this virtual machine, such as: Press the E key to see the system files we created, select the kernel, press the B key to start

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/49/wKioL1fbXraQpDp-ABToss86vNM266.gif "title=" Screengif.gif "alt=" Wkiol1fbxraqpdp-abtoss86vnm266.gif "/>

Select the kernel, press the B key to start, found the system error, what reason? There may be no SELinux policy added

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/87/4C/wKiom1fbYTHSmxD2AAAwuZm83uM581.png "title=" 2.png " alt= "Wkiom1fbythsmxd2aaawuzm83um581.png"/> Selected kernel, press the E key, enter edit mode, add Selinux=0, reboot, found to start normally

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/87/4C/wKiom1fbYuTC4EwrAAAtjQb-BJQ839.png "title=" 3.png " alt= "Wkiom1fbyutc4ewraaatjqb-bjq839.png"/>

Here, a mini version of Linux was born, can be installed on their own mobile USB drive and other devices, here do not explain too much


DIY Linux operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.