ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

6.磁盘内容

2019-08-01 11:57:28  阅读:216  来源: 互联网

标签:oldboyedu 02 dev 内容 swap 磁盘 root


1.磁盘体系结构

6.磁盘内容

1.2磁盘组成

盘片
主轴
磁头

1.3磁盘接口类型

SATA
SAS
SCSI
PCI-E速度最快

1.4磁盘接口选择与磁盘选择

磁盘接口分类

6.磁盘内容

磁盘接口选择

6.磁盘内容

硬盘分类

6.磁盘内容

硬盘选择

6.磁盘内容

机械硬盘可以无限次写入数据
固态硬盘,例如500G为总量,写满一次算一次,总共可写入1-2万次

1.5磁盘内部组成

6.磁盘内容

磁头(head):
盘面的数量==磁头数量
作用:用来读写数据

磁道(track):
以主轴为圆心的不同圆环区域,从外面到里面,最外面是0磁道

扇区(selector):
磁道上面的最小单位,默认大小是512字节

柱面(sylinder):
不同盘面上的相同磁道组成的圆柱体
柱面数==磁道数
磁盘默认按照柱面读写数据

单元块(units):
表示一个柱面的大小

6.磁盘内容

1.6计算磁盘大小

磁盘大小=每个柱面的大小*柱面数量
每个柱面的大小=磁道大小*磁盘数量
磁道大小=每个扇区大小*扇区数量
[root@oldboyedu-02 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x0002da79

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         124      786432   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             124        1306     9493504   83  Linux
[root@oldboyedu-02 ~]# awk 'BEGIN{print 1/3}'
0.333333
[root@oldboyedu-02 ~]# awk 'BEGIN{print 512*63*255*1305/1024^3}'
9.99681
[root@oldboyedu-02 ~]# awk 'BEGIN{print 512*63*255*1305/1000^3}'
10.734
[root@oldboyedu-02 ~]# echo 512*63*255*1305/1000^3|bc
10
[root@oldboyedu-02 ~]#

1B=8bit
1KB=1024B
1MB=1024KB
1GB=1024MB
1TB=1024GB

1.7RAID

6.磁盘内容

1.8磁盘分区

磁盘分区表:
位置:0磁头0磁道1扇区
磁盘--盘片--MBR

6.磁盘内容

主分区:
存放数据的分区,最多有四个

扩展分区:
不能存储数据
只能有一个
需要在扩展分区中创建逻辑分区才能存放数据

逻辑分区:
存放数据

磁盘命名:
sas/sata/scsi接口 sd 第一块sas硬盘sda,第二块sas硬盘sdb

分区命名:
主分区/扩展分区: 1-4
逻辑分区:从5开始

例子:
第一块sas硬盘的第一个主分区 /dev/sda1
第三块sas硬盘的第二个扩展分区 /dev/sdc6
第四块sata硬盘的第一个扩展分区 /dev/sdd5

1.8.1fdisk分区

fdisk
支持的磁盘大小2T
fdisk支持MBR
1.fdisk分区
例子:给/dev/sdb硬盘只创建一个分区,把他挂在到/mnt上面
首先创建分区
[root@oldboyedu-02 ~]# fdisk -cu /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-208895, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 
Using default value 208895

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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: 0x429514a3

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      208895      103424   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2.通知系统/dev/sdb硬盘的磁盘分区表变化了
[root@oldboyedu-02 ~]# partprobe /dev/sdb

3.格式化创建文件系统
[root@oldboyedu-02 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25896 inodes, 103424 blocks
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4.关闭磁盘分区的自动检查
[root@oldboyedu-02 ~]# tune2fs -c 0 -i 0 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds 
-c 0  count关闭每挂载多少次就进行磁盘检查的功能
-i 0   interval 关闭每隔180天就进行磁盘检查的功能

5.挂载
[root@oldboyedu-02 ~]# mount /dev/sdb1 /mnt

6.永久挂载
1)把挂载命令写到/etc/rc.local中
/bin/mount  /dev/sdb1 /mnt
2)配置到/etc/fstab
UUID=b3a88d2b-b491-46ff-96a1-a9eff1a5c3a5 /         ext4    defaults        1 1
UUID=8848e519-989b-4a1f-9fdb-803f0b56db57 /boot    ext4    defaults        1 2
UUID=b6a11888-75c1-4a5f-98fa-32c323404e4e swap     swap   defaults        0 0
/dev/sdb1                                        ext4     defaults       0 0
第一列:设备名
第二列:挂载点
第三列:文件系统类型
第四列:挂载参数
第五列:是否进行备份
第六列:是否进行磁盘检查,系统的要进行检查,自己创建的就不需要检查

