fdisk补充
fdisk-Partition table manipulator for Linux
Linux 下最常用的工具,一般是装完系统后进行分区。装系统之前的分区
多数都是系统ISO里面的工具分,或者Raid里分小磁盘
fdisk 只能root权限用户使用
fdisk 适合于对装系统后的剩余空间进行分区,例如:安装系统时没有全部分区,或者安装系统后添加新的磁盘
fdisk 支持MBR分区表(2T以内)
fdisk实质
用fdisk分区的实质,就是修改0磁头0磁道1扇区的前446字节之后留下的64字节分区表信息。
可以使用fdisk分区的的磁盘大小必须小于2T,如果大于2T,分区就用parted(GPT分区)
查看分区表
[root@oldboyedu ~]# 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 1048576 sdb
8 17 102400 sdb1
8 18 102400 sdb2
partprobe 将分区信息通知内核
parted 分区
简述:parted 是一个磁盘分区工具
他比fdisk更加灵活,功能也更加丰富,同时还支持GUID分区表(GUID Partition Table),这在IA64平台上管理磁盘时非常有用,它同时支持交互模式和非交互模式。他除了能够进行扥去的添加,删除常见操作外,还可以移动分区,制作文件系统,调整文件系统大小,复制文件系统。
需求:RAID 5大小6T,已经装了系统额外添加四快盘
硬盘分区大小: 6.2T
/data0 4.8T
/data1 1T
4G (无需格式化,作为DRBD+Hearbeat+MySQL高可用集群)
[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 #查看命令帮助
align-check TYPE N check partition N for TYPE(min|opt)
alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available
devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
(parted) mklabel 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
Disk Flags:
Number Start End Size File system Name Flags
(parted)
(parted)
(parted) mkpart primary 0 100 #创建第一个主分区
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(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 100MB 100MB primary #创建的第一个分区
(parted) mkpart primary 481 580 #创建第二个分区
(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 100MB 100MB primary
2 481MB 580MB 98.6MB primary
(parted) mkpart lodic 581 600 #创建逻辑分区 ,单位M
(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 100MB 100MB primary
2 481MB 580MB 98.6MB primary
3 581MB 600MB 18.9MB lodic
(parted) rm 3 #删除分区 3
(parted) rm 2 #删除分区 2
(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 100MB 100MB primary
(parted)
一键分区
parted /dev/sdb mkladel gpt
parted /dev/sdb mkpart primary 0 480 I
parted /dev/sdb mkpart primary 481 580 I
parted /dev/sdb p
问题需要:刚买的服务器 4块2T 刚买,要做RAID 5 ,装系统怎么搞
- raid制作视频,raid里可以支持raid5后,允许你把6T分成虚拟磁盘
200G分成第一个虚拟磁盘剩下的不分留着装系统 - 装系统,系统镜像支持GPT格式分区,很隐蔽
- 引导分区,进入然后用parted分区
文件系统:
什么是文件系统
计算机存储和组织数据的方法或机制。落地式一个软件
为什么需要文件系统
磁盘属于物理介质、物理元素。硬件需要软件驱动使用,磁盘需要文件系统驱动。
文件系统实现通过磁盘管理规划、存储数据
文件系统有哪些类型?
Windows :NTFS fat32 msdos
Linux: ext2、ext3(c5)、ext4(c6)、Xfs(c7)、btrfs
创建文件系统实践
parted 中更改格式
[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) mklabel msdos
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? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) q
Information: You may need to update /etc/fstab.
创建文件系统核心(格式化ext4)其实关键就是生成一定数量的Inode和block
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
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 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.9G 17G 11% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 93M 1.6M 85M 2% /mnt
卸载挂载点
umount /mnt
[root@oldboyedu ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.9G 17G 11% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
格式化xfs文件系统
[root@oldboyedu ~]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, 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
挂载xfs sdb2
mount -t xfs /dev/sdb2 /mnt
[root@oldboyedu ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.9G 17G 11% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb2 97M 5.3M 92M 6% /mnt
如何开机自动挂载?
/etc/fstab 开机自动挂载
UUID=03c35fa6-8fab-4192-82bf-998bb14fd954 / xfs defaults 0 0
UUID=06c07b41-5d88-47a0-9718-2d8d974440de /boot xfs defaults 0 0
UUID=6f37550b-7bf2-4735-9ced-961b548a13d9 swap swap defaults 0 0
设备 | 挂载点 | 文件系统类型 | 默认挂载选项 | 是否备份 | 是否磁盘检查 |
---|
blkid查看硬件id:查看块设备属性
[root@oldboyedu ~]# blkid
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="06c07b41-5d88-47a0-9718-2d8d974440de" TYPE="xfs"
/dev/sda2: UUID="6f37550b-7bf2-4735-9ced-961b548a13d9" TYPE="swap"
/dev/sda3: UUID="03c35fa6-8fab-4192-82bf-998bb14fd954" TYPE="xfs"
/dev/sdb1: UUID="b7ba4457-1636-48bb-9211-e1928aeddb0f" TYPE="ext4"
/dev/sdb2: UUID="ee89f78b-c44f-45d5-a1a4-56d9544c25f8" TYPE="xfs"
- 查看文件系统内部细节 :dumpe2fs #查看ext4 文件系统
swap分区的作用
- 内存不够的时候充当内存使用
- 在工作中JAVA服务,内存泄漏,swap就会占用,操作系统性能下降
free -m 查看内存使用量
企业中如何选择文件系统
如何优化文件系统
分区知识
(1)什么是分区,为什么要分区?
(2)磁盘和分区在Linux里的命名。
(3)磁盘分区类型和特点:
(4)磁盘分区工作原理:
(5)磁盘分区实战
(6)生产场景分区方案:4种。参考前面课程