linux下如何挂载硬盘?

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

1插入新硬盘,启动Linux服务器,使用fdisk -l 查看硬盘

#fdisk -l

Disk /dev/sdb: 10002 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: 215 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: 215 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: 215 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: 215 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: 215 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: 215 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 ~]# mkfsext3 /dev/sdc1

//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下

1

2

[root@localhost ~]# mkfsext3 /dev/sdc1

mke2fs 14112 (17-May-2010)

文件系统标签=

*** 作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5241198 blocks

262059 blocks (500%) 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  15G  92% /

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

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

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

/dev/sr0                      42G  42G     0 100% /media/CentOS_65_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

inode满了清理一些不要的文件;

查看Linux服务器的iNode使用情况

df -ih

Inodes 总共 、 IUsed 使用的 、IFree未使用

结合df -h、du -sh 查看占用大的

(但是有可能是小文件这个就要慢慢排查了)

Linux的发行版本不同,重启服务的方式也是不一样的。

centos 6版本:

service 服务名 restart

例如重启vsftpd:

[root@linuxprobe ~]# service vsftpd restart

注意:service 服务器 start/stop/status/restart/reload

这里需要确定下restart 和reload 的区别,restart是重启,也就是kill掉进程,然后在启动进程,而reload是重新加载配置。

centos7x版本:

systemctl restart 服务名

例如重启vsftpd:

[root@linuxprobe ~]# systemctl restart vsftpd

另外,如果服务是编译安装的话,重启的命令就是要看安装包的说明了,例如nginx:

[root@linuxprobe ~]# cd /xxx/xx/xx/sbin

[root@linuxprobe ~]# /nginx -s reload

当然也可以手动些shell重启脚本,一般情况下都是如果重启服务,又没有脚本,比如tomcat,我们一般都是先杀进程 ,然后启服务:

[root@linuxprobe ~]#ps -ef |grep tomcat |grep -v tomcat |awk '{print$2}' |xargs kill -9 && sh /xx/xx/xx/startshsh

更多Linux的知识建议更加系统 的去学习去联系,可以参考《Linux就该这样学》,加油吧!!!

Linux服务器上tomcat如果内存溢出,tomcat就有可能挂掉,直接就结束运行了,不会对服务器本身有影响(不过如果是Web服务器,那就无法继续提供服务了)。Linux程序如果内存溢出程序就直接异常退出了,如果是编程概念中的内存泄露才会对服务器内存有影响,内存泄露会逐渐耗尽服务器的内存,最终服务器会卡、当机。不过内存溢出也有一个影响到服务器的危害,那就是有很少一部分内存溢出是安全漏洞,可以被入侵者利用进而控制服务器,溢出漏洞是危害最大的一类安全漏洞,往往都是属于高危漏洞。

swap是
虚拟内存
,但不是占用的机器内存,而是硬盘空间。你怎么说是从32G内存里来的呢,我还没用过这么大内存的机器。相对于你的内存大小(真有32G的话),
swap设置
是不是太小太小了,通常情况下,Swap空间应大于或等于
物理内存
的大小。
Swap空间的作用可简单描述为:当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用。那些被释放的空间可能来自一些很长时间没有什么 *** 作的程序,这些被释放的空间被临时保存到Swap空间中,等到那些程序要运行时,再从Swap中恢复保存的数据到内存中。
swap值到底是衡量什么指标,应该说是用来均衡IO的负载。
如果Swap空间用完,通常会出现“application
is
out
of
memory”的错误难道你没看到错误。


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

原文地址:https://54852.com/zz/12678442.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2025-08-27
下一篇2025-08-27

发表评论

登录后才能评论

评论列表(0条)

    保存