最全易懂的磁盘管理体系

 

14 磁盘管理

14.1 磁盘的管理体系结构

14.1.1 磁盘从底层开始往上查看

  • 磁盘的物理结构
  • 磁盘的阵列知识
  • 磁盘的分区方法
  • 磁盘的格式化操作(创建文件系统)
  • 磁盘应用操作

14.2 磁盘的物理结构信息

14.2.1 磁盘的外部结构

  • 转 速:普通家用版:5400/7200
    • 企业10000/15000(机械硬盘拥有,固态硬盘没有这种说法)
  • 机械常用的有sata,scsi,sas
  • 固态接口类型常用的有:pci接口类型
  • 主轴:主轴转动的时候也会带动盘片进行转动
  • 机械臂和磁头:机械臂在摆动的时候,机械臂上面有个磁头,会无限的接近盘片进行读

取数据和写入数据

14.2.2 磁盘的内部结构

  • 磁头:读写和写入数据
  • 磁道:一个盘面上的多个同心圆
  • 扇区:存储数据的最小单位(512byte)
  • 柱面:相同磁道构成的柱面信息
    • 柱面的大小*有多少个柱面==磁盘的总大小
    • 磁道的多少*一个柱面的大小==磁盘的总大小
    • 扇区的多少*单个扇区的大小==磁盘的总大小
  • 盘面:磁盘的一面

14.2.3 数据读取原理

14.2.3.1 数据写入原理

一个10K的文件,首先会写入到inode和block里面,inode和block信息在保存在硬盘的扇区里面

14.2.3.2 数据读取原理

数据读取的时候,磁头会首先读取0磁头0磁道1扇区里面的数据,然后在径向运动读取磁道和扇区里的数据

14.3 磁盘的阵列知识

14.3.1 raid0

  • 特点:平行存储,将数据都分到每个硬盘里面,一块硬盘的损坏都会导致数据的不完整,不可用
  • 磁盘数量:1块或者n
  • 磁盘容量:一共磁盘的总和
  • 优点:读写性能比较高
  • 缺点:无冗余与备份,安全性比较低
  • 应用环境:安全性要求不高的地方,比如图形工作站

14.3.2 raid1

  • 特点:镜像存储,就是将每一个磁盘都写入相同的数据,以保证用户数据的可用性和可修复性
  • 磁盘数量:2个或2个以上
  • 磁盘容量:50%
  • 优点:磁盘数据的安全性比较高
  • 缺点:读写性能低,并且代价昂贵

14.3.3 raid5

  • 特点:奇偶校验方式进行存储,也可以说成是01的折中方案
  • 磁盘数量:3个或3个以上
  • 磁盘容量(n-1)/n的总磁盘容量(n代表磁盘个数)
  • 优点:读写性能提高,由于有奇偶校验方式,磁盘数据安全性提高
  • 缺点:由于需要拿出一块盘来进行奇偶校验,导致磁盘容量缩小

14.3.4 raid10

  • 特点:先具有镜像安全功能,又同时拥有和0一样的存储功能
  • 磁盘数量:4个或4个以上
  • 磁盘容量:总磁盘容量的50%
  • 优点:读写性能提高,利用复制进行冗余,安全机制提高
  • 缺点:磁盘容量缩小

 

14.3.5 raid01

  • 特点:先存储后镜像
  • 磁盘数量:4个或4个以上
  • 磁盘容量:总磁盘容量的50%
  • 优点:读写性能提高,利用复制进行冗余,安全机制提高
  • 缺点:磁盘容量缩小

14.3.6 raid10raid01的区别

  • raid 10 是先镜像后条带,即先将硬盘纵向做镜像,然后再横向做条带。在这种情况下,只要不是同一个镜像组中的几块硬盘同时坏掉,raid组都不会崩溃
  • raid 01 是先条带后镜像,即先将硬盘横向做条带,然后再纵向做镜像。在这种情况下,只要不是两个条带上同时有硬盘坏掉,则整个raid组都不会崩溃。不管发生介质损坏的两块硬盘是否是镜像盘。即不同条带组的硬盘不能同时坏掉。
  • raid 01 发生故障的概率要大于raid 10

14.4 lvm逻辑卷管理

14.4.1 lvm的原理

14.4.2 创建lvm的分区

[root@oldboyedu ~] # fdisk /dev/sdd

 

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

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +500M 第一个分区为500M

Partition 1 of type Linux and of size 500 MiB is set

 

Command (m for help): n 创建分区

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2):

First sector (1026048-41943039, default 1026048):

Using default value 1026048

Last sector, +sectors or +size{K,M,G} (1026048-41943039, default 41943039): +500M 第二个分区为500M

Partition 2 of type Linux and of size 500 MiB is set

 

Command (m for help): n 创建分区

Partition type:

p primary (2 primary, 0 extended, 2 free)

e extended

Select (default p): p

Partition number (3,4, default 3):

First sector (2050048-41943039, default 2050048):

