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

技术杂谈78

制作步骤:

先用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文件吧。这个简单。


以上所有推翻重写。

须要懂得理论上的知识,才干做出正确的结果。


首先理解引导中U盘引导部分的过程。
1:当BISO通电引导到磁盘时。会检查MBR区域(MBR:446+DPT:64+ENDFLAG:2=512)
MBR里面必须存在引导程序,一般会是我们熟悉grub,dos,95dos引导等。否则无法引导。
这里做个简要说明:寻常我们将系统安装硬盘上,通常安装都是安装windows,再安装linux,而通常当安装linux时。会提示你是否安装到MBR里面,或者安装到你的某个磁盘分区里面,一般是你的/boot的所在分区。

2:grub的制作
笔者发现win仅仅能自己主动识别出U盘的第一个分区,而对于第二个分区无动于衷。

所以做了这种分区方案。

第一个分区用来存储数据。第二个分区用来放置引导信息,这样不至于在使用过程中。自己创建的grub的boot分区,被别人勿删除,或者格式化。

我的1G U盘分区例如以下:

运行命令
mount /dev/sdc5 /tmp/boot
grub-install --root-directory=/tmp/boot --no-floppy /dev/sdc
此处脚下留神。必须讲grub安装到/dev/sdc,否则眼下对于U盘的MBR来讲。没有能够用的引导程序。
此命令运行后,会在/tmp/boot/文件夹。也就是/dev/sdc5,以下产生文件夹/boot/grub.里面有stage等文件。

最后在/boot/grub 文件夹中建立menu.lst文件。

文件内容例如以下:

timeout 20
default 0

title windows xp
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,0)
makeactive
chainloader +1

讲一下。假设你用U盘引导后,他会把自己标记为hd0。

而已经安装在硬盘上的win操作系统觉得自己的宿主硬盘是hd0。此时引导win操作系统时就会造成盘符错位。

因此我们须要用map进行一下映射转换。

map 的解释及使用例如以下:
map TO_DRIVE FROM_DRIVE

映射 驱动器FROM_DRIVE 到TO_DRIVE.

当你链式引导向dos一样的操作系统。而且该系统没有在第一个驱动器上时,必须进行该映射。

that's Ok!


随着我的使用的愈加频繁。menu.lst上面的内容多了起来。


以下分享一下。里面的内容。首先是文件夹结构。

root@kook:~# fdisk -l /dev/sdb

Disk /dev/sdb: 1010 MB, 1010826752 bytes
32 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 1952 * 512 = 999424 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 951 928145+ 6 FAT16
/dev/sdb2 * 952 1011 58560 83 Linux
root@kook:~# mount /dev/sdb2 /tmp/boot/
root@kook:~# tree -d /tmp/boot
/tmp/boot
|-- boot
| -- grub
|-- centos4.4
|-- centos4.4-64
|-- lost+found
-- ubuntu704

6 directories

以下是menu.lst的内容。

root@kook:~# cat /tmp/boot/boot/grub/menu.lst
color light-gray/blue
timeout 20
default 0

title Windows 95/98/NT/2000
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,0)
makeactive
chainloader +1

title CentOS 4.4 x86_64 Net Install
root (hd0,1)
kernel /centos4.4-64/vmlinuz root=/dev/hda2 ro single
initrd /centos4.4-64/initrd.img
boot

title CentOS 4.4 i386 Net Install
root (hd0,1)
kernel /centos4.4/vmlinuz root=/dev/hda2 ro single
initrd /centos4.4/initrd.img
boot

title Ubuntu 7.04 AMD 64 Net Install
root (hd0,1)
kernel /ubuntu704/linux root=/dev/hda2 ro single
initrd /ubuntu704/initrd.gz
boot

注意:
1:成功的关键是MBR的内容。能够用dd if=/dev/sdc of=/tmp/mbr.bin bs=446 count=1 提取 出。

hexdump -C /tmp/mbr.bin 查看
2:有时候MBR会有问题。

用这个命令清零吧。

dd if=/dev/zero of=/dev/sdc bs=446 count=1

root (hd0,0)
kernel /boot/vmlinuz-3.10xxx
initrd /boot/initrd-3.10xxx
boot
这个格式是grub格式。或者grub一代

root (hd0,msdos0)
linux /boot/vmlinuz-3.10xxx
initrd /boot/initrd-3.10xxx
boot
这是grub2的写法

