首页 > 代码库 > linux 挂载硬盘和自动挂载
linux 挂载硬盘和自动挂载
①挂载:
插入硬盘前:fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000196c4
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2093 16501760 83 Linux
/dev/sda3 2093 2611 4161536 82 Linux swap / Solaris
插入硬盘后:fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000196c4
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2093 16501760 83 Linux
/dev/sda3 2093 2611 4161536 82 Linux swap / Solaris
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x84ea92ab
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 5 Extended
增加了一个/dev/sdb: 2147MB.....
创建挂载点:mkdir /mnt/sdb1
挂载sdb:mount /dev/sdb /mnt/sdb1
查看是否挂载成功:df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G 2.2G 13G 15% /
tmpfs 1012M 112K 1012M 1% /dev/shm
/dev/sda1 291M 29M 248M 11% /boot
/dev/sdb 2.0G 68M 1.9G 4% /mnt/sdb1
最后出现了sdb,则挂载成功;
②自动挂载
获取root权限
vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Apr 23 13:11:23 2014
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=2223d149-2c01-4da9-9a63-b309333d0412 / ext4 defaults 1 1
UUID=56aa6450-c74a-4611-9d3e-648222a5ae3b /boot ext4 defaults 1 2
UUID=97acb599-022e-4d38-8605-297d564f5fa3 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
在最后一行加入:/dev/sdb /mnt/sdb1 ext4 defaults 0 0
注:第一列为设备号或该设备的卷标
第二列为挂载点
第三列为文件系统
第四列为文件系统参数
第五列为是否可以用demp命令备份。0:不备份,1:备份,2:备份,但比1重要性小。设置了该参数后,Linux中使用dump命令备份系统的时候就可以备份相应设置的挂载点了。
第六列为是否在系统启动的时候,用fsck检验分区。因为有些挂载点是不需要检验的,比如:虚拟内存swap、/proc等。0:不检验,1:要检验,2要检验,但比1晚检验,一般根目录设置为1,其他设置为2就可以了
reboot
查看是否自动挂载成功:df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G 2.2G 13G 15% /
tmpfs 1012M 112K 1012M 1% /dev/shm
/dev/sda1 291M 29M 248M 11% /boot
/dev/sdb 2.0G 68M 1.9G 4% /mnt/sdb1
最后出现了sdb,则挂载成功。