系统环境:Ubuntu 64位
设备:Kingston(8G 实际容量7.5G)
1 插上u盘,查看是否被系统识别
root@ubuntu:~# fdisk -l Disk /dev/sda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00051606 Device Boot Start End Blocks Id System /dev/sda1 * 2048 9437183 4717568 83 Linux /dev/sda2 9439230 10483711 522241 5 Extended /dev/sda5 9439232 10483711 522240 82 Linux swap / Solaris #/dev/sdb就是我的u盘了 Disk /dev/sdb: 8011 MB, 8011120640 bytes 246 heads, 40 sectors/track, 1590 cylinders, total 15646720 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000cb8e4 Device Boot Start End Blocks Id System /dev/sdb1 40 12595199 6297580 83 Linux /dev/sdb2 * 12595200 15645599 1525200 83 Linux
如果未能识别u盘,看内核是否加载相应模块,具体查阅http://minilinux.blog.51cto.com/4499123/1247733(CentOS加载U盘)
2 u盘分区
分区情况如下:
分区类型 文件系统类型 容量(根据需要调整)
/dev/sdb1 主分区 ext4 1G
/dev/sdb2 主分区 fat32 6.5G
先删除原有分区
root@ubuntu:~# fdisk /dev/sdb Command (m for help): p Disk /dev/sdb: 8011 MB, 8011120640 bytes 246 heads, 40 sectors/track, 1590 cylinders, total 15646720 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000cb8e4 Device Boot Start End Blocks Id System /dev/sdb1 40 12595199 6297580 83 Linux /dev/sdb2 * 12595200 15645599 1525200 83 Linux Command (m for help): d Partition number (1-4): 1 Command (m for help): d Selected partition 2 Command (m for help): p Disk /dev/sdb: 8011 MB, 8011120640 bytes 246 heads, 40 sectors/track, 1590 cylinders, total 15646720 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000cb8e4 Device Boot Start End Blocks Id System Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. root@ubuntu:~# partprobe
然后重新分区
root@ubuntu:~# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 8011 MB, 8011120640 bytes
246 heads, 40 sectors/track, 1590 cylinders, total 15646720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb8e4
Device Boot Start End Blocks Id System
/dev/sdb1 40 12595199 6297580 83 Linux
/dev/sdb2 * 12595200 15645599 1525200 83 Linux
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
Command (m for help): p
Disk /dev/sdb: 8011 MB, 8011120640 bytes
246 heads, 40 sectors/track, 1590 cylinders, total 15646720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb8e4
Device Boot Start End Blocks Id System
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu:~# partprobe
root@ubuntu:~# fdisk /dev/sdb
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-15646719, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15646719, default 15646719): +1G
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (2099200-15646719, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-15646719, default 15646719):
Using default value 15646719
Command (m for help): p
Disk /dev/sdb: 8011 MB, 8011120640 bytes
247 heads, 62 sectors/track, 1021 cylinders, total 15646720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb8e4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 15646719 6773760 83 Linux
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)
#设置/dev/sda1为引导分区
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb: 8011 MB, 8011120640 bytes
247 heads, 62 sectors/track, 1021 cylinders, total 15646720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb8e4
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 15646719 6773760 b W95 FAT32
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
3 格式化分区
命名第一个分区卷名为boot,ext4格式;第二个卷名为data,vfat格式
root@ubuntu:~# mkfs.ext4 -L boot /dev/sdb sdb sdb1 sdb2 root@ubuntu:~# mkfs.ext4 -L boot /dev/sdb1 mke2fs 1.42.5 (29-Jul-2012) Filesystem label=boot OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done root@ubuntu:~# mkfs.vfat -n data /dev/sdb2 mkfs.vfat 3.0.13 (30 Jun 2012)
4 安装grub相关的文件到/dev/sdb1
root@ubuntu:~# mkdir /mnt/boot -p #/dev/sdb1挂载到/mnt/boot目录下 root@ubuntu:~# mount /dev/sdb1 /mnt/boot/ root@ubuntu:~# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 4.5G 1.8G 2.5G 41% / udev devtmpfs 241M 4.0K 241M 1% /dev tmpfs tmpfs 100M 332K 99M 1% /run none tmpfs 5.0M 0 5.0M 0% /run/lock none tmpfs 248M 0 248M 0% /run/shm none tmpfs 100M 0 100M 0% /run/user /dev/sdb1 ext4 1008M 34M 924M 4% /mnt/boot --》在这里
root@ubuntu:~# grub-install --root-directory=/mnt/ /dev/sdb1 Probing devices to guess BIOS drives. This may take a long time. Installing GRUB to /dev/sdb1 as (hd1,0)... 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
grub-install是安装grub相关的文件到/dev/sdb1
查看grub文件是否存在
root@ubuntu:~# ll /mnt/boot/grub/ total 248 drwxr-xr-x 2 root root 4096 Jul 23 09:33 ./ drwxr-xr-x 4 root root 4096 Jul 23 09:33 ../ -rw-r--r-- 1 root root 197 Jul 23 09:33 default -rw-r--r-- 1 root root 45 Jul 23 09:33 device.map -rw-r--r-- 1 root root 10552 Jul 23 09:33 e2fs_stage1_5 -rw-r--r-- 1 root root 10188 Jul 23 09:33 fat_stage1_5 -rw-r--r-- 1 root root 16 Jul 23 09:33 installed-version -rw-r--r-- 1 root root 11056 Jul 23 09:33 jfs_stage1_5 -rw-r--r-- 1 root root 9608 Jul 23 09:33 minix_stage1_5 -rw-r--r-- 1 root root 12392 Jul 23 09:33 reiserfs_stage1_5 -rw-r--r-- 1 root root 512 Jul 23 09:33 stage1 -rw-r--r-- 1 root root 148864 Jul 23 09:33 stage2 -rw-r--r-- 1 root root 11836 Jul 23 09:33 xfs_stage1_5
发现grub文件安装成功了!
5 安装grub主程序到MBR
root@ubuntu:~# grub Probing devices to guess BIOS drives. This may take a long time. [ 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 Error 1: Filename must be either an absolute pathname or blocklist grub> root (hd1,0) grub> set Possible commands are: setkey setup grub> setup (hd1) Checking if "/boot/grub/stage1" exists... no Checking if "/grub/stage1" exists... yes Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes Running "embed /grub/e2fs_stage1_5 (hd1)"... 21 sectors are embedded. succeeded Running "install /grub/stage1 (hd1) (hd1)1+21 p (hd1,0)/grub/stage2 /grub/menu.lst"... succeeded Done. grub> quit
从网易镜像源http://mirrors.163.com/下载CentOS-6.4-x86_64-minimal.iso
下载完毕后,使用Ultraiso打开CentOS-6.4-x86_64-minimal.iso
打开isolinux文件夹
提取initrd.img和vmlinuz文件出来
复制这两个文件到/mnt/boot/下
root@ubuntu:/mnt/boot# ll total 35712 drwxr-xr-x 4 root root 4096 Jul 23 10:21 ./ drwxr-xr-x 4 root root 4096 Jul 23 08:37 ../ drwxr-xr-x 2 root root 4096 Jul 23 09:33 grub/ -rw-r--r-- 1 root root 32491856 Jul 23 10:21 initrd.img drwx------ 2 root root 16384 Jul 23 08:33 lost+found/ -rw-r--r-- 1 root root 4043888 Jul 23 10:21 vmlinuz
umount /dev/sdb1
拨出u盘,插到windows系统下
发现识别不出fat32的文件系统
没办法,决定给u盘重新分区:(如果可以识别出来就不用再分区了,直接进入下个步骤)
分区如下
文件系统类型 分区类型 容量大小
/dev/sdb1 fat32 主分区 7G
/dev/sdb2 ext4 主分区 512M (引导分区)
重复上述步骤,完成后,再次在windows系统下插上u盘
看到data盘符了吗? 终于搞定了!
打开Ultraiso--》文件--》打开CentOS-6.4-x86_64-minimal.iso(前面下载好的镜像)
提取image文件夹出来
把image文件夹和CentOS-6.4-x86_64-minimal.iso都放到这里面
接下来就是测试的时候了(在vmware虚拟机下测试)
关于在虚拟机下如何用u启安装盘安装系统,请查阅http://minilinux.blog.51cto.com/4499123/1248137(使用U启安装Vmware虚拟机系统)
新建虚拟机CentOS-64-bit
一切都设置好后,打开电源
发现直接就是grub shell界面,原来grub菜单还没做
在grub shell下也可以手动引导
grub> root (hd0,1)<Tab补全>
grub> kernel /vmlinuz
grub> initrd /initrd.img
grub> boot
可以通过Tab键提示
回车,进入如下界面
选择系统安装语言,这里选择中文
选择键盘类型
因为镜像放在u盘里,所以这里选择Hard drive
选择image文件目录所在位置,放在/dev/sdb1
选择下一步
点击下一步
选择全新安装,点击下一步
设置主机名
点击下一步
设置密码(至少8位)
选择创建自定义布局
点击下一步
点击下一步
不管这个,选是。
选择将修改写入磁盘
点击更换设备
将第一BIOS驱动器更改为硬盘,如下设置 点击确定
点击下一步
这样就成功了!
最后记得在虚拟机设置中移除掉硬盘2,否则开机的时候会报错。
最后发现U盘安装盘的grub菜单还没弄,制作u盘grub菜单将在《CentOS 6.4 U盘启动安装盘(grub方式) 下》呈上。
有什么写得不到位的地方,还请大家指出!