树莓派4B CentOS7 + SSD 启动

总体思路:TF卡 + USB3.0 U盘 + SSD(STAT3/M2,最好M2,或者能自供电的,供电不足影响性能)【TF卡提供Bootloader,SSD提供swap和/
 

树莓派SSD安装CentOS 7 x64

  • 需要一个8G+的U盘,一个8G+的TF卡和一个SSD

  • TF卡提供boot分区,SSD提供swap分区和/分区

将raspios刷入TF卡

[root@rpi ~]# cp /etc/apt/sources.list /etc/apt/sources.list.bak    
[root@rpi ~]# cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
​
[root@rpi ~]# nano /etc/apt/sources.list
deb http://mirror.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
deb-src http://mirror.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
​
[root@rpi ~]# nano /etc/apt/sources.list.d/raspi.list
deb http://mirror.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
  • 更新系统

[root@rpi ~]# apt-get update
​
[root@rpi ~]# apt-get full-upgrade
  • 查看bootlaoder的版本

[root@rpi ~]# vcgencmd bootloader_version
  • 插入准备好的U盘,使用树莓派提供的SD卡复制工具将TF卡复制到U盘

  • 关机后移除TF卡,然后接入U盘,在启动树莓派

把CentOS 7刷入TF卡和SSD

在raspios中修改TF卡中的CentOS

  • 将TF卡接入树莓派载板的接口,TF卡会自动挂载到/media目录下

  • 修改TF卡中CentOS的磁盘ID

[root@rpi ~]# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.23.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/mmcblk0: 15.9 GB, 15931539456 bytes, 31116288 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 label type: dos
Disk identifier: 0x000d9655
​
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        8192      593919      292864    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          593920     1593343      499712   82  Linux swap / Solaris
/dev/mmcblk0p3         1593344    31116254    14761455+  83  Linux
​
Command (m for help): x
​
Expert command (m for help): i
New disk identifier (current 0x000d9655): 0x000d9876      
Disk identifier: 0x000d9876
​
Expert command (m for help): r
​
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: 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)
Syncing disks.
​
[root@rpi ~]# partprobe
  • 验证磁盘ID已经修改

[root@rpi ~]# fdisk -l /dev/mmcblk0
​
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes, 31116288 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 label type: dos
Disk identifier: 0x000d9876
​
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        8192      593919      292864    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          593920     1593343      499712   82  Linux swap / Solaris
/dev/mmcblk0p3         1593344    31116254    14761455+  83  Linux
  • 修改/分区的UUID

[root@rpi etc]# blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="D0C4-6DF8" TYPE="vfat" 
/dev/mmcblk0p2: LABEL="_swap" UUID="99e4e43b-f510-4005-9564-580b94d47747" TYPE="swap" 
/dev/mmcblk0p3: LABEL="_/" UUID="eaa5283c-9502-4ff5-9814-30624efbb7c1" TYPE="ext4" 
/dev/mmcblk0: PTTYPE="dos" 
​
[root@rpi ~]# tune2fs -U random /dev/mmcblk0p3
tune2fs 1.42.9 (28-Dec-2013)
​
[root@rpi ~]# blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="D0C4-6DF8" TYPE="vfat" 
/dev/mmcblk0p2: LABEL="_swap" UUID="99e4e43b-f510-4005-9564-580b94d47747" TYPE="swap" 
/dev/mmcblk0p3: LABEL="_/" UUID="48275800-face-4943-bacb-c5a261a4dad2" TYPE="ext4" 
/dev/mmcblk0: PTTYPE="dos" 
​
执行tune2fs命令后,可以看到/分区的UUID已经发生改变,接下来需要将新的/分区的UUID保存到CentOS的/etc/fstab中
​
[root@rpi ~]# vim /media/pi/_/etc/fstab
UUID=48275800-face-4943-bacb-c5a261a4dad2  / ext4    defaults,noatime 0 0
UUID=D0C4-6DF8  /boot vfat    defaults,noatime 0 0
UUID=99e4e43b-f510-4005-9564-580b94d47747  swap swap    defaults,noatime 0 0
  • 删除CentOS的swap分区