7.卸载
1、直接卸载

  [root@localhost /]# umount /data1/img
  umount: /data1/img: device is busy
  umount: /data1/img: device is busy
2、提示被占用,使用强制卸载

  [root@localhost /]# umount -f /data1/img
  umount2: Device or resource busy
  umount: /data1/img: device is busy
  umount2: Device or resource busy
  umount: /data1/img: device is busy
注:使用-f 参数进行强制卸载时一般建议等一会儿再进行下面的操作,一些情况下处理需要1-2分钟的时间。

3、使用umount -f,问题依旧。使用fuser命令,先确认有那些进程在占用该目录

  [root@localhost /]# fuser -cu /data1/img
  /data1/img: 1757c(mysql)
上面查看发现是pid为1757的mysql用户起的进程在占用该目录。

4、确认mysql所起的进程可以kill 后,可以直接使用fuser 的k参数进行kill (也可以手动停掉1757进程再卸载)

  [root@localhost /]# fuser -ck /data1/img
  /data1/img: 1757c
注:这里k 就是kill的意思,注意没进行确认前要谨慎使用该参数。
  另外,umount异常时,也经常会用到 lsof 指定确认文件被什么进程占用
[root@oldboyedu-01 scripts]# lsof|grep /var/log/messages
rsyslogd  1241      root    1w      REG                8,3   319521     140398 /var/log/messages
  上面就是Linux使用umount命令强制卸载文件系统的方法,即使提示被占用也照样能够通过命令来卸载

1.8.2parted分区

主要用于磁盘大于2T
基于GPT分区表
支持的磁盘写法有0 30M, 0 200G  0 2T

p 显示磁盘分区表信息
mklabel 创建磁盘分区表--gpt/msdos(mbr)
mkpart 创建分区
rm 删除分区
q 退出不保存

交互式创建

创建30M
[root@oldboyedu-02 ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Error: /dev/sdc: unrecognised disk label                                  
(parted) mklabel gpt                                                      
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 0 30                                              
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  30.0MB  30.0MB               primary

(parted) mkpart primary 30 60
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  30.0MB  30.0MB               primary
 2      30.4MB  59.8MB  29.4MB               primary

(parted)quit

非交互式创建

非交互式创建
[root@oldboyedu-02 ~]# parted /dev/sdc mklabel gpt
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/No? yes                                                               
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-02 ~]# parted /dev/sdc mkpart primary 0 30 Ignore
Warning: The resulting partition is not properly aligned for best performance.
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-02 ~]# parted /dev/sdc mkpart primary 30 60 
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-02 ~]# parted /dev/sdc print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  30.0MB  30.0MB               primary
 2      30.4MB  59.8MB  29.4MB               primary

[root@oldboyedu-02 ~]#
[root@oldboyedu-01 ~]# parted /dev/sdb mklabel gpt 
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-01 ~]# parted /dev/sdb mkpart primary 0 2T 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-01 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  2000GB  2000GB               primary

[root@oldboyedu-01 ~]# parted /dev/sdb mkpart primary 2T 100% 
Information: You may need to update /etc/fstab.                           