rhel6曾经都採用grub一代,到rhel7则採用grub2模块化引导管理器

grub和grub2的异同还请參考官方文档或自行百度!

我的笔记:

系 统:虚拟机RHEL6.4(2.6.32)

裁剪内核:linux-2.6.34

在虚拟机+虚拟硬盘、945 主板+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-3.2.9.img

经过以上三步,就在当前文件夹下解压了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 --->

318 31b 35a

1024 1280 1600

  1. 加入网络驱动

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

Original: https://www.cnblogs.com/yfceshi/p/7400236.html
Author: yfceshi
Title: 通过grub-install命令把grub安装到u盘-总结



相关阅读

Title: 宏平均和微平均

谈谈评价指标中的宏平均和微平均

今天在阅读周志华老师的《机器学习》一书时,看到性能度量这一小节,里面讲到了宏平均和微平均的计算方法,这也是我一直没有很清晰的一个概念,于是在看了之后又查阅了一些资料,但是还是存在一些问题,想和大家分享一下。

(1)召回率、准确率、F值

对于二分类问题,可将样例根据其真实类别和分类器预测类别划分为:

  • 真正例(True Positive,TP):真实类别为正例,预测类别为正例。
  • 假正例(False Positive,FP):真实类别为负例,预测类别为正例。
  • 假负例(False Negative,FN):真实类别为正例,预测类别为负例。
  • 真负例(True Negative,TN):真实类别为负例,预测类别为负例。

然后可以构建混淆矩阵(Confusion Matrix)如下表所示。

真实类别

预测类别

正例

负例

正例

TP

FN

负例

FP

TN

准确率,又称查准率(Precision,P):

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

召回率,又称查全率(Recall,R):

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

F1值:

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

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

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

如果只有一个二分类混淆矩阵,那么用以上的指标就可以进行评价,没有什么争议,但是当我们在n个二分类混淆矩阵上要综合考察评价指标的时候就会用到宏平均和微平均。

(2)宏平均(Macro-averaging)和微平均(Micro-averaging)

宏平均(Macro-averaging ),是先对每一个类统计指标值,然后在对所有类求算术平均值。

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

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

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

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

微平均(Micro-averaging ),是对数据集中的每一个实例不分类别进行统计建立全局混淆矩阵,然后计算相应指标。

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

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

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

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

从上面的公式我们可以看到微平均并没有什么疑问,但是在 计算宏平均 F值时我给出了两个公式分别为公式(7)和(8 )。这两个公式就是我疑惑的地方,因为我在不同的论文中看到了不同的宏平均F值的计算方法,例如在参考资料的[3][4]。于是我试图查阅宏平均和微平均提出的初始论文。但是可能由于时间比较久远还是某些原因,我并没有找到最早提出的论文,而大多数论文使用它们的时候引用比较多的是 Yang 1999 的这篇论文,论文中也未明确给出宏平均F值的计算公式,但是根据其描述:

"For evaluating performance average across categories, there are two conventional methods, namely macro-averaging_and _micro-averaging. Macro-averaged performance scores are computed by first computing the scores for the per-category contingency tables and then averaging these per-category scores to compute the global means. Micro-averaged performance scores are computed by first creating a global contingency table whose cell values are the sums of the corresponding cells in the per-category contingency tables, and then use this global contingency table to compute the micro-averaged performance scores"

可以看到论文里的宏平均F值应该按照公式(7)计算。但是在不少论文中我也看到了公式(8)的计算方法, 所以在这可能并没有一个定论,我也比较困惑

在参加评测中,评价指标计算都是由主办方制定并进行计算,一般会有明确的计算公式,我在这里想说的是在不少论文中使用宏平均F值时并未给出明确的计算公式,可能会存在两种不同的算法,在论文进行结果比较时,可能会有所差异。

参考资料:

  1. 周志华. 机器学习.清华大学出版社

  2. Yang Y. An evaluation of statistical approaches to text categorization[J]. Information retrieval, 1999, 1(1-2): 69-90.

  3. 杨杰明. 文本分类中文本表示模型和特征选择算法研究. 吉林大学博士论文.

  4. 廖一星. 文本分类及其特征降维研究. 浙江大学博士论文.

Original: https://www.cnblogs.com/sddai/p/15174560.html
Author: stardsd
Title: 宏平均和微平均