Day22
作者:方维超
归档:课堂笔记
时间:2019/3/29
第四章:分区知识
命令:
dd 创建虚拟的文件系统
image.png查看分区系统
[root@CentOS-F~]# cat /proc/partitions
major minor #blocks name
11 0 4481024 sr0
8 0 20971520 sda
8 1 204800 sda1
8 2 2048000 sda2
8 3 18717696 sda3
8 16 524288 sdb
8 17 9749 sdb1
8 18 9216 sdb2
8 19 10240 sdb3
8 20 9216 sdb4
8 21 10240 sdb5
分区完后,必须执行partprobe /devsdb (不需要重启生效),将分区信息通知内核
partad 分区
image.png image.png image.png[root@oldboyedu ~]# parted /dev/sdb #交互式开始分区
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
(parted) mklabel gpt #修改分区格式为gpt
Warning: The existing disk label on /dev/sdb 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/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt #修改结果
(parted) mkpart primary 0 480 #创建第一个主分区480M。
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore #忽略提示。
(parted) mkpart primary 481 580 #创建第二个主分区100M。
Warning: You requested a partition from 481MB to 580MB (sectors 939453..1132812).
The closest location we can manage is 481MB to 481MB (sectors 940031..940031).
Is this still acceptable to you?
Yes/No? Y
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I #忽略提示。
(parted) mkpart logic 581 600 #创建一个20M逻辑分区。
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 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
3 481MB 481MB 512B primary
2 481MB 580MB 98.6MB primary
4 581MB 600MB 18.9MB logic
(parted) rm 4 #删除
(parted) p
修改分区格式:
(parted) mklabel msdos
[root@oldboyedu ~]# 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.
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-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +100M
Partition 1 of type Linux and of size 100 MiB is set
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: 0x000006b6
Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux
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 (206848-2097151, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-2097151, default 2097151): +100M
Partition 2 of type Linux and of size 100 MiB is set
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: 0x000006b6
Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux
/dev/sdb2 206848 411647 102400 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@oldboyedu ~]# ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16 Mar 29 11:31 /dev/sdb
brw-rw---- 1 root disk 8, 17 Mar 29 11:31 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Mar 29 11:31 /dev/sdb2
格式化****ext4****文件系统,其实关键就是生成一定数量的****inode****和****block****。
[root@oldboyedu ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-201
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 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
挂载
[root@oldboyedu ~]# mount -t ext4 /dev/sdb1 /mnt #挂载到/mnt
[root@oldboyedu ~]# df -h #查看挂载结果 Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.9G 18G 10% /
devtmpfs 980M 5.0M 975M 1% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 18M 973M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 253M 136M 118M 54% /boot
tmpfs 199M 0 199M 0% /run/user/0
tmpfs 199M 0 199M 0% /run/user/1000
/dev/sdb1 93M 1.6M 85M 2% /mnt #<====已挂载。 [root@oldboyedu ~]# cat /proc/mounts #查看挂载结果 rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/sda3 / xfs rw,relatime,attr2,inode64,noquota 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=19277 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700,uid=1000,gid=1000 0 0
/dev/sdb1 /mnt ext4 rw,relatime,data=ordered 0 0 #<====已挂载。 [root@oldboyedu ~]# touch /mnt/oldboy
[root@oldboyedu ~]# ls /mnt
lost+found oldboy
[root@CentOS-F/]# blkid
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="193c807e-09b3-4b5f-a7b3-77ed8ca432e9" TYPE="xfs"
/dev/sda2: UUID="0ea8c5c5-acd0-4d2d-aa24-80e6f428e9c9" TYPE="swap"
/dev/sda3: UUID="2fdc9559-7c94-43f8-86ff-d09f09e4ac55" TYPE="xfs"
/dev/sdb1: UUID="a5c24e84-520e-4971-b465-59e2f0cf3d3a" TYPE="ext3" PARTLABEL="primary" PARTUUID="4e82b1c6-dfb2-45ba-9d8c-6e6331f9ac2c"
查看文件系统(****ext****格式)内部细节
[root@CentOS-F/]# dumpe2fs /dev/sdb1
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: /data
Filesystem UUID: a5c24e84-520e-4971-b465-59e2f0cf3d3a
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 2448
Block count: 9748
Reserved block count: 487
Free blocks: 8314
Free inodes: 2436
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 38
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 1224
Inode blocks per group: 153
Filesystem created: Fri Mar 29 00:28:35 2019
Last mount time: Fri Mar 29 11:58:38 2019
Last write time: Fri Mar 29 11:58:38 2019
Mount count: 4
Maximum mount count: -1
Last checked: Fri Mar 29 00:28:35 2019
Check interval: 0 (<none>)
Lifetime writes: 32 kB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: ae793736-7f96-40c2-a720-7db1bd37b99d
Journal backup: inode blocks
Journal features: (none)
Journal size: 1029k
Journal length: 1024
Journal sequence: 0x00000009
Journal start: 0
Group 0: (Blocks 1-8192)
Primary superblock at 1, Group descriptors at 2-2
Reserved GDT blocks at 3-40
Block bitmap at 41 (+40), Inode bitmap at 42 (+41)
Inode table at 43-195 (+42)
6954 free blocks, 1212 free inodes, 2 directories
Free blocks: 1239-8192
Free inodes: 13-1224
Group 1: (Blocks 8193-9747)
Backup superblock at 8193, Group descriptors at 8194-8194
Reserved GDT blocks at 8195-8232
Block bitmap at 8233 (+40), Inode bitmap at 8234 (+41)
Inode table at 8235-8387 (+42)
1360 free blocks, 1224 free inodes, 0 directories
Free blocks: 8388-9747
Free inodes: 1225-2448
分区知识:
(1)什么是分区,为什么要分区?
磁盘分区相当于给磁盘打隔断。**
(2)磁盘和分区在Linux里的命名。**
IDE:hda hdb
SCSI:sda sdb
分区数字表示:sda1 sda2 sda3
(3)磁盘分区类型和特点:**
1.主分区(primary)p
系统中必须要存在的分区,系统盘选择主分区安装
数字编号只能是1-4. sda1 sda2 sda3 sda4
主分区最多4个,最少1个
2.扩展分区(extend)e
相当于一个独立的小磁盘,独立的分区表,不能独立存在。
有独立的分区表
不能独立存在,既不能直接存放数据
要想存放数据,必须在扩展分区上建立逻辑分区才能存放数据
会占用主分区的编号(主分区+扩展分区)之和最多4个
扩展分区可以没有,最多只能有1个
3.逻辑分区(logic)l
数字编号只能从5开始
存放于扩展分区之上
存放任意普通数据**
(4)磁盘分区工作原理:**
磁盘是按柱面分区的。
磁盘分区登记的地点:磁盘分区表
作用:用来存放分区结果信息的。
位置:0磁道0磁头1扇区(512字节)
占用1扇区的前446字节(存放系统引导信息的)的64字节(分区表),剩下两个字节是分区结束标志。
磁盘分区表的容量是有限的,64字节,一个分区固定占16字节。64/16=4分区(主分区+扩展分区)(5)磁盘分区实战**
磁盘分区常用命令 fdisk ,修改MBR分区表,MBR格式。
缺陷:被修改的磁盘大小不能大于2T.
磁盘分区其他命令 parted ,gpt分区格式,既能修改小于2T也能修改大于2T的磁盘
小于2T就用fdisk
大于2T就用parted
(6)生产场景分区方案:4种。参考前面课程。**
获得使用的磁盘过程===买房入住生活的过程
磁盘:房子
RAID:多套房子打通
分区:隔断/几居室/卧室/卫生间/厨房
文件系统:装修风格/中式/欧式/美式(磁盘没有文件系统无法放数据)
格式化过程:装修的过程
挂载:开门开窗开始住人
磁盘管理:生活中收拾屋子,打扫卫生,修修补补等。
1、文件系统:(什么是文件系统?)**
是计算机存储和组织数据的方法或机制。
2、为什么需要文件系统?**
磁盘、物理介质、磁粒子物理元素。硬件需要软件驱动使用,磁盘需要文件系统驱动。
文件系统实现通过洗盘管理规划、存取数据
没有文件系统计算机没办法放数据
3、文件系统有哪些种类?**
windows: NTFS、fat32、msdos
Linux:ext2、ext3(C5)、ect4(C6)、Xfs(C7)、btrfs
4、创建文件系统实践。**
5、文件系统原理(ext文件系统)**
6、企业中如何选择文件系统?**
7、如何优化文件系统?**
1、文件删除原理
静态文件:没有程序和进程正在执行,干掉所有硬链接和它本身,i_link=0
动态文件:有程序或进程正在运行,取消掉所有,i_count=0
2、no space left on device
磁盘满了。df -i检查,df -h检查,可能是定时任务执行时未输入到黑洞设备,导致给root发送邮件,邮件服务默认是关闭的,就会在临时目录下产生大量的小文件。
3、swap作用,内存不够的时候,用来充当内存,一般是内存的1.5倍。大于8G给8G。 将来JAVA服务,内存泄漏, swap就会占用,操作系统性能下降。 [root@CentOS-F/]# free -m**
total used free shared buff/cache available
Mem: 1819 100 1561 9 158 1550
Swap: 1999 0 1999
<今天一堆码,大家看着也很烦吧,抱歉了啊>
网友评论