安装Grub到U盘

来源:互联网 发布:微信数据移动到sd卡 编辑:程序博客网 时间:2024/06/12 19:52

U盘启动器:
目的:安装grub到u盘,用u盘来维护系统
条件:1、电脑设为从USB设备启动。
    2、要有一个Linux系统来安装Grub.
    3、当然这个U盘要为此次行动做出牺牲。(呵呵,赶紧将重要资料转移吧~~)
实施步骤:
1、插入U盘,fdisk查看是否检测到U盘。
      [star@localhost ~]$ sudo fdisk -l

      Disk /dev/sda: 250.1 GB, 250059350016 bytes
      255 heads, 63 sectors/track, 30401 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      Disk identifier: 0xd10cd10c

      DeviceBoot     Start        End     Blocks   Id System
      /dev/sda1                 5540   44500018+  W95  FAT32 (LBA)
      /dev/sda2           5541      30401  199695982+  W95 Ext'd (LBA)
      /dev/sda3          22465      29878   59552955    W95 FAT32 (LBA)
      /dev/sda5           5541      13285   62211681    HPFS/NTFS
      /dev/sda6       13286      22464   73730286   83 Linux
      /dev/sda7          29879      30401    4200966   82 Linux swap / Solaris

      Disk /dev/sdb: 4022 MB, 4022337024 bytes
      255 heads, 63 sectors/track, 489 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      Disk identifier: 0x000f4b77

      DeviceBoot     Start        End     Blocks   Id System
      /dev/sdb1                    490    3928032    W95 FAT32
      Partition 1 has different physical/logical endings:
      phys=(488, 254, 63) logical=(489, 5, 27)

2、先给u盘分区,分区方案自己照自己情况,这里以/dev/sdb1上安装grub为例。
       [star@localhost ~]$ sudo fdisk /dev/sdb

       Command (m for help): d
       Selected partition 1

       Command (m for help): n
    Commandaction
       extended
       primary partition (1-4)
    p
    Partitionnumber (1-4): 1
    Firstcylinder (1-489, default 1):
    Usingdefault value 1
    Lastcylinder, +cylinders or +size{K,M,G} (1-489, default 489):+500M         

    Command (mfor help): n
    Commandaction
       extended
       primary partition (1-4)
    p
    Partitionnumber (1-4): 2
    Firstcylinder (66-489, default 66):
    Usingdefault value 66
    Lastcylinder, +cylinders or +size{K,M,G} (66-489, default 489):
    Usingdefault value 489
    
    Command (mfor help): p
    
    Disk/dev/sdb: 4022 MB, 4022337024 bytes
    255 heads,63 sectors/track, 489 cylinders
    Units =cylinders of 16065 * 512 = 8225280 bytes
    Sector size(logical/physical): 512 bytes / 512 bytes
    Diskidentifier: 0x000f4b77
    
      DeviceBoot     Start        End     Blocks   Id System
   /dev/sdb1                      65     522081   83 Linux
   /dev/sdb2             66        489    3405780   83 Linux
    
    Command (mfor help):a                         (这一步很重要,就是要激活该分区)
    Partitionnumber (1-4): 1
    
    Command (mfor help): w
    Thepartition table has beenaltered!      
    
    Callingioctl() to re-read partition table.
    Syncingdisks.
    
3、格式化,即创建文件系统,我这里以ext3为例:
   [star@localhost ~]$ sudo mkfs -t ext3/dev/sdb1
    mke2fs1.41.10 (10-Feb-2009)
    Filesystemlabel=
    OS type:Linux
    Blocksize=1024 (log=0)
    Fragmentsize=1024 (log=0)
    Stride=0blocks, Stripe width=0 blocks
    130560inodes, 522080 blocks
    26104 blocks(5.00%) reserved for the super user
    First datablock=1
    Maximumfilesystem blocks=67633152
    64 blockgroups
    8192 blocksper group, 8192 fragments per group
    2040 inodesper group
    Superblockbackups stored on blocks:
      8193, 24577, 40961, 57345, 73729, 204801, 221185,401409
    
    Writinginode tables:done                           
    Creatingjournal (8192 blocks): done
    Writingsuperblocks and filesystem accounting information: done
    
    Thisfilesystem will be automatically checked every 24 mounts or
    180 days,whichever comes first.  Use tune2fs -c or -i tooverride.