Using default value 2050048

Last sector, +sectors or +size{K,M,G} (2050048-41943039, default 41943039): +1G 第三个分区为1G

Partition 3 of type Linux and of size 1 GiB is set

 

Command (m for help): p 查看已经创建成功的分区

 

Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos

Disk identifier: 0x268819e2

 

Device Boot Start End Blocks Id System

/dev/sdd1 2048 1026047 512000 83 Linux

/dev/sdd2 1026048 2050047 512000 83 Linux

/dev/sdd3 2050048 4147199 1048576 83 Linux

 

Command (m for help): wq 保存退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # fdisk /dev/sdd

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): t 修改分区类型

Partition number (1-3, default 3): 1 修改第一个分区

Hex code (type L to list all codes): l 查看所有的分区类型

 

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris

1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-

2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-

3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-

4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx

5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data

6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .

7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility

8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt

9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access

a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O

b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor

c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs

e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT

f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/

10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b

11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor

12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor

14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary

16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS

17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE

18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto

1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep

1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT

1e Hidden W95 FAT1 80 Old Minix

Hex code (type L to list all codes): 8e 修改成lvm分区类型

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): t 修改分区类型

Partition number (1-3, default 3): 2 修改第二个分区

Hex code (type L to list all codes): 8e 修改成lvm分区类型

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): t 修改分区类型

Partition number (1-3, default 3): 修改第三个分区

Hex code (type L to list all codes): 8e 修改成lvm分区类型

Changed type of partition 'Linux' to 'Linux LVM'

 

Command (m for help): p 查看分区类型是否修改成功

 

Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos

Disk identifier: 0x268819e2

 

Device Boot Start End Blocks Id System

/dev/sdd1 2048 1026047 512000 8e Linux LVM

/dev/sdd2 1026048 2050047 512000 8e Linux LVM

/dev/sdd3 2050048 4147199 1048576 8e Linux LVM

 

Command (m for help): wq 保存并且退出

14.4.3 pv的使用

14.4.3.1 常使用的pv命令

  • pvcreate                                创建物理分区pv
  • pvscan                                扫描具有PV系统的磁盘
  • pvdisplay:                            显示目前系统上的pv信息
  • pvremove:                            将pv删除
  • pvs                                    粗略的显示pv信息

14.4.3.2 创建pv

[root@oldboyedu ~] # pvcreate /dev/sdd{1..3} 创建sda1,sda2.sda3三个pv物理区

Physical volume "/dev/sdd1" successfully created.

Physical volume "/dev/sdd2" successfully created.

Physical volume "/dev/sdd3" successfully created.

[root@oldboyedu ~] #

14.4.3.3 查看pv信息

14.4.3.3.1 简要查看pv信息

[root@oldboyedu ~] # pvs

PV VG Fmt Attr PSize PFree

/dev/sdd1 lvm2 --- 500.00m 500.00m

/dev/sdd2 lvm2 --- 500.00m 500.00m

/dev/sdd3 lvm2 --- 1.00g 1.00g

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] #

14.4.3.3.2 详细查看pv信息

[root@oldboyedu ~] # pvdisplay

"/dev/sdd3" is a new physical volume of "1.00 GiB"

--- NEW Physical volume ---

PV Name /dev/sdd3

VG Name

PV Size 1.00 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID UsqGKD-BBHR-Nj4R-AhYZ-U1e2-3HVI-qD9jgf

 

"/dev/sdd2" is a new physical volume of "500.00 MiB"

--- NEW Physical volume ---

PV Name /dev/sdd2

VG Name

PV Size 500.00 MiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID ocdey8-ewG5-ViEn-aLoJ-La4c-c3Mc-eMkPhT

 

"/dev/sdd1" is a new physical volume of "500.00 MiB"

--- NEW Physical volume ---

PV Name /dev/sdd1

VG Name

PV Size 500.00 MiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID tcor8K-v8AT-yhsX-RitQ-Ygz2-A8sJ-FGZ5s3

 

[root@oldboyedu ~] #

14.4.4 vg的使用

14.4.4.1 常用的vg命令

  • vgcreate                            新建vg
  • vgscan                            扫描现有的vg
  • vgdisplay                            显示vg详细的信息
  • vgextend                            扩展vg可以新增pv物理分区
  • vgreduce:                        缩减vg可以减少pv物理分区
  • vgchange:                        设置vg是否可以自启
  • vgremove:                        删除一个vg

14.4.4.2 创建vg

[root@oldboyedu ~] # vgcreate oldboy_vg01 /dev/sdd1 创建一个oldboy_vg01vg逻辑卷

Volume group "oldboy_vg01" successfully created

[root@oldboyedu ~] #

14.4.4.3 查看vg信息

14.4.4.3.1 简要查看vg信息

[root@oldboyedu ~] # vgs

VG #PV #LV #SN Attr VSize VFree

