標籤: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移動硬碟的盤符
[email protected] ~ $ 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
[email protected] ~ $
j
接下來就是關鍵一步,查看USB移動硬碟的硬體ID
[email protected] ~ $ 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檔案
[email protected] ~ $ 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移動硬碟