Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
zh-cn:doc:howto:usb.storage [2015/06/10 10:52] – [挂载USB存储设备] yangflzh-cn:doc:howto:usb.storage [2018/05/01 10:12] – link updated tmomas
Line 1: Line 1:
 +====== USB存储 ======
 +请参见[[zh-cn/doc/techref/flash.layout|doc/techref/flash.layout]]。
  
 +设若您已取得了[[docs:guide-user:storage:usb-installing|基本USB支持]],现在,您也许想要连接USB存储设备到路由器上 (U盘,USB移动硬盘,等等)。这个条目将告诉您所需的步骤和要求。
 +
 +===== 准备工作 =====
 +主要步骤如下:
 +  - 在您的OpenWrt设备上获得[[docs:guide-user:storage:usb-installing|基本USB支持]];
 +  - Install USB storage prerequisites as shown [[usb.storage#Required Packages for USB Storage|below]]). A connected USB storage device (e.g. hard disc) can now be recognised by the system;
 +  - If not already done, partition the device and create the file systems you want (see [[Storage]] on how to do this from within OpenWrt). The device itself and its partitions should immediately be available as [[wp>Device file]]s under ''/dev/''. For example ''/dev/sda'' as the device, with ''/dev/sda1'', ''/dev/sda2'', ... , the partitions. Or, in case it is not partitioned with a partition table and it has a single file system it may be directly accessible under e.g. ''/dev/sda''. Subsequent devices you add will be ''/dev/sdb'', ''/dev/sdc'' and so on. Make sure that the file system requirements are satisfied by installing the proper kernel packages for specific file system support (see [[Storage]]);
 +  - These file systems can then be mounted and accessed, see [[Storage]]. Optionally, you can now configure automatic mounting at boot using ''[[docs:guide-user:storage:fstab|/etc/config/fstab]]'' and you can configure it as [[docs:guide-user:additional-software:extroot_configuration|root file system using extroot]].
 +
 +===== 必须软件包 =====
 +When your USB device is properly recognised by the system, using the proper driver kernel packages listed in [[docs:guide-user:storage:usb-installing|基本USB支持]], the following packages facilitate USB storage support:
 +  ***''kmod-usb-storage''** //required// ... Kernel support for USB Mass Storage devices.
 +  ***''kmod-fs-<file_system>''** //required// ... the file system you formatted your partition in. Common examples include kmod-fs-ext4, kmod-fs-hfs, kmod-fs-hfsplus, kmod-fs-msdos, kmod-fs-ntfs, kmod-fs-reiserfs and kmod-fs-xfs.
 +  ***''kmod-usb-storage-extras''** //optional// ... Kernel support for some more drivers, such as for SmartMedia card readers.
 +  ***''block-mount''** //recommended// & //required (if using [[docs:guide-user:storage:fstab]] UCI configuration or [[luci]] Mount Points)// ... Scripts used to mount and check block devices (filesystems and swap) and hotplug capability (recognition when device is plugged in).
 +  ***''kmod-scsi-core''** Any mass storage is a generic SCSI device.
 +
 +| {{:meta:icons:tango:48px-outdated.svg.png?nolink}} | Before the [[about:history#timeline|Attitude Adjustment]] release, other optional packages included: ''block-hotplug'' for USB recognition upon plug-in and ''block-extroot'' required for [[docs:guide-user:additional-software:extroot_configuration|rootfs on external storage]]. In [[https://dev.openwrt.org/changeset/26314/trunk|r26314]] the three opkg packages ''block-mount'', ''block-extroot'' and ''block-hotplug'' have been merged into a single package **''block-mount''**. |
 +
 +
 +===== 额外软件包 =====
 +  ***''e2fsprogs''** //additional// This package contains essential ext2/ext3/ext4 filesystem utilities for formatting and checking for errors on ext2/ext3/ext4 filesystems like mkfs.ext3, mkfs.ext4, fsck and other core utilities.
 +
 +===== 示例 =====
 +The following will install USB storage support, assuming USB works already, install ext4 file system support and mount a connected USB drive, pre-partitioned with a Linux swap partition and an ext4 partition. 
 +
 +<code>
 +opkg update
 +opkg install kmod-usb-storage block-mount kmod-fs-ext4
 +mkswap /dev/sda1
 +swapon /dev/sda1
 +mkdir -p /mnt/share
 +mount -t ext4 /dev/sda2 /mnt/share -o rw,sync
 +</code>
 +
 +Note that partitions are usually auto detected, so this should work as well using default settings:
 +
 +    mount /dev/sda2 /mnt/share
 +
 +Another example is how to use an external usb stick with a FAT32 partition (but we'll keep ext4 support also). See also [[Storage]].
 +<code>
 +opkg update
 +opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
 +mkdir -p /mnt/usb
 +mount -t vfat /dev/sda1 /mnt/usb
 +</code>
 +
 +
 +===== 禁止在未挂载时写入 =====
 +
 +You may create an empty file to indicate that the disk is not plugged in so that you don't put files directly onto NAND by doing
 +<code>
 +umount /mnt/usb   #make sure the disk isn't mounted before doing this
 +touch /mnt/usb/USB_DISK_NOT_PRESENT
 +chmod 555 /mnt/usb 
 +chmod 444 /mnt/usb/USB_DISK_NOT_PRESENT
 +</code>
 +This will prevent only processes not running as root from writing onto NAND (see [[https://forum.openwrt.org/viewtopic.php?id=42351|this discussion]]). You can of course also use this file in your own scripts.
 +
 +===== LUKS =====
 +Linux Hard Disk Encryption With LUKS
 +  - Install required packages: <code>opkg install cryptsetup lvm2 kmod-crypto-aes kmod-crypto-misc kmod-crypto-xts kmod-crypto-iv kmod-crypto-cbc kmod-crypto-hash kmod-dm</code>
 +  - Create necessary config files: Most of the kmod-crypto-* packages create file in /etc/modules.d folder that automatically installs provided modules at boot time. However kmod-crypto-misc containing sha256 module (among others) is an exception to this, hence we need to create such a file manually: <code>echo sha256_generic >/etc/modules.d/11-crypto-misc</code>
 +  - Mounting your encrypted partition: Replace /dev/encrypted_partition with a path to the device file of your encrypted partition and /mnt/mountpoit with your desired mount point: <code>cryptsetup luksOpen /dev/encrypted_partition usbstorage_luks && mount /dev/mapper/usbstorage_luks /mnt/mountpoint</code>
 +  - Umounting: <code>umount /mnt/mountpoint && cryptsetup luksClose usbstorage_luks</code>
 +
 +===== 注释 =====
 +<none yet> 
 +/* the previous note was moved to the OPKG page since it was specific to that */
 +
 +===== Tags =====
 +{{tag>USBrelated}}
  • Last modified: 2019/08/26 16:40
  • by vgaetera