4、挂载系统:
   [star@localhost ~]$ sudo mkdir /media/test
   [star@localhost ~]$ sudo mount -t ext3 /dev/sdb1/media/test/

5、安装Grub到U盘上:
   [star@localhost ~]$ sudo grub-install--root-directory=/media/test/ /dev/sdb
    Probingdevices to guess BIOS drives. This may take a long time.
    Installationfinished. No error reported.
    This is thecontents of the device map /media/test//boot/grub/device.map.
    Check ifthis is correct or not. If any of the lines is incorrect,
    fix it andre-run the script `grub-install'.
    
   (fd0)   /dev/fd0
   (hd0)   /dev/sda
   (hd1)   /dev/sdb
          
6、复制当前系统的menu.lst到u盘grub下:
   [star@localhost ~]$ sudo cp /boot/grub/menu.lst/media/test/boot/grub/
7、根据实际情况修改menu.lst。
8、安装grub到MBR:
   [star@localhost ~]$ sudo grub

      GNU GRUB  version 0.97  (640Klower / 3072K upper memory)

     [ MinimalBASH-like line editing is supported.  For thefirst word, TAB
      listspossible command completions.  Anywhere else TABlists the possible
      completionsof a device/filename. ]


   grub> find /boot/grub/stage1
    (hd0,5)
    (hd1,0)

   grub> root (hd1,0)
     Filesystemtype 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)"...  19 sectors are embedded.
    succeeded
     Running "install /boot/grub/stage1 (hd1)(hd1)1+19 p (hd1,0)/boot/grub/stage2
      /boot/grub/menu.lst"... succeeded
     Done.

   grub> quit
9、卸载就OK了,即完成了。以后就可以使用这个U盘来引导或修复系统了。

 
阅读(0)|评论(0)
推荐 转载

历史上的今天

最近读者

热度

评论

U盘启动器:
目的:安装grub到u盘,用u盘来维护系统
条件:1、电脑设为从USB设备启动。
    2、要有一个Linux系统来安装Grub.
    3、当然这个U盘要为此次行动做出牺牲。(呵呵,赶紧将重要资料转移吧~~)
实施步骤:
1、插入U盘,fdisk查看是否检测到U盘。
      [star@localhost ~]$ sudo fdisk -l

      Disk /dev/sda: 250.1 GB, 250059350016 bytes

', blogTag:'', blogUrl:'blog/static/18351930820112171500149',isPublished:1, istop:false, type:0, modifyTime:0,publishTime:1300341000149,permalink:'blog/static/18351930820112171500149', commentCount:0,mainCommentCount:0, recommendCount:0, bsrk:-100, publisherId:0,recomBlogHome:false, currentRecomBlog:false, attachmentsFileIds:[],vote:{}, groupInfo:{}, friendstatus:'none',followstatus:'unFollow', pubSucc:'', visitorProvince:'',visitorCity:'', visitorNewUser:false, postAddInfo:{}, mset:'000',mcon:'', srk:-100, remindgoodnightblog:false, isBlackVisitor:false,isShowYodaoAd:false, hostIntro:'', hmcon:'0',selfRecomBlogCount:'0', lofter_single:'' }
{ifx.visitorName==visitor.userName} ${x.visitorNickname|escape} {else}${x.visitorNickname|escape} {/if}
{if x.moveFrom=='wap'}   {elseifx.moveFrom=='iphone'}   {elseifx.moveFrom=='android'}   {elseifx.moveFrom=='mobile'}   {/if}${fn(x.visitorNickname,8)|escape}
{/if} {/list}
${a.selfIntro|escape}{ifgreat260}${suplement}{/if}
 
{/if}
原创粉丝点击