Day 22 课堂笔记

第16章 Linux磁盘管理体系

满足本能需求,比满足意识需求更重要

分区知识:

(1)什么是分区,为什么要分区?

(2)磁盘和分区在Linux里的命名。

(3)磁盘分区类型和特点:

(4)磁盘分区工作原理:

(5)磁盘分区实战

(6)生产场景分区方案:4种。参考前面课程。

1.parted分区——传统的MBR(Master boot Re

2.文件系统

什么是文件系统?

为什么需要文件系统?

创建文件系统实践

dumpe2fs /dev/sdb1

企业中如何选择文件系统

企业里如何优化文件系统



格式化分区:

1.创建两个分区

2.查看/dev/sdb下分区  (ls -l /dev/sdb*)

3.mkfs -t ext4 /dev/sdb1 ##格式化ext4文件系统(生成一定数量的Indoe和Block)

4.mount -t exxt4 /dev/sdb1/mnt ###挂载到mnt      ###(df -h查看挂载)

5.cat /proc/mounts ###查看挂载结果

6.touch /mnt/woshi  ##测试(在mnt下创建一个文件)ls /mnt 查看

7.umount /mnt ###卸载mnt    df -h (查看成功与否)

[root@keyan

    ~]# mount /dev/sdb2/opt  ###没有格式化不能挂载

mount: can't find /dev/sdb2/opt in /etc/fstab

8.mkfs.xfs /dev/sdb2  ###格式化xfs文件系统

9.mount -t xfs /dev/sdb2 /opt ###挂载到/opt下(df -h查看)

10.cat /etc/fstab ##查看开机自动挂载    (编辑vim  实现开机挂载)


第一列 设备 /dev/sdb2

第二列    挂载点        /opt

第三列  文件系统类型    xfs

第四列  默认挂载类型    defaults

第五烈    是否备份

第六列    是否开机设备挂载

11.blkid 列出当前系统中已挂载的文件类型  (tail -1 /etc/fstab查看开机自动挂载的最后一个)  ###df -h主分区Block 大小  df -ih  主分区Inode大小

12.dumpe2fs /dev/sdb1  ###查看ext文件内部细节

dumpe2fs /dev/sdb1|egrep -i "size" ###在文件内部细节过滤出有size关键字的

备注:放入/etc/rc.local实现自动挂载,但不推荐。

/sbin/mount -t xfs /dev/sdb2 /opt

13.mkfs -t ext4 -b 4096 -I 512 /dev/sdb1  ###指定block和inode大小(这里指定大小4096和inode512)    dumpe2fs /dev/sdb1|egrep -i "size"  查看更改

14. free -m 查看swap 大小空间

15.增加swap

partprobe /dev/sdb  ####更新/dev/sdb

mkswap /dev/sdb4    ###把/dev/sdb4创建swap

free -m  ###查看大小

Command action

  a  toggle a bootable flag

  b  edit bsd disklabel

  c  toggle the dos compatibility flag

  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

  u  change display/entry units

  v  verify the partition table

  w  write table to disk and exit

  x  extra functionality (experts only)

业:如何用一条fdisk命令回车完成上述分区。

1.parted分区——传统的MBR(Master boot Re

优势:创建文件系统

需求:Raid5大小6T ,已装系统,额外添加4块2T盘

硬盘总分区大小:6。2T

/data0    4.8T

/data1    1T

                4T  (无需格式化,做DRBD+Hearbeat+MySQL高可用集群)


2.文件系统

什么是文件系统?

计算机存储和组织数据的方法或机制。

为什么需要文件系统?

磁盘、物理介质、磁粒子物理元素。硬件是需要软件驱动使用,磁盘需要文件系统驱动。

文件系统实现通过磁盘管理规划、存取数据。

文件系统有哪些种类?

Windows、NTFS、fat32、msdos

Linux:ext2、ext3(C5)、ext(C6)、Xfs(C7)

创建文件系统实践

挂载:

[root@keyan~]# fdisk /dev/sdb

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): n

Partition number (1-128, default 1):

First sector (34-2097118, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-2097118, default 2097118): +100

First sector (34-2097118, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-2097118, default 2097118): +150M

Created partition 1

Command (m for help): p

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: gpt

Disk identifier: 78F96531-A47F-4A7A-8732-E481A2BECDBB

#        Start          End    Size  Type            Name

1        2048      309247    150M  Linux filesyste

Command (m for help): n

Partition number (2-128, default 2):

First sector (34-2097118, default 309248):

Last sector, +sectors or +size{K,M,G,T,P} (309248-2097118, default 2097118): +150m 

Created partition 2

Command (m for help): n

Partition number (3-128, default 3):

First sector (34-2097118, default 616448):

Last sector, +sectors or +size{K,M,G,T,P} (616448-2097118, default 2097118): +150M

Created partition 3

Command (m for help): p

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: gpt

Disk identifier: 78F96531-A47F-4A7A-8732-E481A2BECDBB

#        Start          End    Size  Type            Name

1        2048      309247    150M  Linux filesyste

2      309248      616447    150M  Linux filesyste

3      616448      923647    150M  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@keyan~]# ls -l /dev/sdb*

brw-rw---- 1 root disk 8, 16 Mar 29 11:47 /dev/sdb

brw-rw---- 1 root disk 8, 17 Mar 29 11:47 /dev/sdb1

