linux下如何挂载硬盘?

linux下如何挂载硬盘?,第1张

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 Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        2611    20458496   8e  Linux 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 Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        2610    20964793+  83  Linux

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

a   toggle a bootable flag      #设定可启动标记

b   edit bsd disklabel

c   toggle the dos compatibility flag

d   delete a partition          #删除一个分区

l   list known partition types  #各分区类型所对应的ID

m   print this menu             #菜单

n   add a new partition         #添加一个分区

o   create a new empty DOS partition table

p   print the partition table   #显示该磁盘下的当前分区信息

q   quit without saving changes #不保存退出

s   create a new empty Sun disklabel

t   change a partition's system id

u   change display/entry units

v   verify the partition table

w   write table to disk and exit #保存退出

x   extra 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 Boot      Start         End      Blocks   Id  System

Command (m for help): n //创建一个新的分区

Command action

e   extended//输入e为创建扩展分区

p   primary partition (1-4) //输入p为创建逻辑分区

p

Partition number (1-4): 1//划分逻辑分区

First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区

Using default value 1

Last cylinder, +cylinders or +size{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 Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        2610    20964793+  83  Linux

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 Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        2610    20964793+  83  Linux

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两个磁盘挂载

Filesystem                    Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root   18G   15G  1.5G  92% /

tmpfs                         932M   76K  932M   1% /dev/shm

/dev/sda1                     485M   40M  421M   9% /boot

/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone

/dev/sr0                      4.2G  4.2G     0 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 root  4096 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下手动设置Windows磁盘挂载点

我的笔记本是同时装了Linux系统和Windows系统。Linux系统启动后,Windows磁盘就会自动挂载在/media目录下,而且挂载点的名称又长又难记。例如,windows系统C盘挂载后名称变为FE6C0C5C6C0C1257。如果windows系统总共有好几个盘,那么挂载后,就是一堆字符串,很难分辨到底各自对应哪个盘。于是,我决定手动修改磁盘挂载点。

首先,执行命令“sudo fdisk -l”,显示系统存在的各个磁盘分区信息如下所示:

Device Boot Start End Blocks Id System

/dev/sda1 * 1 2150 17269843 7 HPFS/NTFS

/dev/sda2 2151 14593 99948367 5 Extended

/dev/sda5 2151 4802 21302158+ 7 HPFS/NTFS

/dev/sda6 7414 14593 57673318+ 7 HPFS/NTFS

/dev/sda7 4803 5051 1998848 82 Linux swap / Solaris

/dev/sda8 5052 7413 18971648 83 Linux

由于我的windows系统总共有3个盘:C盘,D盘,E盘,且都是NTFS格式,所以“/dev/sda1”应该对应C盘,“/dev/sda5”应该对应D盘,“/dev/sda6”应该对应E盘。C盘是windows *** 作系统,一般不需要访问。只需要重新挂载D盘和E盘即可。于是我使用mkdir命令在"/home/cary"(cary为我的用户名)目录下创建了programFiles和myDocuments两个目录分别作为D盘和E盘的挂载点(实际上这两个目录的名字是可以随意命名的)。

执行“sudo gedit /etc/fstab”打开fstab文件。参照文件中提示的格式,在文件最后添加下面两行语句:

/dev/sda5 /home/cary/programFiles ntfs defaults,user,rw 0 0

/dev/sda6 /home/cary/myDocuments ntfs defaults,user,rw 0 0

保存该文件后,先执行"sudo umount -a"命令卸载各磁盘,再执行“sudo mount -a”重新挂载所有磁盘。则D盘和E盘就都挂载在指定路径下了。通过“~/programFiles”和“~/myDocuments”两个路径就能访问。

下面对fstab文件作简单介绍。

文件/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件,则可以通过mount /directoryname命令来加载一个文件系统,每种文件系统都对应一个独立的行,每行中的字段都有空格或tab键分开。

fstab文件格式示例如下:

fs_spec fs_file fs_type fs_options fs_dump fs_pass

/dev/hda1 / ext2 defaults 1 1

fs_spec - 该字段定义希望加载的文件系统所在的设备或远程文件系统,对于一般的本地块设备情况来说:IDE设备一般描述为/dev/hdaXN,X是IDE设备通道 (a, b, or c),N代表分区号;SCSI设备一描述为/dev/sdaXN。

fs_file - 该字段描述希望的文件系统加载的目录点,对于swap设备,该字段为none;对于加载目录名包含空格的情况,用40来表示空格。

fs_type - 定义了该设备上的文件系统,一般常见的文件类型为ext2 (Linux设备的`常用文件类型)、vfat(Windows系统的fat32格式)、NTFS、iso9600等。

fs_options - 指定加载该设备的文件系统是需要使用的特定参数选项,多个参数是由逗号分隔开来。对于大多数系统使用defaults就可以满足需要。其他常见的选项包括:rw 以读写模式加载该文件系统;user 允许普通用户加载该文件系统。

fs_dump - 该选项被dump命令使用来检查一个文件系统应该以多快频率进行转储,若不需要转储就设置该字段为0

fs_pass - 该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序,根文件系统/对应该字段的值应该为1,其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0

首先查看U盘或者移动硬盘文件系统格式

U盘:

移动硬盘:

windows下支持的文件系统格式主要是FAT,ntfs。

inux常见的文件系统有:JFS、 ReiserFS、ext、ext2、ext3、ISO9660、XFS、Minx、MSDOS、UMSDOS、VFAT、NTFS、HPFS、NFS、 SMB、SysV、PROC

不同的文件系统格式的存储设备在linux上挂载的方式不同。

像我的一个硬盘两块分区,各自格式不同就比较麻烦

下面开始正式 *** 作

上面的框是已挂载的,下面的是USB接入的硬盘

成功之后查看:

就可以当普通硬盘一样使用了

直接 cd /ntft 即可进入硬盘目录

查看文件传输速度:


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7620870.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-07
下一篇2023-04-07

发表评论

登录后才能评论

评论列表(0条)

    保存