grub命令 u盘安装linux,通过grub-install命令把grub安装到u盘-总结

通过grub-install命令把grub安装到u盘

①准备一个u盘,容量不限,能有1MB都足够了。

②把u盘格式化(我把u盘格式化成FAT、fat32格式了,最后证明也是成功的)。

③开启linux系统,打开命令行终端,进入root模式,然后输入命令行:

mount   /dev/sdb3   /tmp/boot

grub-install --root-directory=/tmp/boot --no-floppy /dev/sdb

注意:上面/dev/sdb是我的u盘,在linux系统里的盘符吧,那个/dev/sdb3为什么是“3”,这个因不同的实际情况而不同吧。

总的来说,/dev/sdb就是我的u盘的名字,/dev/sdb3就是我的u盘的一个分区。

④这个时候,你会发现,你的u盘,已经多了一个boot目录,里面有一些内容,这个时候,boot目录的路径是/dev/sdb3/boot/。

⑤把“/boot/grub/grub.conf”和“/boot/grub/splash.xpm.gz”,复制到“/dev/sdb3/boot/grub/”下面(也就是“u盘/boot/grub/”)。

⑥然后把/dev/sdb3/boot/grub/grub.conf修改成以下内容:

# grub.conf generated by anaconda

#

# Note that you do not have to rerun grub after making changes to this file

# NOTICE:  You do not have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /, eg.

#          root (hd0,0)

#          kernel /boot/vmlinuz-version ro root=/dev/sda1

#          initrd /boot/initrd-version.img

#boot=/dev/sda

default=0

timeout=5

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Red Hat Enterprise Linux Server 1280*1024(3.4.0)

root (hd0,0)

kernel /boot/vmlinuz-3.4.0  root=/dev/sda1 selinux=0 init=/sbin/init vga=795 fb:on

initrd /boot/initrd.img-3.4.0

title Red Hat Enterprise Linux Server 1600*1200(3.4.0)

root (hd0,0)

kernel /boot/vmlinuz-3.4.0  root=/dev/sda1 selinux=0 init=/sbin/init vga=858 fb:on

initrd /boot/initrd.img-3.4.0

⑦重启计算机,在BIOS里,设置为从u盘启动,即可。

说明:grub2.0以后支持的是grub.cfg

set default=0

set timeout=5

set gfxmode=1280x1024

menuentry 'Red Hat Enterprise Linux Server 1280*1024(3.4.0)' {

set gfxpayload=1280x1024x32,1024x768x32,800x600x32,800x600x16,800x600,640x480

linux /boot/vmlinuz-3.4.0 root=/dev/sda1 selinux=0 init=/sbin/init vga=795

initrd /boot/initrd.img-3.4.0

}

制作步骤:

先用cfdisk 在U盘中,创建个两个分区,第二个一会儿作为boot分区。

0:mkfs.ext3 /dev/sdc5

1:mount /dev/sdc5 /tmp/boot

2:grub-install --root-directory=/tmp/boot --no-floppy  /dev/sdc(*注意*)

自己修改一下menu.lst文件吧。这个简单。

主板+USB,均引导内核成功,系统未作复杂裁剪,未作压缩镜像

1.      linux内核编译:

具体步骤:

# tar zxvf linux-2.6.tar.gz -C /usr/src

# cd /usr/src/linux2.6

# make menuconfig

# make

# make modules_install

# cp arch/x86/boot/bzImage /boot/vmlinuz-2.6

# make install

对比/boot/grub/grub.cfg文件的改动

2.      安装启动盘(U盘、硬盘)

# Fdisk /dev/sdb

#mkfs.ext2 /dev/sdb1

# mkdir /tmp/boot ; mount /dev/sdb1/tmp/boot

# grub-install--root-directory=/tmp/boot --no-floppy /dev/sdb

# cp /boot/grub/grub.conf /tmp/boot/boot/grub/

# cp /boot/grub//boot/grub/splash.xpm.gz /tmp/boot/boot/grub/

# cp /boot/vmlinuz-2.6.34/mnt/boot/vmlinuz

# cp /boot/initramfs-2.6.34.img/mnt/boot/initramfs.img

3.  构建系统目录

# mkdir dev proc etc sbin bin lib mntusr

# cp /bin /tmp/boot/

# cp –dpr /dev/{console,fd0.hda,hda8,hda9,hda10,initctl,initrd,kmem,mem,null,ram,ram0,ramdisj,sda,tty1,tty} /tmp/boot/

# cp/etc/{default,ld.so.cache,ld.so.conf,login.defs,fstab,groub,init.d,inittab,issue,modules.conf,mtab,nsswitch.conf,pam.d,profile,rc.d} /tmp/boot/

4.  编辑grub.conf

Default为默认启动项

Grub2 grub.cfg

set default=0

set timeout=5

set gfxmode=1280x1024

menuentry 'Red Hat EnterpriseLinux Server 1280*1024(3.4.0)' {

setgfxpayload=1280x1024x32,1024x768x32,800x600x32,800x600x16,800x600,640x480

linux/boot/vmlinuz-3.4.0  root=/dev/sda1selinux=0 init=/sbin/init vga=795

initrd/boot/initrd.img-3.4.0

}

5. 添加必要的命令

例如:ls

Ldd ls,添加对应的依赖库文件;ldd ls > 1.txt

6. 修改initrd

重新编译内核后,可能加入了自定义的模块,就有可能需要修改init文件,而init文件就在initrd中,这里记录下操作步骤,以防遗忘。

1.  cp  /boot/initrd-3.2.img /tmp/mylinux/initrd-3.2.img.gz

这里之所以进行改名,是因为initrd-3.2.img是经过gzip压缩过的,所以需要对其解压,但是gzip对解压的文件的文件后缀名又有要求,所以就先进行改名。

2.   gunzip  initrd-3.2.9.img.gz

3.   cpio  -id  

经过以上三步,就在当前目录下解压了initrd文件,从而得到了init文件。

根据自己的需求修改init文件后,通过下面命令重新生成initrd文件。

4.   find  .  | cpio  -H  newc  -o  |  gzip  -9  > /boot/initrd-3.2.9.img

find . | cpio -H newc -o | gzip -9>../initrd.img-3.4.0

7. 内核添加fb0

mknod /dev/fb0 c 29 0

Device Drivers --->

Graphics support --->

Support for frame buffer devices--->

318     31b    35a

1024    1280   1600

8. 添加网络驱动

# initrd,img/init

echo "0: linuxrunning on initrd.img"

echo "1: linuxrunning on usb ext2 filesystem"

read -p "select:" data

if [ $data ="0" ]; then

echo "0: linux running oninitrd.img  selected"

uname -r

insmod lib/modules/3.4.0/kernel/drivers/net/mii.ko

insmod lib/modules/3.4.0/kernel/drivers/net/ethernet/realtek/r8169.ko#添加网络

insmod lib//modules/3.4.0/kernel/drivers/usb/storage/usb-storage.ko#添加USB

sleep 1

mkdir usb

mount /dev/sda1usb

ifconfig -a

ifconfig eth0192.168.1.88

sleep 1

sh

else

echo "1: linux running on usb ext2filesystem  selected"

sleep 1

fi

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值