码迷,mamicode.com
首页 > 移动开发 > 详细

Linux系统自动挂载USB移动硬盘

时间:2015-09-14 12:28:32      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:linux 挂载移动硬盘   usb   

在Linux系统上挂载USB设备并不难,用简单的mount命令就可以轻松挂载USB设备。但是如果你挂载的USB移动硬盘是分为多个分区的话当你重新启动系统时你所挂载的分区有可能会挂载到另外一个路径去。为了避免这个问题,我们必须保障多分区的USB移动硬盘挂载到Linux系统时通过硬件的ID来之别躯体挂载到那个路径上去。


首先为了让linux系统识别NTFS格式硬盘,安装

sudo apt-get install ntft-3g

在系统上创建几个目录用于挂载移动硬盘

sudo mkdir /mnt/disk1

sudo mkdir /mnt/disk2

sudo mkdir /mnt/disk3

sudo mkdir /mnt/disk4

然后利用fdisk -l查看USB移动硬盘的盘符

pi@raspberrypi ~ $ sudo fdisk -l


Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes

4 heads, 16 sectors/track, 486192 cylinders, total 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 identifier: 0xa6202af7


        Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)

/dev/mmcblk0p2          122880    31116287    15496704   83  Linux


Disk /dev/sda: 500.1 GB, 500107862016 bytes

255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0xf91440c6


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1              63   204796619   102398278+   7  HPFS/NTFS/exFAT

/dev/sda2       204796620   976768064   385985722+   f  W95 Ext‘d (LBA)

/dev/sda5       204796683   614389859   204796588+   7  HPFS/NTFS/exFAT

/dev/sda6       614389923   976768064   181189071    7  HPFS/NTFS/exFAT

pi@raspberrypi ~ $ 

j

接下来就是关键一步,查看USB移动硬盘的硬件ID

i@raspberrypi ~ $ ls -la /dev/disk/by-id

total 0

drwxr-xr-x 2 root root 400 Sep 13 21:48 .

drwxr-xr-x 6 root root 120 Jan  1  1970 ..

lrwxrwxrwx 1 root root   9 Sep 13 21:48 ata-Hitachi_HTS545050B9A300_120208PBG408P7HXNZBV -> ../../sda

lrwxrwxrwx 1 root root  10 Sep 13 21:48 ata-Hitachi_HTS545050B9A300_120208PBG408P7HXNZBV-part1 -> ../../sda1

lrwxrwxrwx 1 root root  10 Sep 13 21:48 ata-Hitachi_HTS545050B9A300_120208PBG408P7HXNZBV-part2 -> ../../sda2

lrwxrwxrwx 1 root root  10 Sep 13 21:48 ata-Hitachi_HTS545050B9A300_120208PBG408P7HXNZBV-part5 -> ../../sda5

lrwxrwxrwx 1 root root  10 Sep 13 21:48 ata-Hitachi_HTS545050B9A300_120208PBG408P7HXNZBV-part6 -> ../../sda6

lrwxrwxrwx 1 root root  13 Jan  1  1970 memstick-SL16G_0x2833b5cb -> ../../mmcblk0

lrwxrwxrwx 1 root root  15 Sep 13 21:48 memstick-SL16G_0x2833b5cb-part1 -> ../../mmcblk0p1

lrwxrwxrwx 1 root root  15 Sep 13 21:48 memstick-SL16G_0x2833b5cb-part2 -> ../../mmcblk0p2

lrwxrwxrwx 1 root root   9 Sep 13 21:48 scsi-SGeneric_External_120208PBG408P7HXNZBV -> ../../sda

lrwxrwxrwx 1 root root  10 Sep 13 21:48 scsi-SGeneric_External_120208PBG408P7HXNZBV-part1 -> ../../sda1

lrwxrwxrwx 1 root root  10 Sep 13 21:48 scsi-SGeneric_External_120208PBG408P7HXNZBV-part2 -> ../../sda2

lrwxrwxrwx 1 root root  10 Sep 13 21:48 scsi-SGeneric_External_120208PBG408P7HXNZBV-part5 -> ../../sda5

lrwxrwxrwx 1 root root  10 Sep 13 21:48 scsi-SGeneric_External_120208PBG408P7HXNZBV-part6 -> ../../sda6

lrwxrwxrwx 1 root root   9 Sep 13 21:48 wwn-0x5000cca6addb20a6 -> ../../sda

lrwxrwxrwx 1 root root  10 Sep 13 21:48 wwn-0x5000cca6addb20a6-part1 -> ../../sda1

lrwxrwxrwx 1 root root  10 Sep 13 21:48 wwn-0x5000cca6addb20a6-part2 -> ../../sda2

lrwxrwxrwx 1 root root  10 Sep 13 21:48 wwn-0x5000cca6addb20a6-part5 -> ../../sda5

lrwxrwxrwx 1 root root  10 Sep 13 21:48 wwn-0x5000cca6addb20a6-part6 -> ../../sda6


找到硬件ID后修改/etc/fstab文件

pi@raspberrypi ~ $ cat /etc/fstab

proc            /proc           proc    defaults          0       0

/dev/mmcblk0p1  /boot           vfat    defaults          0       2

/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

/dev/sda1 /mnt/disk1 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/sda2 /mnt/disk2 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/sda5 /mnt/disk3 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/sda6 /mnt/disk4 ntfs-3g defaults,noexec,umask=0000 0 0


/dev/disk/by-id/scsi-SGeneric_External_120208PBG408P7HXNZBV-part1 /mnt/disk1 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/disk/by-id/scsi-SGeneric_External_120208PBG408P7HXNZBV-part2 /mnt/disk2 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/disk/by-id/scsi-SGeneric_External_120208PBG408P7HXNZBV-part5 /mnt/disk3 ntfs-3g defaults,noexec,umask=0000 0 0

/dev/disk/by-id/scsi-SGeneric_External_120208PBG408P7HXNZBV-part6 /mnt/disk4 ntfs-3g defaults,noexec,umask=0000 0 0



重启系统后发现系统自动加载了USB移动硬盘。





本文出自 “菜鸟极客” 博客,请务必保留此出处http://raspjason.blog.51cto.com/8565009/1694437

Linux系统自动挂载USB移动硬盘

标签:linux 挂载移动硬盘   usb   

原文地址:http://raspjason.blog.51cto.com/8565009/1694437

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!