brw-rw---- 1 root disk 8, 18 Mar 29 11:47 /dev/sdb2

brw-rw---- 1 root disk 8, 19 Mar 29 11:47 /dev/sdb3

[root@keyan~]# mkfs -t ext4 /dev/sdb1  ======

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

38456 inodes, 153600 blocks

7680 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=33816576

19 block groups

8192 blocks per group, 8192 fragments per group

2024 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

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

[root@keyan~]# mount -t ext4 /dev/sdb1 /mnt

[root@keyan~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G  2.1G  17G  11% /

devtmpfs        477M    0  477M  0% /dev

tmpfs          488M    0  488M  0% /dev/shm

tmpfs          488M  32M  456M  7% /run

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

/dev/sda1      197M  102M  95M  52% /boot

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

/dev/sdb1      142M  1.6M  130M  2% /mnt

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

[root@keyan~]# touch /mnt/woshi

[root@keyan~]# cat /mnt

cat: /mnt: Is a directory

[root@keyan~]# ls         

1  abc.txt  data  oldboy  oldboy.txt  sudo  woshi

[root@keyan~]# ls /mnt

lost+found  woshi

方法二:

[root@oldboyedu ~]# mount -t xfs /dev/sdb2 /opt

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

[root@oldboyedu ~]# df -h|grep opt

/dev/sdb2        97M  5.3M   92M   6% /opt

[root@oldboyedu ~]# touch /opt/oldgirl

[root@oldboyedu ~]# ls /opt

oldgirl

如何开机自动挂载?

/etc/fstab 开机自动挂载

几列? 6列

UUID=25027b5a-f7c1-4c54-af0d-52f48755ff5a /                      xfs    defaults       

UUID=dd5867b8-2d24-4526-9c88-8ce8db3175cb /boot                  xfs    defaults       

UUID=1f30dc74-c1df-411e-8e78-b8a3d005e5fd swap

dumpe2fs /dev/sdb1

fsck 磁盘检查和修复

swap作用,内存不够充当内存

文件系统原理(ext文件系统)、文件系统特点

企业中如何选择文件系统

企业里如何优化文件系统

[root@keyan~]#fdisk /dev/sdb

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.警告:fdisk GPT支持目前是新的,因此还处于试验阶段。使用时请自行决定。

Welcome to fdisk (util-linux 2.23.2).欢迎来到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):  p      命令(m寻求帮助):

实操:

1.创建分区:

2.m

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

  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  ###更改一个系统分区Id

  u  change display/entry units

  v  verify the partition table

  w  write table to disk and exit

  x  extra functionality (experts only)

Command (m for help):t

Partition number (1-3, default 3): 2

Hex code (type L to list all codes): L


Hex code (type L to list all codes):8e  ###修改分区类型Linux为Linux LVM

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

Command (m for help): p     

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: 0xdd380bb6

  Device Boot      Start        End      Blocks  Id  System

/dev/sdb1            2048      309247      153600  83  Linux

/dev/sdb2          309248      616447      153600  8e  Linux LVM  ###以修改完毕

/dev/sdb3          616448      923647      153600  83  Linux

[root@keyan                                                             

~]#parted /dev/sdc

GNU Parted 3.1

Using /dev/sdc

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

(parted)p           

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 1074MB

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

Partition Table: gpt  #####mktable gpt 修改分区格式

Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted)mkpart primary 0 480        ###创建第一个主分区480M

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: 1074MB

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

Partition Table: gpt

Disk Flags:

Number  Start  End    Size  File system  Name    Flags

1      17.4kB  480MB  480MB              primary

(parted)mkpart primary 481 580          ###创建第二个自主分区100M

(parted) p                                                               

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 1074MB

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

Partition Table: gpt

Disk Flags:

Number  Start  End    Size    File system  Name    Flags

1      17.4kB  480MB  480MB                primary

2      481MB  580MB  98.6MB              primary

(parted)mkpart logic 581 600  ###创建一个20M逻辑分区

(parted)p

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 1074MB

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

Partition Table: gpt

Disk Flags:

Number  Start  End    Size    File system  Name    Flags

1      17.4kB  480MB  480MB                primary

2      481MB  580MB  98.6MB              primary

3      581MB  600MB  18.9MB              logic

(parted)rm 3  ###删除逻辑分区

(parted) p                                                               

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 1074MB

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

Partition Table: gpt

Disk Flags:

Number  Start  End    Size    File system  Name    Flags

1      17.4kB  480MB  480MB                primary

2      481MB  580MB  98.6MB              primary

(parted)mklabel msdos  ###修改分区格式为msdos

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? Y                                                               

(parted) p                                                               

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdc: 1074MB

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

Partition Table:msdos  ###分区格式为msdos

Disk Flags:

Number  Start  End  Size  Type  File system  Flags

[root@keyan

~]# ls -l /dev/sd*    ###查看挂载情况

brw-rw---- 1 root disk 8,  0 Mar 30 23:36 /dev/sda

brw-rw---- 1 root disk 8,  1 Mar 30 23:36 /dev/sda1

brw-rw---- 1 root disk 8,  2 Mar 30 23:36 /dev/sda2

brw-rw---- 1 root disk 8,  3 Mar 30 23:36 /dev/sda3

brw-rw---- 1 root disk 8, 16 Mar 30 23:43 /dev/sdb

brw-rw---- 1 root disk 8, 32 Mar 31 00:18 /dev/sdc

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容