oldboy_vg01 1 0 0 wz--n- 496.00m 496.00m

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] #

14.4.4.3.2 详细查看vg信息

VG Name oldboy_vg01 vg名字

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 1

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 496.00 MiB vg大小

PE Size 4.00 MiB

Total PE 124

Alloc PE / Size 0 / 0

Free PE / Size 124 / 496.00 MiB

VG UUID mlusFE-Rcdd-2BXa-KurH-EZ8l-Q6y7-7tKF50

 

[root@oldboyedu ~] #

14.4.4.4 扩展vg容量

[root@oldboyedu ~] # vgextend oldboy_vg01 /dev/sdd2 sda2进行扩展在vgoldboy_vg01里面

Volume group "oldboy_vg01" successfully extended

[root@oldboyedu ~] # vgdisplay

--- Volume group ---

VG Name oldboy_vg01

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 2

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 2

Act PV 2

VG Size 992.00 MiB vg大小从500M变成了1000M

PE Size 4.00 MiB

Total PE 248

Alloc PE / Size 0 / 0

Free PE / Size 248 / 992.00 MiB

VG UUID mlusFE-Rcdd-2BXa-KurH-EZ8l-Q6y7-7tKF50

 

[root@oldboyedu ~] #

14.4.4.5 缩减vg容量

[root@oldboyedu ~] # vgreduce oldboy_vg01 /dev/sdd2 sda2进行缩减在vgoldboy_vg01里面

Removed "/dev/sdd2" from volume group "oldboy_vg01"

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # vgdisplay

--- Volume group ---

VG Name oldboy_vg01

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 3

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 1

Act PV 1

VG Size 496.00 MiB vg总大小从1000M变成了496M

PE Size 4.00 MiB

Total PE 124

Alloc PE / Size 0 / 0

Free PE / Size 124 / 496.00 MiB

VG UUID mlusFE-Rcdd-2BXa-KurH-EZ8l-Q6y7-7tKF50

 

[root@oldboyedu ~] #

14.4.5 lv的使用

14.4.5.1 常用的lv命令

lvcreate                            新建lv

lvscan                                扫描现有的lv

lvdisplay                            显示lv的详细信息

lvextend                            扩展lv容量

lvreduce                            减少lv容量

lvremove                            删除一个lv

lvresize                            对lv的大小进行调整

14.5.1.2 创建lv

[root@oldboyedu ~] # lvcreate -L 300M -n oldboy_lv1 oldboy_vg01 创建一个300Mlv,并且名叫oldboy_lv1

WARNING: xfs signature detected on /dev/oldboy_vg01/oldboy_lv1 at offset 0. Wipe it? [y/n]: y

Wiping xfs signature on /dev/oldboy_vg01/oldboy_lv1.

Logical volume "oldboy_lv1" created.

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # mkfs.xfs /dev/oldboy_vg01/oldboy_lv1 lvm进行格式化

meta-data=/dev/oldboy_vg01/oldboy_lv1 isize=512 agcount=4, agsize=19200 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=76800, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=855, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # mount /dev/oldboy_vg01/oldboy_lv1 /mnt/ 挂载到mnt下面

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 15M 472M 3% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/mapper/oldboy_vg01-oldboy_lv1 297M 16M 282M 6% /mnt 查看挂载成功

[root@oldboyedu ~] #

 

14.4.5.3 lvm的扩容操作

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 15M 472M 3% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/mapper/oldboy_vg01-oldboy_lv1 297M 16M 282M 6% /mnt 查看发现原先300M

[root@oldboyedu ~] # lvextend -L +50M /dev/oldboy_vg01/oldboy_lv1 扩展50M

Rounding size to boundary between physical extents: 52.00 MiB.

Size of logical volume oldboy_vg01/oldboy_lv1 changed from 300.00 MiB (75 extents) to 352.00 MiB (88 extents).

Logical volume oldboy_vg01/oldboy_lv1 successfully resized.

[root@oldboyedu ~] # xfs_growfs /dev/oldboy_vg01/oldboy_lv1 xfs系统拉伸

meta-data=/dev/mapper/oldboy_vg01-oldboy_lv1 isize=512 agcount=4, agsize=19200 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=76800, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal bsize=4096 blocks=855, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 76800 to 90112

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 15M 472M 3% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/mapper/oldboy_vg01-oldboy_lv1 349M 16M 334M 5% /mnt 发现已经增加50M

[root@oldboyedu ~] #

14.4.5.4 lvm的缩容操作

[root@oldboyedu ~] # lvreduce -L -100M /dev/oldboy_vg01/oldboy_lv1 lv350M缩减为250M

WARNING: Reducing active and open logical volume to 252.00 MiB.

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce oldboy_vg01/oldboy_lv1? [y/n]: y

Size of logical volume oldboy_vg01/oldboy_lv1 changed from 352.00 MiB (88 extents) to 252.00 MiB (63 extents).

Logical volume oldboy_vg01/oldboy_lv1 successfully resized.

