Plug in the USB flash drive and unleash your data wizards! How to cleverly mount the U disk in the Armbian system?

1. Basic knowledge [can be omitted]

1.1 sudo permissions

  • sudoPermissions refer to the permissions that allow ordinary users to execute specific commands or operations with superuser (root) permissions in the systemLinux . In most Linux distributions, sudois a tool used to authorize users to execute privileged commands.
  • By granting user sudoprivileges, system administrators can allow ordinary users to perform tasks that require privileged access, such as system administration, installing software, or modifying system configuration files. This approach can improve the security of the system, because ordinary users can only obtain privileges when needed. Ordinary users cannot perform privileged operations without sudopermission and require root账户或者roota password to perform these operations.
  • sudoPermissions can be assigned by adding users to sudoersthe file. The sudoers file specifies which users can use the sudo command and which commands and parameters can be run. Only system administrators can edit the sudoers file or assign permissions through other authorization methods sudo.
  • Through sudocommands, ordinary users can run commands with root privileges or the privileges of other authorized users, as long as they have the corresponding sudoprivileges. When executing commands, users may be asked to enter their own password to authenticate.

1.2 Detect the available status of the USB interface

  1. Open a terminal: Connect to the Armbian device and open a terminal window.

  1. Run the lsusb command: Enter the following command in Terminal to list connected USB devices:
    • The output will show a list of USB devices connected to the Armbian device, including the device's vendor ID and product ID.
    • If the USB device is displayed in the list, it means that the USB interface is available normally.
lsusb
  • Demo:
    root@armbian:~# lsusb
    Bus 001 Device 002: ID ffff:5678 USB Disk 2.0
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    
  • Interpretation of results:
  1. Bus 001: This indicates the bus number to which the USB device is connected, usually there are multiple buses, here is bus 1.
  2. Device 002: This indicates the device number of the USB device on the bus, here is device 2.
  3. ID ffff:5678: This is the vendor ID and product ID of the USB device. In your case the Vendor ID is ffff and the Product ID is 5678. Based on the ID provided, I can't determine the exact make or model of this device, as the ID "ffff" is usually a default, probably because the correct vendor ID wasn't available.
  4. USB Disk 2.0: This is the descriptive information about the connected USB device, it indicates that this device is a USB Disk 2.0.
  5. Bus 001 Device 001: This is the root hub of the USB bus, which is the parent node of the USB devices connected to the bus.
  6. ID 1d6b:0002: This is the Vendor ID and Product ID of the root hub of the USB bus. The vendor ID is 1d6b and the product ID is 0002. The Linux Foundation is an open source software organization that maintains the Linux kernel, so what is shown here is the Linux Foundation root hub.
  • The Armbian device has a USB Disk 2.0 device connected with vendor ID ffff and product ID 5678.

  • Supplement:
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubIt is the root hub of a USB bus. The root hub is the starting point for USB device connections, providing a physical interface and power to enable other USB devices to communicate with the computer.

  • This particular root hub was developed by the Linux Foundation to support the USB 2.0 specification. It plays the role of expanding and managing USB devices on the USB bus.
    Specific functions include:

    1. Provides connection points for USB devices: The root hub provides multiple USB ports that allow you to plug other USB devices into the computer system.
    2. Power Management: The root hub provides power to USB devices connected to its connectors.
    3. Data transfer: The root hub transfers data over the USB bus, enabling data exchange between connected USB devices and computers.
    4. Device Management: Through the root hub, the operating system can identify and manage connected USB devices, enabling the appropriate drivers and features on the computer.
  • In general, the Linux Foundation 2.0 root hub is the basis of USB device connection, responsible for providing power and data transmission functions, so that other USB devices can be connected to the computer system, and support the management and control of these devices by the operating system.


Two armbian mount U disk

2.1 Requirements

  • Requirement: On the armbian system with low power consumption of the arm architecture, how to mount and use the U disk normally (the file system is FAT32) to ensure that the Chinese content is displayed normally without garbled characters?

2.2 Solutions

