Linux系统磁盘介绍
所有有系统都一样,都是一种软件被安装于某个硬件之上,这个硬件无外非是一种存储设备,通常操作系统都是安装磁盘中,所以Linux系统也一样,都是安装在磁盘当中,但是它不同与windows系统的安装,因为Linux都是需要创建文件系统的才可以使用,今天我们变来介绍下最基础的知识——磁盘
一:磁盘分类
目前市场上磁盘的分类有:IDE磁盘(多用于PC机)、 SATA磁盘、SAS 磁盘、SSD磁盘等这么几种分类,企业级服务器中大多用后二者,SATA磁盘多用于企业内部的一些业务、SAS 磁盘多用于对外的业务(一些业务平台)。
SATA磁盘目前容量比较大的有4T、SAS 磁盘一般都在300G---600G居多,企业生产环境中使用也最多的是这种容量的,实际生产中磁盘的使用主要看性能需求,也就是磁盘的读写速度。
二:磁盘的体系结构
企业级服务器多块磁盘的情况
三:磁盘容量的计算
磁盘的结构一般包括磁道、盘面、扇区、碰头等
一个磁道的大小=512字节*扇区数
一个盘面的大小=磁道的大小*磁道数
一个磁盘的大小=盘面大小*磁头数
因些
一个磁盘的容量=512字节*扇区数*磁道数*磁头数
代码语言:javascript复制[root@Centos ~]# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb712cc55
四:磁盘分区
所有的磁盘分区信息都是存储在分区表中,Linux系统仅支持4个分区表信息(主分区 扩展分区),一个分区表的在小是64bytes
linux一般分为三个分区分别是:boot 分区、swap分区、 /根分区
linux 的分区编号:主分区1-4,逻辑分区从5开始计算
代码语言:javascript复制Command action
e extended
p primary partition (1-4)
实际生产环境分区要求
1、最少要有/和swap两个分区
2、swap(虚拟内存)=1.5*物理内存大小,一般大小于或等于16G的物理内存的服务器,swap分区一般都直接设置为16G大小
3、建议设置/boot分区,Linux引导分区,如内核文件等 ,一般所有文件一共才几十M的大小,因些一般此分区设置100M-200M即可
五:磁盘分区工具(fdisk和parted) 1、fdisk 是征对磁盘容量小于2T 的分区工具
代码语言:javascript复制[root@Centos ~]# fdisk -l 查看磁盘信息
Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000acb37
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 10444 83373056 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb712cc55
fdisk /dev/sdb 对/dev/sdb这块磁盘进行分区操作
代码语言:javascript复制[root@Centos ~]# fdisk /dev/sdb
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)
以上就是日常常用的参数
代码语言:javascript复制Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 设置起始柱面
Using default value 1
Last cylinder, cylinders or size{K,M,G} (1-2610, default 2610):
设置大小或柱面
代码语言:javascript复制Using default value 2610
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Command (m for help): p 打印分区表信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb712cc55
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793 83 Linux
分区完成后执行partprobe通知系统分区表发生改变
接下来进行格式化分区
[root@Centos ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Centos ~]# tune2fs -c -1 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[root@Centos ~]# mount /dev/sdb1 /mnt挂载分区至/mnt下
[root@Centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /
tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home
/dev/sdb1 20G 172M 19G 1% /mnt
硬盘分区、格式化完成,并已成功挂载可以使用了
2、由于环境受限无法有2T或以上大小的磁盘,只能模拟环境来使用parted分区工具来进行分区
[root@Centos ~]# parted /dev/sdb mklabel gpt
将磁盘转换成gpt的格式
代码语言:javascript复制[root@Centos ~]# parted /dev/sdb mkpart primary 0 200(200M)
Warning: The resulting partition is not properly aligned for best
performance.
Ignore/Cancel? Ignore
[root@Centos ~]# parted /dev/sdb p 打印分区表信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 200MB 200MB primary
[root@Centos ~]# parted /dev/sdb mkpart primary 201 1073
分区并设置大小
代码语言:javascript复制Information: You may need to update /etc/fstab.
[root@Centos ~]# parted /dev/sdb p 打印分区表信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 200MB 200MB primary
2 201MB 1073MB 871MB primary
[root@Centos ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
48960 inodes, 195296 blocks
9764 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
24 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Centos ~]# tune2fs -c -1 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[root@Centos ~]# mount /dev/sdb1 /mnt
[root@Centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /
tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home
/dev/sdb1 185M 5.6M 170M 4% /mnt
磁盘分区、格式化完成,并挂载成功可以使用了
parted使用场景:
1、一般只有硬盘大小或者RAID后大于2T,否则只用fdisk分区
2、一般都是系统装好之后
3、大于2T的磁盘,在安装系统时可使用RAID中的虚拟磁盘分出大小(适合安装系统的大小)
然后进行安装系统,进入系统后再用parted进行分区