[root@oldboyedu ~] # mount /dev/oldboy_vg01/oldboy_lv1 /mnt/ 这里发现缩减以后无法挂载

mount: /dev/mapper/oldboy_vg01-oldboy_lv1: can't read superblock

[root@oldboyedu ~] # mkfs.ext4 /dev/oldboy_vg01/oldboy_lv1 格式化分区为ext4类型的

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

64512 inodes, 258048 blocks

12902 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=33816576

32 block groups

8192 blocks per group, 8192 fragments per group

2016 inodes per group

Superblock backups stored on blocks:

    8193, 24577, 40961, 57345, 73729, 204801, 221185

 

Allocating group tables: done

Writing inode tables: done

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

 

[root@oldboyedu ~] # mount /dev/oldboy_vg01/oldboy_lv1 /mnt/ 重新挂载发现挂载成功

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 15M 472M 3% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/mapper/oldboy_vg01-oldboy_lv1 241M 2.1M 222M 1% /mnt 查看发现已经减少了100M

[root@oldboyedu ~] #

14.5 硬盘的分区操作

14.5.1 硬盘安装完以后不重启服务器识别新增加的硬盘

14.5.1.1 命令行识别硬盘

14.5.1.1.1 查看主机总线号

[root@oldboyedu ~] # ls /sys/class/scsi_host/

host0 host1 host2

[root@oldboyedu ~] #

14.5.1.1.2 重新扫描SCSI总线添加设备

echo "- - -" > /sys/class/scsi_host/host0/scan

echo "- - -" > /sys/class/scsi_host/host1/scan

echo "- - -" > /sys/class/scsi_host/host2/scan

14.5.1.2 脚本完成添加硬盘识别

[root@oldboyedu ~] # cat 1.sh

#!/usr/bin/bash

 

scsisum=`ls -l /sys/class/scsi_host/host*|wc -l`

 

for ((i=0;i<${scsisum};i++))

do

echo "- - -" > /sys/class/scsi_host/host${i}/scan

done

14.5.2 centos6.9硬盘的分区介绍

14.5.2.1 小于2T的硬盘分区(fdisk)

14.5.2.1.1 硬盘分区命令帮助手册的介绍

  • d    delete a partition                            删除一个分区
  • g    create a new empty GPT partition table            创建一个新的GPT分区表(默认dos)
  • l    list known partition types                    列出已知的分区类型
  • m    print this menu                            列出帮助菜单
  • n    add a new partition                            添加一个新的分区
  • p    print the partition table                        打印分区表
  • q    quit without saving changes                    退出不保存
  • t    change a partition's system id                    改变一个分区的系统ID
  • w    write table to disk and exit                    保存并且退出

14.5.2.1.2 开始分区

[root@oldboyedu scripts] # fdisk /dev/sdb 开始磁盘分区

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x12ca22cf.

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

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1): 1 开始分第一个主分区

First sector (2048-2097151, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +100M 第一个主分区分100M

Partition 1 of type Linux and of size 100 MiB is set

 

Command (m for help): n 再次创建新的主分区

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2): 2 开始分第二个分区

First sector (206848-2097151, default 206848):

Using default value 206848

Last sector, +sectors or +size{K,M,G} (206848-2097151, default 2097151): +100M 第二个主分区分100M

Partition 2 of type Linux and of size 100 MiB is set

 

Command (m for help):

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos

Disk identifier: 0x12ca22cf

 

Device Boot Start End Blocks Id System

/dev/sdb1 2048 206847 102400 83 Linux 查看分的2个主分区

/dev/sdb2 206848 411647 102400 83 Linux

 

Command (m for help):

Command (m for help):

….

继续分区…………..

14.5.2.2 主分区扩展分区和逻辑分区的概念

上图表示已经分了4个主分区了,不能再分区了,如果想分区需要将一个主分区变成扩展分区,在进行划分

这是由于mbr引导分区的时候造成的

14.5.2.2.1 什么是mbr

mbr一共有512个字节

其中446字节是引导数据使用的

64字节是分区使用的(每个分区占用16字节,一共可以划分4个主分区)

为了划出多个分区,则设计出来将一个主分区分成扩展分区和逻辑分区

  • 主分区                    3个主分区(可以挂载)
  • 扩展分区                只有一个(不可以挂载)
  • 逻辑分区                扩展分区下面可以有128个逻辑分区(可以挂载)

14.5.2.2 大于2T的硬盘分区(parted)

14.5.2.2.1 【错误】使用fdisk分区时候的错误

[root@oldboyedu ~] # fdisk /dev/sdc 开始使用fdisk分区

 

WARNING: The size of this disk is 3.2 TB (3221225472000 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID

partition table format (GPT).

………………..

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-4294967295, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294): +2500G 分大于2T的分区

Partition 1 of type Linux and of size 452 GiB is set

 

Command (m for help): wq 保存并且退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 -f 格式化分区