2.2.1 Manual mount

  • Note: It is recommended to use root user privileges to operate, and the following steps need to be performed manually after each startup.

  1. Insert the USB key: First, insert the USB key into your system.

  1. Display the U disk: open the terminal, and use lsblkthe or fdisk -lcommand to view all block devices and their partitions
    lsblk # 或者 fdisk -l
    
  • demo
    root@armbian:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 1 29.3G 0 disk
    └─sda1 8:1 1 29.3G 0 part
    mmcblk1 179:0 0 29.1G 0 disk
    ├─mmcblk1p1 179:1 0 255M 0 part /boot
    └─mmcblk1p2 179:2 0 28.9G 0 part /
    mmcblk1boot0 179:32 0 4M 1 disk
    mmcblk1boot1 179:64 0 4M 1 disk
    zram0 254:0 0 1.9G 0 disk [SWAP]
    zram1 254:1 0 50M 0 disk /var/log
    
  • specific explanation
    • This command displays all block devices and their partition information in the system. Block devices usually include storage devices such as hard drives, SSDs, and USB drives.
result illustrate
sda 8:0 1 29.3G 0 disk This is a 30GB USB HDD ( sda)
1indicates that the device supports delete flags, 0indicating that the device has no read-only flags
8:0are the major and minor numbers of the device.
└─sda1 8:1 1 29.3G 0 part This is a partition (sda1) of the USB hard drive . It takes up 30GB of the entire USB drive.
Similarly, 1it indicates that the delete mark is supported, 0that there is no read-only mark, and that the device number is 8:1.
mmcblk1 179:0 0 29.1G 0 disk This is a 29.1GB Flash memory (mmcblk1) , which is generally used for storage in embedded systems . This device has two partitions.
├─mmcblk1p1 179:1 0 255M 0 part /boot The first partition is the boot partition , /bootwhich stores the kernel and boot configuration files required for booting , with a size of 255MB.
└─mmcblk1p2 179:2 0 28.9G 0 part / The second partition is root , which is the root partition of the system and stores system and user files , with a size of 28.9GB.
mmcblk1boot0 179:32 0 4M 1 diskandmmcblk1boot1 179:64 0 4M 1 disk These two devices are two special boot partitions of the Embedded Multimedia Card (EMMC), which are always read-only and can be used as boot loaders.
zram0 254:0 0 1.9G 0 disk [SWAP] This is a virtual RAM disk (zram0) with a size of 1.9GB, which is used as a swap partition and used as virtual memory .
zram1 254:1 0 50M 0 disk /var/log This is also a virtual RAM disk (zram1) with a size of 50MB, which is used as /var/loga directory for saving log information .

  1. View the file system type of the USB flash drive: Use the following command to view the file system type of the selected device
    • **Please /dev/sdXreplace with the actual U disk device node, that is, sdathe partition name in the output result of the second step.
