linux挂载硬盘命令 linux如何挂载硬盘到指定的目录

linux磁盘重新挂载?linux 重新挂载需要先卸载再重新挂载 , 如果要一条命令可以通过符号将两个命令组合到一个命令里,例如:
umount -l /mnt/testmount -o ro /dev/hda1/mnt/test
linux中挂载命令是mount,卸载是umount,在命令行中使用可以将多条命令组合成一条命令并顺序执行,以达到快速执行的目的 。
扩展资料
linux挂载命令mount的用法介绍:
1、语法
mount [-fnrsvw] [-t vfstype] [-o options] device dir
2、参数说明:
-V:显示程序版本
-h:显示辅助讯息
-v:显示较讯息 , 通常和 -f 用来除错 。
-a:将 /etc/fstab 中定义的所有档案系统挂上 。
-F:这个命令通常和 -a 一起使用,它会为每一个 mount 的动作产生一个行程负责执行 。在系统需要挂上大量 NFS 档案系统时可以加快挂上的动作 。
-f:通常用在除错的用途 。它会使 mount 并不执行实际挂上的动作,而是模拟整个挂上的过程 。通常会和 -v 一起使用 。
-n:一般而言,mount 在挂上后会在 /etc/mtab 中写入一笔资料 。但在系统中没有可写入档案系统存在的情况下可以用这个选项取消这个动作 。
linux磁盘挂载linux默认不会识别外部的设备(磁盘),所有我们需要将设备挂载到系统已经存在的目录下才能进行访问 。这个过程就叫做挂载,使用的命令为mount 。
(1)根文件系统是必须最先挂载的
(2)挂载点必须存在
(3)挂载设备和挂载点同一时刻只能挂载一次
3.1 查看文件/etc/fstab,这个文件是挂载的配置文件 , 配置好挂载信息系统重新后会直接读取该文件内容进行自动挂载 。
命令: cat /etc/fstab
文件内容解释:
(1)第一列为挂载设备 , 这里使用的UUID进行挂载,可以通过blkid查询设备的UUD 。
查询UUID命令: blkid /dev/vda1
(2)第二列内容为挂载的位置,即当前设备下存在的路径 。
(3)第三列为挂在的类型,查询UUID时会带有type值即挂载类型 。
(4)第四列为挂载参数,defaults是默认值的意思 。
(5)第五列为是否备份,0代表不要做dump备份;1代表每天进行dunp操作;2代表不定日期进行dump操作 。
(6)是否进行磁盘检验,0代表不检验;1代表最早检验;2代表1级别检验完之后进行检验 。
3.2编辑fstab文件 , 可以使用命令: vim /etc/fstab 进入文件编辑,增加需要挂载的磁盘信息即可 。
3.2编辑完成后,使用 mount -a可以完成的文档在系统挂载
(1)查看系统磁盘挂载信息: df -l
(2)查看服务器有多少块磁盘: lsblk
(3)卸载挂载: umount -l /data/data 是磁盘挂载路径
linux下如何挂载硬盘?1.插入新硬盘 , 启动Linux服务器,使用fdisk -l 查看硬盘
#fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
2.格式化硬盘
#mkfs -t ext4 /dev/sdb
3.挂载硬盘
#mount 硬盘地址 要挂载的地址
#mount /dev/sdb /media/imgs
4.实现系统重启后自动挂载该分区
#vi /etc/fstab
在最后一行添加
/dev/sdb /media/imgs ext4 defaults 1 2
一、添加磁盘
添加加新硬盘重启服务器
添加完之后就可以重启机器了,如果你机器是开启的 , 进入系统并不能看见你刚添加的那块磁盘,只有等系统重启 , 重新加载之后才会显示安装的那块磁盘
二、进入系统
使用root用户进入系统
三、 查看硬盘信息
[root@localhost ~]# fdisk -l//磁盘命令
1
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: 0x000c4cb5
Device BootStartEndBlocksIdSystem
/dev/sda1*16451200083Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2642611204584968eLinux LVM
Disk /dev/sdb: 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: 0xd0f5c869
Device BootStartEndBlocksIdSystem
/dev/sdb1126102096479383Linux
Disk /dev/sdc: 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: 0x00000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
可以看到这台机器加载了三个磁盘sda、sdb、sdc
其中sda是初始磁盘 , sdb已经初始化且经过使用,sdc是刚刚加载的,未格式化的新磁盘
四、创建新硬盘分区
[root@localhost ~]# fdisk /dev/sdc #进入磁盘
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45a3cadb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
atoggle a bootable flag#设定可启动标记
bedit bsd disklabel
ctoggle the dos compatibility flag
ddelete a partition#删除一个分区
llist known partition types#各分区类型所对应的ID
mprint this menu#菜单
nadd a new partition#添加一个分区
ocreate a new empty DOS partition table
pprint the partition table#显示该磁盘下的当前分区信息
qquit without saving changes #不保存退出
screate a new empty Sun disklabel
tchange a partition's system id
uchange display/entry units
vverify the partition table
wwrite table to disk and exit #保存退出
xextra functionality (experts only)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
知道命令之后就可以进行分区了
Command (m for help): p //打印分区信息,可以看到当前并没有分区
Disk /dev/sdc: 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: 0x45a3cadb
Device BootStartEndBlocksIdSystem
Command (m for help): n //创建一个新的分区
Command action
eextended//输入e为创建扩展分区
pprimary partition (1-4) //输入p为创建逻辑分区
p
Partition number (1-4): 1//划分逻辑分区
First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区
Using default value 1
Last cylinder,cylinders orsize{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): p //再次查看可以看到该磁盘已经有1个分区了
Disk /dev/sdc: 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: 0x45a3cadb
Device BootStartEndBlocksIdSystem
/dev/sdc1126102096479383Linux
Command (m for help): w //保存分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
再次使用”fdisk -l”命令查看磁盘信息
Disk /dev/sdc: 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: 0x406a4c58
Device BootStartEndBlocksIdSystem
/dev/sdc1126102096479383Linux
1
2
3
4
5
6
7
8
9
第三块磁盘/dev/sdc已经分区好了
五、格式化分区
[root@localhost ~]# mkfs.ext3 /dev/sdc1
//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下
1
2
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.Use tune2fs -c or -i to override.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
格式化完毕,此时就可以使用“mount”命令挂载分区了,然后使用这个磁盘空间了
六、挂载分区以及开机自动挂载
[root@localhost ~]# df -h //此时只有sda1和sdb1两个磁盘挂载
FilesystemSizeUsed Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root18G15G1.5G92% /
tmpfs932M76K932M1% /dev/shm
/dev/sda1485M40M421M9% /boot
/dev/sdb120G1.2G18G7% /disk/diskone
/dev/sr04.2G4.2G0 100% /media/CentOS_6.5_Final
[root@localhost /]# cd /disk/
[root@localhost disk]# ll
总用量 4
drwxr-xr-x. 4 root root 4096 7月28 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
总用量 20
drwx------. 2 root root 16384 7月28 16:12 lost found
drwxr-xr-x. 2 root root4096 7月28 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //创建被挂载的路径
[root@localhost disk]# ll
总用量 8
drwxr-xr-x. 4 root root 4096 7月28 17:04 diskone
drwxr-xr-x. 2 r
【linux挂载硬盘命令 linux如何挂载硬盘到指定的目录】linux挂载硬盘命令的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于linux如何挂载硬盘到指定的目录、linux挂载硬盘命令的信息别忘了在本站进行查找喔 。

    推荐阅读