meta-data=/dev/sdc1 isize=512 agcount=4, agsize=29622272 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=118489088, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=57856, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

[root@oldboyedu ~] # mount /dev/sdc1 /mnt 挂载分区

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdc1 452G 33M 452G 1% /mnt 查看发现只有452G,不是我们分的2500G

 

原因:因为fdisk默认分区类型为dos系统,不支持分大于2T的分区,需要使用GPT来解决这个问题

14.5.2.2.2 parted硬盘分区手册

  • mklabel,mktable LABEL-TYPE                            创建分区表的类型
  • mkpart PART-TYPE [FS-TYPE] START END                创建主分区并且设置类型其实和终点
  • print [devices|free|list,all|NUMBER]                        查看分区信息
  • quit                                                    退出,并且会自动保存
  • rm NUMBER                                            删除分区(以ID代表)

14.5.2.2.3 【正确】parted开始分区

[root@oldboyedu ~] # parted /dev/sdc 使用parted开始分区

GNU Parted 3.1

Using /dev/sdc

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) mklabel gpt 修改分区类型为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

(parted) p 查看当前是否有分区信息

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 3221GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

 

Number Start End Size File system Name Flags

 

(parted) mkpart primary xfs 0 2500G 创建一个文件系统为xfs的并且大小为2500G的分区

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: 3221GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

 

Number Start End Size File system Name Flags

1 17.4kB 2500GB 2500GB primary

 

(parted) q 保存与退出

Information: You may need to update /etc/fstab.

 

[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分区

meta-data=/dev/sdc1 isize=512 agcount=4, agsize=152587890 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=610351558, imaxpct=5

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=298023, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # mount /dev/sdc1 /mnt/ 挂载分区

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdc1 2.3T 33M 2.3T 1% /mnt 查看创建的分区是否挂载成功并且分区大小一致

[root@oldboyedu ~] #

14.5.3 centos7.6硬盘的分区介绍

14.5.3.1 小于2T的硬盘分区

提示:参照centos6.9分区则可

14.5.3.2 大于2T的硬盘分区

14.5.3.2.1 第一种办法

提示:参照centos6.9分区则可

14.5.3.2.2 第二种办法(使用fdisk里面的g命令,修改为gpt分区)

[root@oldboyedu ~] # fdisk /dev/sdc 使用fdisk进行分区大于2T的分区

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): m 查看帮助手册

Command action

d delete a partition

g create a new empty GPT partition table

G create an IRIX (SGI) partition table

l list known partition types

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

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

 

Command (m for help): g 修改分区类型

Building a new GPT disklabel (GUID: 0EBB52E0-7B58-48A1-87B3-E1F1E4D3C198) 更新成功

 

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

Partition number (1-128, default 1):

First sector (2048-6291455966, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-6291455966, default 6291455966): +2800G 分区为2800G

Created partition 1

 

 

Command (m for help): p 查看创建分区是否成功

 

Disk /dev/sdc: 3221.2 GB, 3221225472000 bytes, 6291456000 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 label type: gpt 类型已经改为gpt

Disk identifier: 0EBB52E0-7B58-48A1-87B3-E1F1E4D3C198

 

 

# Start End Size Type Name

1 2048 5872027647 2.8T Linux filesyste

 

Command (m for help): wq 保存与退出

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

You have new mail in /var/spool/mail/root