[root@oldboyedu-01 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  2000GB  2000GB               primary
 2      2000GB  3221GB  1221GB               primary

1.9增加swap

Java内存不足,导致大量占用swap,怎样临时增加swap

1.创建文件块
[root@oldboyedu-02 ~]# dd if=/dev/zero of=/tmp/swap bs=1MB count=100
100+0 records in
100+0 records out
100000000 bytes (100 MB) copied, 1.45344 s, 68.8 MB/s
[root@oldboyedu-02 ~]# ls -lh /tmp/swap 
-rw-r--r-- 1 root root 96M Mar  1 07:18 /tmp/swap

2.变成swap
[root@oldboyedu-02 ~]# mkswap /tmp/swap 
mkswap: /tmp/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 97652 KiB
no label, UUID=09537748-05e6-4e1f-89cf-ff42cea75160
[root@oldboyedu-02 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           980        230        750          0         13        133
-/+ buffers/cache:         83        897
Swap:          767          0        767

3.增加swap
[root@oldboyedu-02 ~]# swapon /tmp/swap

4.验证
[root@oldboyedu-02 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           980        230        750          0         13        133
-/+ buffers/cache:         83        897
Swap:          863          0        863
[root@oldboyedu-02 ~]#

5.取消增加的swap
[root@oldboyedu-02 ~]# swapoff /tmp/swap 
[root@oldboyedu-02 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           980        230        750          0         13        133
-/+ buffers/cache:         83        897
Swap:          767          0        767
[root@oldboyedu-02 ~]#

6.swap永久生效
方法一:命令写到/etc/rc.local中
swapon /tmp/swap
方法二:/etc/fstab中
/tmp/swap   swap   swap    defaults   0 0 

1.10Linux把我的内存吃了-查看内存

linux 特点会把使用过的命令和数据临时存放在内存中,buffer和cache中,主要是为了提升速度
实际的内存使用量看第二行
[root@oldboyedu-02 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          980M       230M       750M       248K        13M       133M
-/+ buffers/cache:        83M       897M
Swap:         767M         0B       767M

1.11文件系统组成

inode记录文件属性和block位置
block存放文件数据
superblock记录整个文件系统中inode和block使用了多少,剩余多少。
dumpe2fs -h /dev/sda1可查看superblock中信息

[root@oldboyedu-02 ~]# dumpe2fs -h /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:   <none>
Last mounted on:          /boot
Filesystem UUID:          8848e519-989b-4a1f-9fdb-803f0b56db57
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              51200
Block count:              204800
Reserved block count:     10240
Free blocks:              154188
Free inodes:              51161
First block:              1

1.12文件系统的选择

opensuse linux的默认文件系统ReiserFS文件系统
IBM的AIX使用jfs日志文件系统
Centos7采用XFS文件系统
Centos6采用ext4文件系统
Centos5采用ext3文件系统

1.13磁盘命令

fdisk:磁盘分区工具,磁盘大小不超过2T
parted:磁盘分区工具,磁盘大小大于2T
partprobe:通知系统磁盘的分区信息变化,更新内核的硬盘分区表信息
tune2fs:调整ext2/ext3/ext4文件系统参数
-c 0 关闭每挂载多少次进行磁盘检查
-i 0 关闭每隔多久进行磁盘检查
关闭磁盘分区的自动检查
mkfs:创建Linux文件系统
-t 指定文件系统类型
mkfs.ext4==mkfs -t ext4
dumpe2fs:显示superblock信息
resize2fs:调整ext2/ext3/ext4文件系统大小
fsck:检查并修复linux文件系统
-a
dd:转换或复制文件
od:查看二进制文件内容
od -xa /tmp/512.bin
mount:挂载文件系统
umount:卸载文件系统
df:报告文件系统磁盘空间使用情况
mkswap:创建交换分区
swapon:激活交换分区
swapoff:关闭交换分区
sync:刷新问阿金系统缓冲区
top:
iotop:查看系统磁盘读写速度,显示出进程使用swap的情况
io: input/output
htop:top的升级
iftop:查询网卡流量情况
-i 指定监视网卡

标签:oldboyedu,02,dev,内容,swap,磁盘,root
来源: https://blog.51cto.com/10983441/2425548

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有