[root@rpi ~]# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.23.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/mmcblk0: 15.9 GB, 15931539456 bytes, 31116288 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 label type: dos
Disk identifier: 0x000d9876
​
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        8192      593919      292864    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          593920     1593343      499712   82  Linux swap / Solaris
/dev/mmcblk0p3         1593344    31116254    14761455+  83  Linux
​
Command (m for help): d
Partition number (1-3, default 3): 2
Partition 2 is deleted
​
Command (m for help): p
​
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes, 31116288 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 label type: dos
Disk identifier: 0x000d9655
​
        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        8192      593919      292864    c  W95 FAT32 (LBA)
/dev/mmcblk0p3         1593344    31116254    14761455+  83  Linux
​
Command (m for help): w
The partition table has been altered!
​
Command (m for help): q
​
删除swap分区后,需要把/etc/fstab中的自动挂载项也去掉
​
[root@rpi ~]# vim /media/pi/_/etc/fstab
UUID=48275800-face-4943-bacb-c5a261a4dad2  / ext4    defaults,noatime 0 0
UUID=D0C4-6DF8  /boot vfat    defaults,noatime 0 0
  • 修改CentOS中的/boot/cmdline.txt,指定root(即/分区)所在的分区

由于SSD(SATA)通过USB接口接入,所以SSD会被识别为/dev/sda,而CentOS系统包好三个分区,即:
/boot、swap和/,所以root=/dev/sda3
​
[root@rpi etc]# cp /media/pi/boot/cmdline.txt /media/pi/boot/cmdline.txt.bak
[root@rpi etc]# vim /media/pi/boot/cmdline.txt
console=ttyAMA0,115200 console=tty1 root=/dev/sda3 rootfstype=ext4 elevator=deadline rootwait
  • 关闭树莓派,移除U盘

USB2.0 + SSD 启动CentOS

  • TF卡接入树莓派载板自带的接口

  • SSD接入树莓派载板的USB2.0接口

  • 接通电源,正常进入CentOS 7,默认账号:root,密码:centos

  • 查看boot分区是否为TF卡提供,swap分区和/分区是否为SSD提供

[root@rpi ~]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0  14.9G  0 disk 
├─mmcblk0p3 179:3    0  14.1G  0 part 
└─mmcblk0p1 179:1    0   286M  0 part /boot
sda           8:0    0 238.5G  0 disk 
├─sda2        8:2    0   488M  0 part [SWAP]
├─sda3        8:3    0 237.7G  0 part /
└─sda1        8:1    0   286M  0 part 
  • 再次校验/分区所在的磁盘分区

[root@rpi ~]# findmnt -n -o SOURCE /
/dev/sda3

USB3.0 + SSD 启动CentOS

  • 将SSD从USB2.0中移除,接入USB3.0接口,启动树莓派

  • 启动如果卡住了,则可能是UAS造成的,需要在/boot/cmdline.txt中配置quirks,配置格式:storage.quirks=idVendor1:idProduct1:u[,idVendor2:idProduct2:u,idVendor3:idProduct3:u]

  • 把SSD接回USB2.0接口,启动树莓派

  • 使用lsusb获取SSD的idVendor和idProduct(需安装usbutils: yum install -y usbutils)

[root@rpi ~]# lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
​
在上面的信息中,找到
Bus 001 Device 003: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
其中,152d:0578就是idVendor和idProduct
  • 在cmdline.txt中指定SSD的idVendor和idProduct

[root@rpi ~]# vim /boot/cmdline.txt
usb-storage.quirks=152d:0578:u console=ttyAMA0,115200 console=tty1 root=/dev/sda3 rootfstype=ext4 elevator=deadline rootwait
​
只需要把“usb-storage.quirks=152d:0578:u”添加到行首即可
  • 关闭树莓派,将SSD接入USB3.0接口,重新启动树莓派即可

测试SSD的读写速度

  • 使用dd命令测试SSD的读写速度

[root@rpi ~]# time dd if=/dev/zero of=data bs=8k count=50000 oflag=direct
50000+0 records in
50000+0 records out
409600000 bytes (410 MB) copied, 4.70217 s, 87.2 MB/s
​
real    0m4.702s
user    0m0.023s
sys     0m1.779s
​
​
[root@rpi ~]# dd if=data of=/dev/null bs=8k count=50000
50000+0 records in
50000+0 records out
409600000 bytes (410 MB) copied, 1.83391 s, 223 MB/s
​
[root@rpi ~]# rm -rf data

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值