Linux 系统管理06--磁盘管理
Linux系统管理06——磁盘管理
一、磁盘结构
1、硬盘的物理结构
盘片:硬盘有多个盘片,每个盘片2面
磁头:每面一个磁头
2、硬盘的数据结构
扇区:盘片被分为多个扇形区域,每个扇形区存放512字节的数据
磁道:统一盘片不同半径的同心圆
柱面:不同盘片相同半径构成的圆柱面
3、硬盘存储容量=磁头数x磁道(柱面)数x每道扇区数x每扇区字节数
4、可以用柱面/磁头/扇区来唯一定位磁盘上的每一个区域
二、磁盘接口
1、IDE(并口)
2、SATA(串口)
速度快
纠错能力强
3、SCSI
转速快
CPU占用资源低
支持热插拔
4、设备目录:/dev
Hd IDE
Sd SATA SCSI SAS
磁盘顺序:a..z
分区:用阿拉伯数字表示
三、MBR
1、定义:MBR(Master Boot Record)主引导记录
2、位置:MBR位于硬盘第一个物理扇区处
3、MBR中包含硬盘的主引导程序和硬盘分区表。分区表有4个分区记录区,每个分区记录区占16个字节,共64字节。446字节存放主引导程序,2字节校验。
四、磁盘分区表示
1、Linux中将硬盘等设备均表示为文件
2、磁盘分区结构
硬盘中的主分区数目只有4个,因此主分区和扩展分区的序号也就限制在1~4。扩展分区再分为逻辑分区,逻辑分区的序号始终从5开始。
五、文件系统类型
1、EXT4,第4代扩展(Extended)文件系统
存放文件和目录数据的分区
典型的日志型文件系统
系统中默认使用的文件系统
2、SWAP,交换文件系统
为Linux系统建立交换分区,类似于windows系统的虚拟缓存
3、Linux支持的其他系统文件类型
FAT16、FAT32、NIFS、XFS、JFS……
六、检测并确认新硬盘 fdisk -l命令
1、格式:fdisk –l [磁盘设备]
2、输出信息说明
Device:分区的设备文件名称
Boot:是否是引导分区。是,则有“*”标识
Stat/End:分区的起始/结束位置(柱面数)
Blocks:块,默认大小为1024字节
Id:分区对应的系统ID号。83表示Linux中的EXT4分区、8e表示LVM逻辑卷、82表示swap、fd表示RAID
System:分区类型
示例:列出当前系统中所有硬盘设备及其分区的信息
[root@crushlinux ~]# fdisk -l Disk /dev/sda: bytes heads, sectors/track, cylinders Units = cylinders of * = bytes Sector size (logical/physical): bytes / bytes I/O size (minimum/optimal): bytes / bytes Disk identifier: 0x000d78d8 Device Boot Start End Blocks Id System /dev/sda1 * Linux Partition does not end on cylinder boundary. /dev/sda2 8e Linux LVM Disk /dev/mapper/vg_duanwenya-lv_root: bytes heads, sectors/track, cylinders Units = cylinders of * = bytes Sector size (logical/physical): bytes / bytes I/O size (minimum/optimal): bytes / bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_duanwenya-lv_swap: MB, bytes heads, sectors/track, cylinders Units = cylinders of * = bytes Sector size (logical/physical): bytes / bytes I/O size (minimum/optimal): bytes / bytes Disk identifier: 0x00000000
七、规划硬盘中的分区 fdisk命令
1、作用:在交互式的操作环境中管理磁盘分区
2、格式:fdisk [磁盘设备]
3、常用选项:
m:查看操作指令的帮助信息
p:列表查看分区信息
n:新建分区
d:删除分区
t:变更分区类型
w:保存分区设置并退出
q:放弃分区设置并退出
Ctrl+退格键:删除输入的错误字符
4、示例:
为主机新增一块20G的SCSI硬盘
对该硬盘进行分区
划分两个主分区,各5G,剩余空间为扩展分区
在扩展分区中建立两个逻辑分区,第一个逻辑分区1G,类型为swap。第二个逻辑 分区为9G。
(1)关机
(2)新增硬盘
(3)
开机,查看新硬盘是否添加
()使用fdisk进行分区
[root@crushlinux ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4f3a72ac.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
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
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)
Command (m for help): p
Disk /dev/sdb: bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x4f3a72ac
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended 【扩展分区】
p primary partition (-) 【主分区】
p
Partition number (-):
First cylinder (-, default ): 回车
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G
Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ): 回车
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G
Command (m for help): n
Command action
e extended
p primary partition (-)
e
Partition number (-):
First cylinder (-, default ): 回车
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): 回车
Using default value
Command (m for help): n
Command action
l logical ( or over) 【逻辑分区】
p primary partition (-)
l
First cylinder (-, default ): 回车
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G
Command (m for help): t
Partition number (-):
Hex code (type L to list codes):
Changed system type of partition to (Linux swap / Solaris)
Command (m for help): n
Command action
l logical ( or over)
p primary partition (-)
l
First cylinder (-, default ): 回车
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): 回车
Using default value
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
八、大小超过2T的分区规划 parted命令
1、作用:规划大小超过2T的分区,也可用于小分区的规划
2、格式:parted [选项] [分区设备]
3、交互式状态下的常用命令:
?/help/--help:帮助
quit/q:保存退出
print/p:打印
mklabel:改变硬盘的文件类型
mkpart:分区
rm:删除某分区,后面跟分区号,例如:rm 3
4、示例:
为主机新增一块20G的SCSI硬盘
对该硬盘进行分区
将硬盘类型改为gpt
划分三个分区,前两个分区各5G,剩下的都空间都划分给第三分区
(1)关机
(2)新增硬盘
(3)开机,查看新硬盘是否添加
[root@crushlinux ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
1049kB 525MB 524MB primary ext4 启动
525MB 107GB 107GB primary lvm
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
[root@crushlinux ~]# parted /dev/sdb
GNU Parted 2.1
使用 /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
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
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
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
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
新的磁盘标签类型? 【两次tab键】
aix amiga bsd dvh gpt loop mac msdos pc98 sun
新的磁盘标签类型? gpt
警告: 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) mkpart
分区名称? []? part1
文件系统类型? [ext2]? ext4
起始点?
结束点? 5G
(parted) mkpart
分区名称? []? part2
文件系统类型? [ext2]? ext4
起始点? 5G
结束点? 10G
(parted) mkpart
分区名称? []? part3
文件系统类型? [ext2]? ext4
起始点? 10G
结束点? -
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1049kB 5000MB 4999MB part1
5000MB .0GB 5001MB part2
.0GB .5GB .5GB part3
(parted) quit
[root@crushlinux ~]# ls -l /dev/sdb*
brw-rw----. root disk , 1月 : /dev/sdb
brw-rw----. root disk , 1月 : /dev/sdb1
brw-rw----. root disk , 1月 : /dev/sdb2
brw-rw----. root disk , 1月 : /dev/sdb3
[root@crushlinux ~]# mkfs.ext4 /dev/sdb1
mke2fs (-May-)
文件系统标签=
操作系统:Linux
块大小= (log=)
分块大小= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
第一个数据块=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , ,
正在写入inode表: 完成
Creating journal ( blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@crushlinux ~]# mkdir /sdb1
[root@crushlinux ~]# mount /dev/sdb1 /sdb1/
[root@crushlinux ~]# cd /sdb1/
[root@crushlinux sdb1]# echo ceshiwenjian > test.txt
[root@crushlinux sdb1]# cd
[root@crushlinux ~]# umount /sdb1/
[root@crushlinux ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1049kB 5000MB 4999MB ext4 part1
5000MB .0GB 5001MB part2
.0GB .5GB .5GB part3
(parted) 【模拟误删除分区】
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
5000MB .0GB 5001MB part2
.0GB .5GB .5GB part3
(parted) rescue 【救援误删除分区】
起始点?
结束点? 5G
信息: A ext4 primary partition was found at 1049kB -> 5000MB. Do you want to add it to the
partition table?
是/Yes/否/No/放弃/Cancel? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: .5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1049kB 5000MB 4999MB ext4
5000MB .0GB 5001MB part2
.0GB .5GB .5GB part3
(parted) q
信息: You may need to update /etc/fstab.
[root@crushlinux ~]# mount /dev/sdb1 /sdb1/
[root@crushlinux ~]# cat /sdb1/test.txt 【测试文件已被找回】
ceshiwenjian
Linux 系统管理06--磁盘管理的更多相关文章
- Linux系统管理_磁盘管理——敬请期待!!!
df 显示磁盘空间使用情况 -a 全部文件系统列表 -h 以方便阅读的方式显示 -T 列出文件系统类型 du 查看目录和文件的磁盘空间使用情况 -a 显示目录中所有文件大小 -h 以易读方式显示文件大 ...
- Linux基本命令——系统管理和磁盘管理
转: Linux基本命令--系统管理和磁盘管理 Linux命令--系统管理和磁盘管理 一.系统管理 1.1 时间相关指令 <1> 查看当前日历: cal <2> 显示或设置时间 ...
- Linux文件系统与磁盘管理
Linux文件系统与磁盘管理 有哪些文件系统: FAT:微软在Dos/Windows系列操作系统中共使用的一种文件系统的总称. exFAT(Extended File Allocation ...
- Linux 系统管理04--账号管理
Linux系统管理04--账号管理 一.用户账号管理 1.用户账号概述 (1)用户账号的常见分类: 1>超级用户:root uid=0 gid=0 权限最大. 2>普通用户:uid> ...
- Linux系统的磁盘管理
Linux系统的磁盘管理有三个命令:df.du.fdisk. df:列出Linux中所有文件系统的整体磁盘使用量: du:对文件和目录所占用磁盘空间的查看: fdisk:用于磁盘分区时列出所有的磁盘. ...
- 【Linux学习】Linux系统管理1—进程管理
Linux系统管理1-进程管理 一.Linux的三种进程 Linux包括3中不同类型的进程: 交互进程:由一个shell启动的进程.交互进程可以在前后台运行 批处理进程:该进程和终端无联系,是一个进程 ...
- linux基本命令之磁盘管理命令(ls,cd,pwd,mkdir,rmdir,clear, touch)
linux磁盘管理命令 1.ls(list)命令:列出目录内容. 格式:ls [参数][文件或目录] ls -a或-all表示列出所有文件和目录,以点开始的是影藏文件,例如,.bash_history ...
- linux基础之磁盘管理与文件系统
上面一篇文章(https://www.cnblogs.com/ckh2014/p/7224851.html)介绍了硬盘的基本结构,那么一块磁盘如何应用取存储数据呢? 它的步骤是这样的: 识别硬盘 -- ...
- Linux进阶之磁盘管理及LVM逻辑卷
本节内容 磁盘管理 LVM 一.磁盘管理 1.硬盘接口 种类及其应用: IDE接口硬盘多用于家用产品,部分应用于服务器 SATA SCSI接口硬盘主要应用于服务器 SAS只在高端服务器上,价格昂贵 2 ...
随机推荐
- 简易漫画网站搭建-漫画喵Server版
小喵的唠叨话:寒假的时候写了一个漫画爬虫,爬取了好几个漫画,不过一直没有找到合适的漫画阅读的工具.因此最近就试着自己写一个漫画的网站,放在公网上或者局域网里,这样就能随时随地用手机.Pad看漫画了. ...
- 百度api使用心得体会
最近项目中在使用百度地图api,对于其中的一些有用的点做一些归纳整理,如有不对的地方,欢迎各位大神纠正指出. 一定要学会查找百度地图api提供的类参考网站:http://lbsyun.baidu.co ...
- js动态加载的蒙板弹框
我们访问一些网站时总会遇到这种点击后,背景像被打上一层模板一样,这个是怎么做到的呢? 它是将这个弹框div独立于页面容器wrap,设置position为absolute,将其水平垂直之后都居中,设置弹 ...
- ehcache 使用笔记
要想使用 java 的本地缓存,可以考虑用 ehcache,或者 guava. guava 更高端一点,可以自动定时刷新.我选择了 ehcache. 在 spring 中是集成了 ehcache 的. ...
- Linux云自动化运维第二课
一.Linux系统结构 1.Linux是一个倒树结构.Linux中所有的东西都是文件.这些文件都在系统的顶级目录中"/","/"是根目录."/&quo ...
- 深入解读Python的unittest并拓展HTMLTestRunner
unnitest是Python的一个重要的单元测试框架,对于用Python进行开发的同事们可能不需要对他有过深入的了解会用就行,但是,对于自动化测试人员我觉得是要熟知unnitest的执行原理以及相关 ...
- shell 之时间戳
vim 1.sh #/bin/bash##by cc read -p "Please input yourtime:" timea=$timeif [ $a != 0 ] then ...
- 【G】开源的分布式部署解决方案文档 - 手动安装
G.系列导航 [G]开源的分布式部署解决方案 - 导航 序言 因各种原因,决定先写使用文档.也证明下项目没有太监.至于安装过程复杂,是因为还没有做一键安装,这个现阶段确实没精力. 项目进度 (点击图片 ...
- Android 增加(键盘)按键
以添加 camera按键为例(红色是需要添加的) 一.kernel键值定义 (1)键扫描码 ScanCode是由linux的Input驱动框架定义的整数类型,可参考input.h头文件,即geteve ...
- Centos6.8 安装 nginx
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm ...