有点厌倦了yum软件安装的繁琐,想安装Debian,新鲜一下。
没有光盘,只能用U盘做系统盘,不满于总是按照别人的步骤安装,稍微有些问题就解决不了,决定稍微学习一下grub的使用。
废话少说,上步骤:
1、在U盘安装grub2
条件:
电脑设为从USB设备启动。
要有一个Linux系统来安装Grub.
实施步骤:
将U盘分为2个区,第一个区为vfat格式,第二个区为ext2格式,grub安装到第二个区,将第二个区作为可引导区
1、分区
[[email protected] ~]# fdisk /dev/sdb
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-487, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-487, default 487): +3072M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (375-487, default 375):
Using default value 375
Last cylinder or +size or +sizeM or +sizeK (375-487, default 487):
Using default value 487
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
2、格式化分区
卸载U盘:在桌面右键点击“删除文件卷”
插上U盘
[[email protected] ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sda6 /dev/sda7 /dev/sda8 /dev/sdb /dev/sdb1 /dev/sdb2
[[email protected] ~]# umount /dev/sdb1
[[email protected] ~]# umount /dev/sdb2
[[email protected] ~]# mkfs.vfat /dev/sdb1
mkfs.vfat 2.11 (12 Mar 2005)
[[email protected] ~]# mkfs.ext2 /dev/sdb2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
113568 inodes, 226918 blocks
11345 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=234881024
7 block groups
32768 blocks per group, 32768 fragments per group
16224 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3、激活/dev/sdb2
[[email protected] ~]# fdisk /dev/sdb
Command (m for help): a
Partition number (1-4): 2
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# fdisk -l
...
Disk /dev/sdb: 4008 MB, 4008706048 bytes
255 heads, 63 sectors/track, 487 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 374 3004123+ 83 Linux
/dev/sdb2 * 375 487 907672+ 83 Linux # 可引导分区
4、安装grub到U盘
查看U盘各分区的挂载情况
[[email protected] ~]# df
...
/dev/sdb2 893388 904 847104 1% /media/disk
/dev/sdb1 2998248 4 2998244 1% /media/disk-1
[[email protected] ~]# grub-install --root-directory=/media/disk --no-floppy /dev/sdb2
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 /media/disk/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'.
(hd0) /dev/sda
(hd1) /dev/sdb
5、安装到U盘的MBR
[[email protected] ~]# grub
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd1,
Possible partitions are:
Partition num: 0, Filesystem type unknown, partition type 0x83
Partition num: 1, Filesystem type is ext2fs, partition type 0x83
grub> root (hd1,1)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd1)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,1)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.
grub> quit