美文网首页树莓派树莓派
U盘安装树莓派系统,利用U盘启动Raspberry

U盘安装树莓派系统,利用U盘启动Raspberry

作者: 科技爱好者 | 来源:发表于2017-05-05 17:12 被阅读338次

    本文首发于科技爱好者博客【http://blog.lxx1.com】

    树莓派的系统一般是安装在SD卡上,但是SD卡比较脆弱,如果频繁的读写数据,会导致SD卡损坏。SD卡的读写速度也比U盘慢。如果我们将树莓派系统安装在U盘中,利用更加强壮、速度更快的U盘启动树莓派,则可以解决使用SD卡遇到的问题。

    以下是U盘安装树莓派系统,利用U盘启动Raspberry的教程。

    一、准备条件

    • 树莓派一台
    • SD卡一个,容量不用太大,但必须大于128M.
    • U盘一个,8G以上
    • 树莓派系统镜像

    二、安装系统

    将树莓派系统写入到U盘中,方法和写入SD卡的方法一样,windows下可以使用win32diskimager(镜像写U盘工具)将系统写入。

    格式化SD卡,然后将写好系统的U盘下的内容全部复制到SD卡根目录中。
    修改SD卡根目录下的cmdline.txt文件。因为U盘现在有2个分区,一个是boot(/dev/sda1)分区,另一个才是root(/dev/sda2)分区。 将root=/dev/mmcblk0p2
    修改为root=/dev/sda2。

    然后,将U盘和SD卡同时插到树莓派上,上电就可以将树莓派从U盘启动了。

    启动后可以感受到,树莓派的运行速度快了许多,这是因为我们使用了速度更快的U盘安装系统。

    三、扩展U盘空间

    U盘安装完系统后,发现虽然我的U盘是32G大小的,但是使用df命令可以看到只有4G大小,使用sudo raspi-config扩展,提示不能自动扩展:
    sda2 is not an SD card. Don't know how to expand


    这时需要使用fdisk命令手动扩展空间,信息过程如下。带有注释的行是需要输入的信息。
    pi@raspberrypi:~ $ sudo fdisk /dev/sda  #扩展分区
    
    Welcome to fdisk (util-linux 2.25.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): p #查看现有分区
    Disk /dev/sda: 28.7 GiB, 30752000000 bytes, 60062500 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
    Disklabel type: dos
    Disk identifier: 0x2d52e4bb
    
    Device     Boot  Start      End  Sectors  Size Id Type
    /dev/sda1         8192   137215   129024   63M  c W95 FAT32 (LBA)
    /dev/sda2       137216 60062499 59925284 28.6G 83 Linux
    
    
    Command (m for help): d #删除分区2
    Partition number (1,2, default 2): 2    #选择要删除的分区号
    
    Partition 2 has been deleted.
    
    Command (m for help): n     #新建分区
    Partition type
       p   primary (1 primary, 0 extended, 3 free)
       e   extended (container for logical partitions)
    Select (default p): p   #选择p,即为主分区
    Partition number (2-4, default 2): 2    #选择要新建的分区号
    First sector (2048-60062499, default 2048): 137216  #输入删除分区前/dev/sda2的起始磁盘柱
    Last sector, +sectors or +size{K,M,G,T,P} (137216-60062499, default 60062499): #默认即可
    
    Created a new partition 2 of type 'Linux' and of size 28.6 GiB.
    
    Command (m for help): p #查看修改后的分区
    Disk /dev/sda: 28.7 GiB, 30752000000 bytes, 60062500 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
    Disklabel type: dos
    Disk identifier: 0x2d52e4bb
    
    Device     Boot  Start      End  Sectors  Size Id Type
    /dev/sda1         8192   137215   129024   63M  c W95 FAT32 (LBA)
    /dev/sda2       137216 60062499 59925284 28.6G 83 Linux
    
    
    Command (m for help): wq    #保存退出
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Re-reading the partition table failed.: Device or resource busy
    
    The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
    
    

    然后重启系统sudo reboot。

    重启完成后,使用sudo resize2fs /dev/sda2 命令进行实际的空间拓展,等待命令执行完成,再次重启系统,即完成了U盘空间的拓展。

    原创文章,转载请注明:转载自科技爱好者博客【http://blog.lxx1.com】

    本文地址:U盘安装树莓派系统,利用U盘启动Raspberry

    链接:http://blog.lxx1.com/2574

    如果我的文章对你有帮助,请给我打赏

    相关文章

      网友评论

      本文标题:U盘安装树莓派系统,利用U盘启动Raspberry

      本文链接:https://www.haomeiwen.com/subject/gtzltxtx.html