sudo file -s /dev/sdX
  • Demo:
    root@armbian:~# sudo file -s /dev/sda1
    /dev/sda1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID “MSDOS5.0”, sectors/cluster 32, reserved sectors 2784, 
    Media descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 64, sectors 61439936 (volumes > 32 MB), 
    FAT (32 bit), sectors/FAT 14992, reserved 0x1, serial number 0x3272a6ee, unlabeled
    
    • Conclusion: The file system of the U disk is recognized as FAT (32-bit) format.
  • Here is an interpretation of the output:
    1. DOS/MBR boot sector: Indicates that the partition uses the DOS/MBR boot sector format. DOS/MBR is a common partitioning scheme that works on most Windows and Linux systems.
    2. Code offset 0x58+2: The offset of the boot code, indicating the position of the boot code in the boot sector.
    3. OEM-ID "MSDOS5.0": Indicates that the OEM ID of the partition is "MSDOS5.0", which means that the partition was probably created under MS-DOS 5.0 or a similar system.
    4. Sectors/cluster 32: The number of sectors occupied by each cluster. A cluster is the basic unit of file system management space.
    5. Reserved sectors 2784: The number of reserved sectors. These sectors are used to store metadata such as boot code and partition tables.
    6. Media descriptor 0xf8: Media descriptor indicating the media type of the partition. 0xf8 corresponds to a standard hard disk media type.
    7. Sectors/track 63: The number of sectors per track. A track is a circular track on the surface of a disk.
    8. Heads 255: The number of heads. A magnetic head is the physical component of a disk drive that reads and writes data.
    9. Hidden sectors 64: The number of hidden sectors. Hidden sectors are the number of sectors that are located in front of the partition and are not visible.
    10. Sectors 61439936: The total number of sectors of the partition. This determines the size of the partition.
    11. FAT (32 bit): The file system type is FAT32, which is a common Windows file system format.
    12. Sectors/FAT 14992: The number of sectors occupied by each FAT table. The FAT table is a data structure used by the FAT file system to store file allocation information.
    13. Reserved 0x1: The value of the reserved field is 0x1, indicating the content of the reserved field.
    14. Serial number 0x3272a6ee: Partition serial number. Each partition has a unique serial number that identifies the partition.
    15. Unlabeled: The partition has no label or name.

  1. Create a mount point:
    • Before mounting the U disk, you need to create a mount point, which is a directory for accessing and managing the contents of the U disk.
    • For example, a /mntdirectory under can be created as a mount point. Run the following command:
       sudo mkdir /mnt/usb
    

  1. Mount the U disk:
    • In order to mount partitions and support Chinese filenames, the filesystem needs to be mounted with the correct options.
    • You need to specify the file system type (in this case vfat, this is FAT32the file system type), and use iocharsetthe option to set the character set of the file name, so that the Chinese file name can be displayed correctly. The command is as follows:
       sudo mount -t vfat /dev/xxx /mnt/usb -o iocharset=utf8
    
    • Note: /dev/xxxReplace with the name of the USB device found in step 2.

  1. Verify mount: You can use df -hthe command to view the mount status of the file system.
    • For example:
    root@armbian:~# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            1.8G     0  1.8G   0% /dev
    tmpfs           394M  6.2M  387M   2% /run
    /dev/mmcblk1p2   29G  2.2G   27G   8% /
    tmpfs           2.0G     0  2.0G   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           2.0G  8.0K  2.0G   1% /tmp
    /dev/mmcblk1p1  223M   80M  139M  37% /boot
    /dev/zram1       49M  2.5M   43M   6% /var/log
    tmpfs           394M     0  394M   0% /run/user/0
    /dev/sda1        30G   64K   30G   1% /mnt/usb
    

  1. Use U disk: /mnt/usbaccess and use the files in the U disk through the path.
cd /mnt/usb

2.2.2 Automatic mount

  • Note: Please use sudothe access authority, it is recommended to use the root user identity to perform the following operations
  1. View block devices and their partitions
    lsblk # 或者 fdisk -l
    
  • demo
    root@armbian:~# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 1 29.3G 0 disk
    └─sda1 8:1 1 29.3G 0 part
    mmcblk1 179:0 0 29.1G 0 disk
    ├─mmcblk1p1 179:1 0 255M 0 part /boot
    └─mmcblk1p2 179:2 0 28.9G 0 part /
    mmcblk1boot0 179:32 0 4M 1 disk
    mmcblk1boot1 179:64 0 4M 1 disk
    zram0 254:0 0 1.9G 0 disk [SWAP]
    zram1 254:1 0 50M 0 disk /var/log
    
  • specific explanation
    • This command displays all block devices and their partition information in the system. Block devices usually include storage devices such as hard drives, SSDs, and USB drives.
