新建硬盘并分区
[root@magedu ~]# fdisk -l /dev/sdb
Disk
/dev/sdb: 21.4 GB, 21474836480 bytes
255 heads,
63 sectors/track, 2610 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes
Device
Boot Start End Blocks Id System
/dev/sdb1 1 13 104391 83 Linux
/dev/sdb2 14 136 987997+ 83 Linux
格式化
mke2fs -j
/dev/sdb1
mke2fs -j
/dev/sdb2
挂载
[root@magedu ~]# cd /mnt
[root@magedu mnt]# mkdir boot
[root@magedu mnt]# mkdir sysroot
[root@magedu mnt]# mount /dev/sdb1 /mnt/boot
[root@magedu mnt]# mount /dev/sdb2 /mnt/sysroot
[root@magedu mnt]#
[root@magedu mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
158422636 7231864
143013520 5% /
/dev/sda1 101086 20186 75681 22% /boot
tmpfs 1028280 0 1028280 0% /dev/shm
/dev/sdb1 101086 5664 90203 6% /mnt/boot
/dev/sdb2 972436 17632 905408 2%
/mnt/sysroot
[root@magedu mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
152G 6.9G 137G 5% /
/dev/sda1 99M 20M 74M 22% /boot
tmpfs 1005M 0 1005M 0% /dev/shm
/dev/sdb1 99M 5.6M 89M 6% /mnt/boot
/dev/sdb2 950M 18M 885M 2% /mnt/sysroot
[root@magedu mnt]#
boot--安装grub
会自动到/mnt中找boot目录
[root@magedu mnt]# grub-install --root-directory=/mnt
/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 /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
[root@magedu mnt]#
boot--复制内核
[root@magedu boot]# cp /boot/vmlinuz-2.6.18-308.el5
/mnt/boot/vmlinuz
boot--生成initrd(解压—修改init—压缩)
[root@magedu boot]# cp
/boot/initrd-2.6.18-308.el5.img /root
[root@magedu boot]# cd /root
[root@magedu ~]# ls
anaconda-ks.cfg initrd-2.6.18-308.el5.img install.log install.log.syslog mbox
[root@magedu ~]# mv initrd-2.6.18-308.el5.img
initrd-2.6.18-308.el5.img.gz
[root@magedu ~]# gzip -d
initrd-2.6.18-308.el5.img.gz
[root@magedu ~]# ls
anaconda-ks.cfg initrd-2.6.18-308.el5.img install.log install.log.syslog mbox
[root@magedu ~]# file initrd-2.6.18-308.el5.img
initrd-2.6.18-308.el5.img: ASCII cpio archive (SVR4 with no
CRC)
[root@magedu ~]# mkdir test
[root@magedu ~]# cd test
[root@magedu test]# cpio -id <
../initrd-2.6.18-308.el5.img
17854
blocks
[root@magedu test]# ls
bin dev etc init lib proc sbin sys sysroot
[root@magedu test]#
修改init文件
mkrootdev -t ext3 -o defaults,ro
/dev/VolGroup00/LogVol00
为
mkrootdev -t ext3 -o defaults,ro
/dev/sdb2
[root@magedu test]# pwd
/root/test
[root@magedu test]# ls
bin dev etc init lib proc sbin sys sysroot
[root@magedu test]# find . | cpio -H newc --quiet -o | gzip
-9 /mnt/boot/initrd.gz
gzip:
/mnt/boot/initrd.gz: No such file or directory
[root@magedu test]# find . | cpio -H newc --quiet -o | gzip
-9 > /mnt/boot/initrd.gz
[root@magedu boot]# pwd
/mnt/boot
[root@magedu boot]# ll
total
5602
drwxr-xr-x
2 root root 1024 Aug 8 18:21 grub
-rw-r--r--
1 root root 3580656 Aug 8 18:48
initrd.gz
drwx------
2 root root 12288
Aug 8 18:18 lost+found
-rw-r--r--
1 root root 2115772 Aug 8 18:25
vmlinuz
[root@magedu boot]#
boot--制作grub.conf
[root@magedu boot]# pwd
/mnt/boot
[root@magedu boot]# vim /mnt/boot/grub/grub.conf
[root@magedu boot]# cat /mnt/boot/grub/grub.conf
default=0
timeout=5
title Test
Linux(Magedu Team)
root(hd0,0)
kernel /vmlinuz
initrd /initrd.gz
[root@magedu boot]#
/--创建根下目录
[root@magedu sysroot]# pwd
/mnt/sysroot
[root@magedu sysroot]# mkdir proc sys dev
etc/rc.d lib bin sbin boot home var/log usr/{bin,sbin} root tmp
lib64 -pv
/--复制/sbin/init /bin/bash
[root@magedu sysroot]# cp /sbin/init
/mnt/sysroot/sbin/
[root@magedu sysroot]# cp /bin/bash
/mnt/sysroot/bin/
[root@magedu sysroot]#
/--复制/sbin/init /bin/bash
的依赖库
[root@magedu sysroot]# ldd /sbin/init
linux-vdso.so.1 => (0x00007fffbf9fd000)
libsepol.so.1
=> /lib64/libsepol.so.1 (0x0000003051a00000)
libselinux.so.1 => /lib64/libselinux.so.1
(0x0000003051e00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003049c00000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000304a800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003049800000)
[root@magedu sysroot]# cp
/lib64/libsepol.so.1 /mnt/sysroot/lib64/
[root@magedu sysroot]# cp
/lib64/libselinux.so.1 /mnt/sysroot/lib64/
[root@magedu sysroot]# cp
/lib64/libc.so.6 /mnt/sysroot/lib64/
[root@magedu sysroot]# cp
/lib64/libdl.so.2 /mnt/sysroot/lib64/
[root@magedu sysroot]# cp
/lib64/ld-linux-x86-64.so.2 /mnt/sysroot/lib64/
[root@magedu sysroot]#
[root@magedu sysroot]# ldd /bin/bash
linux-vdso.so.1 => (0x00007fff15cf3000)
libtermcap.so.2 =>
/lib64/libtermcap.so.2 (0x000000304ac00000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000304a800000)
libc.so.6 => /lib64/libc.so.6 (0x0000003049c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003049800000)
[root@magedu sysroot]# cp
/lib64/libtermcap.so.2 /mnt/sysroot/lib64/
[root@magedu sysroot]#
/--制作etc/inittab
[root@magedu sysroot]# cat
/mnt/sysroot/etc/inittab
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
[root@magedu sysroot]#
/--制作etc/inittab
[root@magedu sysroot]# cat
/mnt/sysroot/etc/rc.d/rc.sysinit
#!/bin/bash
#
echo -e
"\tWelcome to \033[31mMageEdu Team\033[0m Linux."
/bin/bash
[root@magedu sysroot]#
[root@magedu sysroot]# chmod +x
/mnt/sysroot/etc/rc.d/rc.sysinit
[root@magedu sysroot]# sync
[root@magedu sysroot]# sync
[root@magedu sysroot]# sync
[root@magedu sysroot]#
可以做个测试,把这个硬盘在另外的虚拟机上,看是不是可以启动(本虚拟机要先挂起)