安装Grub到U盘

本文详细介绍如何在U盘上安装Grub启动加载器,包括U盘分区、格式化、安装Grub及配置等步骤,适用于Linux系统维护与启动修复。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装Grub到U盘

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    (如果原来只有一个分区,且这个分区占用了全部u盘空间,那么您必须先将这个分区删除,然后才能重新分区!!)
    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, default489): 
    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 mountsor
    180 days,whichever comes first.  Use tune2fs -c or -i tooverride.
其它格式:
【20101010补充:格式化之前需要卸载该设备,否则会格式化不成功,命令:#umount 设备名】

在linux下面有命令:
mkfs.ext2  设备名
mkfs.ext3  设备名
mkfs.msdos  设备名
mkfs.vfat  设备名    
等命令,可以将磁盘格式化为不同的文件系统格式。 这里的设备名要是分区名 ,而不是硬盘设备名 (切记先记好分区名 ,别输入错 ,不然格式化错了就麻烦了)

等待之后分区就格式化好了 , 记得复制文件之前要修复一下
再次提示下修复命令 fsck.ext3 设备名

do mkfs.vfat -F 32 -n disk /dev/sdb1           /*格式化*/

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下:
6、复制当前系统的grub.cfg(因为11.04已经是grub2了,用的grub.cfg)t到u盘grub下:
   [star@localhost ~]$ sudo cp /boot/grub/grub.cfg   /media/test/boot/grub/
7、根据实际情况修改grub.cfg。
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盘来引导或修复系统了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值