result illustrate
sda 8:0 1 29.3G 0 disk This is a 30GB USB HDD ( sda)
1indicates that the device supports delete flags, 0indicating that the device has no read-only flags
8:0are the major and minor numbers of the device.
└─sda1 8:1 1 29.3G 0 part This is a partition (sda1) of the USB hard drive . It takes up 30GB of the entire USB drive.
Similarly, 1it indicates that the delete mark is supported, 0that there is no read-only mark, and that the device number is 8:1.
mmcblk1 179:0 0 29.1G 0 disk This is a 29.1GB Flash memory (mmcblk1) , which is generally used for storage in embedded systems . This device has two partitions.
├─mmcblk1p1 179:1 0 255M 0 part /boot The first partition is the boot partition , /bootwhich stores the kernel and boot configuration files required for booting , with a size of 255MB.
└─mmcblk1p2 179:2 0 28.9G 0 part / The second partition is root , which is the root partition of the system and stores system and user files , with a size of 28.9GB.
mmcblk1boot0 179:32 0 4M 1 diskandmmcblk1boot1 179:64 0 4M 1 disk These two devices are two special boot partitions of the Embedded Multimedia Card (EMMC), which are always read-only and can be used as boot loaders.
zram0 254:0 0 1.9G 0 disk [SWAP] This is a virtual RAM disk (zram0) with a size of 1.9GB, which is used as a swap partition and used as virtual memory .
zram1 254:1 0 50M 0 disk /var/log This is also a virtual RAM disk (zram1) with a size of 50MB, which is used as /var/loga directory for saving log information .

  1. Create a mount directory: The mount command itself does not automatically create a directory, but needs to ensure that the directory exists before the file system can be mounted to the directory.
    mkdir /mnt/usb
    
    • Here use mkdir /mnt/usbas mount directory
  2. Configure auto-mount file: If you want the system to automatically mount the U disk, you need to edit /etc/fstabthe file to achieve. Add a line to the end of the file, then save and exit.
    # 将一个名为/dev/sda1的vfat文件系统挂载到/mnt/usb目录上的
    /dev/sda1  /mnt/usb  vfat  auto,nofail,noatime,rw,users,iocharset=utf8  0  0
    
  • After restarting the system, the U disk will be automatically mounted to /mnt/usbthe

Here is an explanation of each part:

  1. /dev/sda1: This is a device file that represents the first partition of the device sda.
    • In Linux, disk devices are usually denoted as /dev/sdX, where X is the letter a, b, c, etc. to identify different devices. The number 1 indicates the first partition of the device.
  2. /mnt/usb: The target directory where the file system will be mounted . In this command, the file system will be mounted on /mnt/usbthe directory.
  3. vfat: The file system type, indicating that the FAT file system is used . FAT is a commonly used file system format, often used on removable devices such as USB flash drives. Check the operation of the file system type, please refer to the operation method in manual operation
  4. auto: mount option, which means to automatically detect the type of the file system .
  5. nofail: The mount option, which means that if the file system cannot be mounted, the startup process will not fail . This is useful for optional filesystems to prevent the system boot process from failing because some drives cannot be mounted.
  6. noatime: A mount option, indicating that the access time of the file is not recorded . This can improve file system performance.
  7. rw: Mount option, which means to mount the file system in read-write mode . This means that users can read and write to the file system.
  8. users: mount option, allowing ordinary users to mount and unmount file systems .
  9. iocharset=utf8: A mount option, indicating that the UTF-8 character set is used to process file names . [UTF-8 is a universal character encoding that can handle various languages ​​and characters. ]
  10. 0: The backup option of the file system, used to determine when the file system needs to be backed up. 0 means no backup.
  11. 0: The detection option of the file system, used to determine whether to detect the file system when the system is booted. 0 means no detection.

Three armbian unmount U disk

  • Before pulling out the USB flash drive (U disk), it is best to unmount it (safely unmount or unmount it) to ensure that the data writing has been completed and avoid data loss.
  • The following are the steps to uninstall the USB flash drive in the Linux system:
  1. Find the mount point of the USB flash drive: Run the following command to view the list of mounted file systems:

     mount
    
    • Find the mount point of the USB flash drive in the output, usually displayed as a path similar to /mnt/usbor /media/username/usb.
  2. Uninstall the USB flash drive: Use the following command to unmount the USB flash drive.

    # 如果U盘已经挂载到其他位置,请根据实际情况更改卸载命令中的路径。
    sudo umount /mnt/usb
    
  3. Wait for the uninstallation to complete: After executing the uninstallation command, please wait for a while to ensure that the system completes the uninstallation operation and releases the use of the U disk.

  4. Safely pull out the USB flash drive: After confirming that the USB flash drive has been completely uninstalled, you can safely pull it out.

    • Please note, do not pull out the USB flash drive during the file transfer process, so as not to damage the data or file system.

Guess you like

Origin blog.csdn.net/yang2330648064/article/details/131713892