[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 格式化分区

mkfs.xfs: /dev/sdc1 appears to contain an existing filesystem (xfs).

mkfs.xfs: Use the -f option to force overwrite.

[root@oldboyedu ~] # mkfs.xfs /dev/sdc1 -f

meta-data=/dev/sdc1 isize=512 agcount=4, agsize=183500800 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=734003200, imaxpct=5

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=358400, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

[root@oldboyedu ~] # mount /dev/sdc1 /mnt 挂载分区

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdc1 2.8T 33M 2.8T 1% /mnt 挂载成功,并且分区大小为2800G

[root@oldboyedu ~] #

14.6 硬盘格式化

14.6.1 文件系统是什么

存储数据的一种机制

14.6.2 硬盘格式化常用的命令

  • mkfs.ext4                                    centos6.9硬盘格式化命令
  • mkfs -t ext4                                centos6.9硬盘格式化命令
  • mkfs.xfs                                    centos7.6硬盘格式化命令
  • mkfs -t xfs                                centos7.6硬盘格式化命令

14.6.3 硬盘格式化常见类型和不同

14.6.3.1 类型有

windows    常见的有FAT32格式和NTFS格式

linux    常见的有xfs格式和ext3,ext4格式

14.6.3.2 不同点

windows

FAT32格式的只能存储小于等于4G的文件

NTFS默认是能存储无限大的数据

linux

xfs格式化(创建文件系统)速度更快,存储效率更快

ext4格式化(创建文件系统)速度较慢,存储效率也慢

 

14.7 硬盘挂载与卸载

14.7.1 挂载常用的参数

  • rw                                        拥有读写权限
  • ro                                        只拥有读权限
  • suid                                        允许获取默认支持特殊权限位(suid)
  • nosuid                                    不允许获取默认支持特殊权限位(suid)
  • exec                                        允许文件进行执行
  • noexec                                    不允许文件进行执行
  • async                                    异步存储数据(安全性低,效率高)
  • sync                                        同步存储数据(安全性高,效率低)
  • noauto                                    当使用mount-a的时候默认不自动更新 挂载
  • auto                                        当使用mount-a的时候默认自动更新 挂载
  • user                                        允许普通用户挂载
  • nouser                                    普通用户无法挂载

14.7.2 临时挂载

14.7.2.1 默认临时挂载

[root@oldboyedu ~] # mount /dev/sdb1 /mnt/ 默认挂载

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 5.2G 94G 6% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdb1 3.9M 53K 3.5M 2% /mnt

[root@oldboyedu ~] #

14.7.2.2 拥有suid和nosuid时候的不同效果

14.7.2.2.1 拥有suid

[root@oldboyedu ~] # mount -o suid /dev/sdb1 /mnt/ 挂载有suid的设备文件

[root@oldboyedu ~] #

 

[root@oldboyedu mnt] # ls

cat lost+found

[root@oldboyedu mnt] # chmod u+s cat 增加suid权限

[root@oldboyedu mnt] # ll cat

-rwsr-xr-x 1 root root 54160 Oct 5 12:13 cat

 

[oldboy01@oldboyedu ~] $ cat /etc/shadow 用系统自己设置的cat无法查看没有权限的密码文件

cat: /etc/shadow: Permission denied

[oldboy01@oldboyedu ~] $ /mnt/cat /etc/shadow 用自己保存的cat可以成功查看密码文件

root:$6$urUU5dR4$ORJJcLWsmQ1drz.ggOhv9ko9EVRfelsBGibs7vL/4EkUOvZGejq3pved6qP0.txGFWSA82bhVB5ueEZ.JcRzZ0:18150:0:99999:7:::

bin:*:17834:0:99999:7:::

daemon:*:17834:0:99999:7:::

adm:*:17834:0:99999:7:::

lp:*:17834:0:99999:7:::

sync:*:17834:0:99999:7:::

shutdown:*:17834:0:99999:7:::

14.7.2.2.2 拥有nosuid的时候

[root@oldboyedu ~] # mount -o nosuid /dev/sdb1 /mnt/ 挂载有nosuid参数的时候

 

[root@oldboyedu mnt] # ls

cat lost+found

[root@oldboyedu mnt] # chmod u+s cat

[root@oldboyedu mnt] # ll cat 增加suid权限

-rwsr-xr-x 1 root root 54160 Oct 5 12:13 cat

 

[oldboy01@oldboyedu ~] $ cat /etc/shadow 普通用户查看密码文件发现权限拒绝

cat: /etc/shadow: Permission denied

[oldboy01@oldboyedu ~] $ /mnt/cat /etc/shadow 拥有属主root权限的命令也无法打开

/mnt/cat: /etc/shadow: Permission denied

[oldboy01@oldboyedu ~] $

14.7.2.3 拥有exec和noexec时候的不同效果

14.7.2.3.1 拥有exec

[root@oldboyedu ~] # mount -o exec /dev/sdb1 /mnt/ 挂载设备文件的参数exec的时候

[root@oldboyedu ~] # cd /mnt/

[root@oldboyedu mnt] # ls

cat lost+found

[root@oldboyedu mnt] # echo "echo oldboy" > 1.sh

[root@oldboyedu mnt] # sh 1.sh 执行脚本发现可以成功执行

oldboy

[root@oldboyedu mnt] #

14.7.2.3.2 拥有noexec

[root@oldboyedu mnt] # mount -o noexec /dev/sdb1 /mnt/ 挂载设备文件的参数noexec

 

[root@oldboyedu mnt] # sh 1.sh 发现挂载上去还可以正常的执行挂载目录里面的脚本,不正常

oldboy

[root@oldboyedu mnt] # rm -rf 1.sh 删除以前的脚本

You have new mail in /var/spool/mail/root

[root@oldboyedu mnt] # echo "echo oldboy" > 1.sh 再次重新创建

[root@oldboyedu mnt] # ./1.sh 执行发现执行失败

-bash: ./1.sh: Permission denied

[root@oldboyedu mnt]

结论:在挂载一个里面有数据的目录的时候,里面有的文件不会因为挂载目录参数的改变而发生改变,只对新创建的有效果

14.7.2.4 拥有async和sync时候的不同效果

14.7.2.4.1 拥有async的时候

async异步存储数据:先存储到内存在从内存放入硬盘

特点:存储数据快,安全性比较低

14.7.2.4.2 拥有sync的时候

sync 同步存储数据:直接将数据存储到硬盘中

特点:存储数据慢,安全性比较高

14.7.2.5 拥有rw和ro时候的不同效果

14.7.2.5.1 拥有rw的时候

[root@oldboyedu mnt] # mount -o rw /dev/sdb1 /mnt/ 挂载设备文件参数为rw

[root@oldboyedu mnt] # touch aa.txt 可以创建文件aa.txt

[root@oldboyedu mnt] #

14.7.2.5.2 拥有ro的时候

[root@oldboyedu mnt] # mount -o remount,ro /dev/sdb1 /mnt 挂载设备文件参数为ro

[root@oldboyedu mnt] # touch bb.txt 创建bb.txt失败,发现为只读无法创建

touch: cannot touch 'bb.txt': Read-only file system

[root@oldboyedu mnt] #

14.7.2.6 拥有user和nouser的时候不同效果

14.7.2.6.1 拥有nouser的时候

[root@oldboyedu ~] # mount -o nouser /dev/sdb1 /mnt/ root用户使用nouser参数挂载的时候

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdb1 2.0M 37K 1.7M 3% /mnt 挂载成功

[root@oldboyedu ~] # su - oldboy01 切换为oldboy01用户

Last login: Sat Oct 5 12:24:09 CST 2019 on pts/1

[oldboy01@oldboyedu ~] $ mount /dev/sdb1 /aa 挂载的时候发现挂载失败,提示只有root用户才可以挂载

mount: only root can do that

[oldboy01@oldboyedu ~] $

14.7.2.6.2 拥有user的时候

普通用户可以正常的使用mount命令

14.7.2.7 拥有auto和noauto的时候不同效果

14.7.2.7.1 拥有auto的时候

[root@oldboyedu ~] # umount /mnt 卸载mnt

[root@oldboyedu ~] # umount /mnt

umount: /mnt: not mounted

[root@oldboyedu ~] # vim /etc/fstab

UUID=8e7004ef-83c2-4b8d-b9db-b85768271eb2 swap swap defaults 0 0

#UUID=2018-11-25-23-54-16-00 /mnt iso9660 defaults 0 0

/dev/sdb1 /mnt ext4 auto 0 0 添加挂载的设备,参数为auto

 

[root@oldboyedu ~] # mount -a 重新加载

[root@oldboyedu ~] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdb1 2.0M 37K 1.7M 3% /mnt 加载成功

[root@oldboyedu ~] #

14.7.2.7.2 拥有noauto的时候

[root@oldboyedu ~] # umount /mnt 卸载设备

[root@oldboyedu ~] # umount /mnt

umount: /mnt: not mounted

[root@oldboyedu ~] # vim /etc/fstab

UUID=8e7004ef-83c2-4b8d-b9db-b85768271eb2 swap swap defaults 0 0

#UUID=2018-11-25-23-54-16-00 /mnt iso9660 defaults 0 0

/dev/sdb1 /mnt ext4 noauto 0 0 挂载设备,并且参数为noauto

 

[root@oldboyedu ~] # mount -a 重新加载

[root@oldboyedu ~] # df -h 发现没有加载上去mnt目录

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

[root@oldboyedu ~] #

 

 

 

14.7.3 永久挂载

14.7.3.1 /etc/fatab来进行挂载

[root@oldboyedu mnt] # blkid /dev/sdb1

/dev/sdb1: UUID="4752496d-83de-4797-ba45-6027b40b4f26" TYPE="xfs "

[root@oldboyedu mnt] # cat /etc/fstab

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=27114df9-3f54-4b94-acb7-0890b452e99f / xfs defaults 0 0

UUID=4260ed75-aad2-4389-b24a-2be6362c2597 /boot xfs defaults 0 0

UUID=8e7004ef-83c2-4b8d-b9db-b85768271eb2 swap swap defaults 0 0

UUID=4752496d-83de-4797-ba45-6027b40b4f26 /mnt xfs defaults 0 0

通过UUID来挂载

/dev/sdb1 /mnt xfs defaults 0 0

通过设备名称来挂载

[root@oldboyedu mnt] #

14.7.3.2 /etc/rc.local里面挂载

[root@oldboyedu mnt] # cat /etc/rc.local

#!/bin/bash

/dev/sdb1 /mnt xfs defaults 0 0

通过设备名称来挂载

[root@oldboyedu mnt] #

14.7.4 硬盘挂载与卸载常见的问题

14.7.4.1 卸载硬盘分区失败

14.7.4.1.1 问题

卸载的时候提示该文件被占用

14.7.4.1.2 产生的原因

1.卸载的时候卸载的目录正好是自己当前所在的目录

2.卸载的时候该文件被其他进程占用

14.7.4.1.2 解决办法

1.退出当前的目录在卸载

2.使用懒惰卸载法umount -lf

14.7.5 硬盘卸载

14.7.5.1 普通卸载

[root@oldboyedu mnt] # df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

/dev/sdb1 3.9M 72K 3.5M 3% /mnt 挂载成功

[root@oldboyedu mnt] # cd

[root@oldboyedu ~] # umount /mnt 卸载分区

[root@oldboyedu ~] # df -h'

> ^C

[root@oldboyedu ~] # df -h 卸载成功

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

[root@oldboyedu ~] #

14.7.5.2 懒惰卸载

[root@oldboyedu mnt] # umount -l /mnt 懒惰卸载/dev/sdb1

You have new mail in /var/spool/mail/root

[root@oldboyedu mnt] # df -h 查看发现已经卸载成功

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 99G 6.2G 93G 7% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 197M 160M 37M 82% /boot

tmpfs 98M 12K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

[root@oldboyedu mnt] #

14.8 常见有关分区之间的企业案例

14.8.1 根分区遭到破坏的时候

14.8.1.1 问题

上述出现保存无法写入的原因是什么?

14.8.1.2 原因

根分区遭到破坏造成的

14.8.1.3 解决办法

重新给/加载rw权限

[root@oldboyedu ~] # mount -o remount,rw / 上述方法使用的时候会报找不到此UUID

mount: can't find UUID=27104df9-3f54-4b94-acb7-0890b452e99f

[root@oldboyedu ~] # mount -o remount rw / 下面的方法可以成功的解决此问题

[root@oldboyedu ~] #

[root@oldboyedu ~] # cat /etc/rc.local 发现aaa已经添加成功

#!/bin/bash

 

aaa

[root@oldboyedu ~] #

14.8.2 系统进不去的时候

14.8.2.1 问题

系统出去启动失败,进不去页面

14.8.2.2 原因

分区配置出现问题造成的

14.8.2.3 解决办法

14.8.2.3.1 输入root密码

14.8.2.3.2 sdb1改为sdb2

 

14.8.3 磁盘空间不足的时候怎么解决

14.8.3.1 inode占满的情况

14.8.3.1.1 原因

inode占满的情况下会造成磁盘空间的不足,是因为生成的小文件太多造成的

14.8.3.1.2 解决办法

使用find命令查找出来小文件用xargs删除则解决

14.8.3.2 block占满的情况

14.8.3.2.1 原因

有很多的大文件占用空间比较大造成的

14.8.3.2.2 解决办法

rm -rf bigsize

14.8.3.3.3 找出大文件的方法(补充)

利用find命令查找大文件

利用du -sh|sort -hr 来查找大文件

14.8.3.3.4 如何将文件彻底删除(补充)

查看硬链接,使用find命令将硬链接全部删除

将大文件里面的内容清空

将大文件占用的进程全部杀死

14.9 swap交换空间的改变

14.9.1 实现硬盘中那些空间给swap空间使用的

[root@oldboyedu mnt] # dd if=/dev/zero of=/tmp/1G bs=100M count=10

从黑洞中拿出来1G交给/tmp/1G使用

10+0 records in

10+0 records out

1048576000 bytes (1.0 GB) copied, 3.58782 s, 292 MB/s

[root@oldboyedu mnt] # ll -h /tmp/1G

-rw-r--r-- 1 root root 1000M Oct 5 15:26 /tmp/1G

[root@oldboyedu mnt] #

14.9.2 标记给swap空间

[root@oldboyedu mnt] # mkswap /tmp/1G 标记给swap空间

Setting up swapspace version 1, size = 1023996 KiB

no label, UUID=8eea78e2-8f88-4c77-89a4-9910047d1983

[root@oldboyedu mnt] #

14.9.3 /tmp/1G交给swap空间使用

[root@oldboyedu mnt] # free -h

total used free shared buff/cache available

Mem: 972M 343M 154M 10M 473M 436M

Swap: 1.5G 0B 1.5G 空闲1.5G

You have new mail in /var/spool/mail/root

[root@oldboyedu mnt] # swap

swaplabel swapoff swapon

[root@oldboyedu mnt] # swapon /tmp/1G 增加1G

swapon: /tmp/1G: insecure permissions 0644, 0600 suggested.

[root@oldboyedu mnt] # free -h

total used free shared buff/cache available

Mem: 972M 344M 153M 10M 474M 435M

Swap: 2.5G 0B 2.5G 空闲2.5G

[root@oldboyedu mnt] #

14.9.4 /tmp/1G取消给swap空间的使用

[root@oldboyedu mnt] # free -h

total used free shared buff/cache available

Mem: 972M 344M 153M 10M 474M 435M

Swap: 2.5G 0B 2.5G 空闲2.5G

[root@oldboyedu mnt] # swapoff /tmp/1G 增加1G

You have new mail in /var/spool/mail/root

[root@oldboyedu mnt] # free -h

total used free shared buff/cache available

Mem: 972M 344M 154M 10M 474M 436M

Swap: 1.5G 0B 1.5G 空闲1.5G

[root@oldboyedu mnt] #

posted @ 2019-11-30 15:49  HXX-LYX  阅读(460)  评论(0编辑  收藏  举报