Raspberry Pi Mount Hard Drive/U Disk and Partition Tutorial

1. Hardware preparation

Raspberry Pi, hard disk/U disk, choose mobile hard disk with power supply.
Fdisk is a tool for managing disks under linux, which can add, delete, and convert disks.

2. Start of the tutorial

1. Insert your hard drive/U disk into the Raspberry Pi

2. The second step is to check whether the U disk has been recognized, and where is the recognized U disk

sudo fdisk -l 

Insert picture description here

3. Partition the hard disk

sudo fdisk /dev/sda

Insert picture description here
Command introduction

p查看现有分区

d删除分区

n创建分区

Enter P to view existing partitions

Insert picture description here

Delete the existing disk enter d

Insert picture description here

Divide a new area input n
Insert picture description here

Select whether the new partition is a primary partition or an extended partition, write p for the primary partition and write e for the extended partition
Insert picture description here

Choose the starting position of the partition

The default starting position is 2048MB

Press enter to confirm,

Because we are here only to store files on the Raspberry Pi to make up for the insufficient memory of the Raspberry Pi, only one partition is needed, so the default end position is the end of the disk.
If you want to divide a lot of areas, you can add the size of the partition you want to the end position, and then enter n to divide the second area.
Insert picture description here
Insert picture description here

Then enter p to view our partition
Insert picture description here

You can see that the id of our partition is 83

83 represents the linux partition

Linux partition is not recognized on windows

If your hard drive wants to be used on Raspberry Pi and your win computer, you need to change the partition type

Type t

Enter b

It changed to win95 fat32 type, fat32 can be recognized by windows and linux

Enter w to save and exit

4. Format the hard drive

sudo mkfs.ext4 /dev/sda1

5. Mount the hard disk to the system

Although the system has recognized the disk partition, it has not been added to the system yet, so we have to mount the disk partition to the system

The mounted disk is generally in the /mnt or /media directory

sudo mkdir /mnt/disk

sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/disk

Now the disk has been mounted in the /mnt/disk directory, but the mounting is only temporary, and it will be remounted after restart, so we have to modify /etc/fstab to solve this problem

sudo nano /etc/fstab

Add the following piece of code at the end

/dev/sda1 /mnt/disk auto defaults,noexec,umask=0000 0 0

Ctrl x save and exit
successfully
. Use the following commands to view the mounting situation.

cd  /mnt/disk

ls

Guess you like

Origin blog.csdn.net/qq_41676577/article/details/112856637