linux分区设备类型设置,Linux磁盘分区介绍

磁盘分区介绍

一、fdisk命令介绍

1)、fdisk -l 查看本机磁盘信息(查的本机有两块硬盘,分别是sda 128.8G,sdb21.5G,sda这块硬盘有两个分区,分别是sda1,sda2)

[root@station78 ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes

255 heads, 63 sectors/track, 15665 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: 0x00057501

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 204800 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 26 7859 62914560 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: 0x12ae388b

Device Boot Start End Blocks Id System

2)、对/dev/sdb这块硬盘进行基本操作

0818b9ca8b590ca3270a3433284dd417.png

3)、创建分区,查看分区,保存分区信息并退出(设置一个5G的主分区)

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

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

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): +5G

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

Device Boot Start End Blocks Id System

/dev/sdb1 1 654 5253223+ 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@station78 ~]# fdisk -l /dev/sdb

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

Device Boot Start End Blocks Id System

/dev/sdb1 1 654 5253223+ 83 Linux

[root@station78 ~]#

4)、磁盘分区之后,使用的内核读到硬盘分区信息然后才能格式化分区(让内核重新读取硬盘的分区数)使用以下命令查看是否出现了sdb1的信息,从一下结构中很容易得知内核已经读到了硬盘信息

[root@station78 ~]# cat /proc/partitions

major minor #blocks name

8 0 125829120 sda

8 1 204800 sda1

8 2 62914560 sda2

8 16 20971520 sdb

8 17 5253223 sdb1

253 0 20971520 dm-0

253 1 2097152 dm-1

253 2 10485760 dm-2

253 3 20971520 dm-3

[root@station78 ~]#

注意:如果内核没有读取信息,则使用以下命令,然后在查看

[root@station78 ~]# partx -a /dev/sdb1 /dev/sdb

[root@station78 ~]#

二、硬盘的格式化查看磁盘类型并修改块大小

1)、使用mkfs 命令格式化硬盘

[root@station78 ~]# mkfs -t ext4 /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

328656 inodes, 1313305 blocks

65665 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1346371584

41 block groups

32768 blocks per group, 32768 fragments per group

8016 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@station78 ~]#

2)、查看文件类型以及分区的唯一标识UUID(UUID用于区分硬盘)

[root@station78 ~]# blkid /dev/sdb1

/dev/sdb1: UUID="f2263aef-fbc0-4dab-abc1-ccda473dc20a" TYPE="ext4"

[root@station78 ~]#

3)、修改硬盘的块大小,默认的块大小是4096字节,如果我们存储的数据文件都是小文件的时候,那么我们需要将块调小一些,这样更加合理的利用磁盘空间

mke2fs 不仅可以修改块大小,还能够设置磁盘的类型,设定卷标等

Mke2fs 命令常用选项

-b {1024|2048|4096 } bytes 设置块大小

-t {ext2|ext3|ext4} 指定文件类型

-L 指定卷标

4)使用mke2fs 设定/dev/sdb1的文件类型,块大小并指定卷标

[root@station78 ~]# mke2fs -t ext4 -b 1024 -L MYDAT /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=MYDAT

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

328704 inodes, 5253220 blocks

262661 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=72613888

642 block groups

8192 blocks per group, 8192 fragments per group

512 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553,

1024001, 1990657, 2809857, 5120001

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@station78 ~]#

5)、查看硬盘信息

[root@station78 ~]# blkid /dev/sdb1

/dev/sdb1: UUID="4bc881bb-8e96-4c10-9541-1169b01f28e5" TYPE="ext4" LABEL="MYDAT"

[root@station78 ~]#

注意:设定硬盘块大小时候必须格式化硬盘

三、硬盘格式化之后查看硬盘属性并调整(使用 tune2fs 命令)

1)、查看设备属性

[root@station78 ~]# tune2fs -l /dev/sdb1

tune2fs 1.41.12 (17-May-2010)

Filesystem volume name: MYDAT

Last mounted on:

Filesystem UUID: 4bc881bb-8e96-4c10-9541-1169b01f28e5

Filesystem magic number: 0xEF53

Filesystem revision #: 1 (dynamic)

Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize

Filesystem flags: signed_directory_hash

Default mount options: (none)

Filesystem state: clean

Errors behavior: Continue

Filesystem OS type: Linux

Inode count: 328704

Block count: 5253220

Reserved block count: 262661

Free blocks: 5133085

Free inodes: 328693

First block: 1

Block size: 1024

Fragment size: 1024

Reserved GDT blocks: 256

Blocks per group: 8192

Fragments per group: 8192

Inodes per group: 512

Inode blocks per group: 128

Flex block group size: 16

Filesystem created: Wed Jul 17 07:33:29 2013

Last mount time: n/a

Last write time: Wed Jul 17 07:33:31 2013

Mount count: 0

Maximum mount count: 27

Last checked: Wed Jul 17 07:33:29 2013

Check interval: 15552000 (6 months)

Next check after: Mon Jan 13 07:33:29 2014

Lifetime writes: 113 MB

Reserved blocks uid: 0 (user root)

Reserved blocks gid: 0 (group root)

First inode: 11

Inode size: 256

Required extra isize: 28

Desired extra isize: 28

Journal inode: 8

Default directory hash: half_md4

Directory Hash Seed: 16ed53d0-29bf-4fd8-b50e-d98a5d87984b

Journal backup: inode blocks

[root@station78 ~]#shan

2)、通过硬盘属性查看硬盘预留空间的块数(设置预留空间的块数的原因是防止硬盘数据存满以后,管理员无法在硬盘中任何操作,比如说当硬盘数据100%的时候,管理员无法使用任何命令操作。)

[root@station78 ~]# tune2fs -l /dev/sdb1 | grep "Reserved"

Reserved block count: 262661 块数

Reserved GDT blocks: 256

Reserved blocks uid: 0 (user root) 管理员

Reserved blocks gid: 0 (group root)

[root@station78 ~]#

3)、调整预留空间的块大小(防止当硬盘分区较大时浪费磁盘容量)

[root@station78 ~]# tune2fs -m 3 /dev/sdb1 设置预留块数为3%

tune2fs 1.41.12 (17-May-2010)

Setting reserved blocks percentage to 3% (157596 blocks)

[root@station78 ~]# tune2fs -l /dev/sdb1 | grep "Reserved" 查看属性

Reserved block count: 157596 变成157596

Reserved GDT blocks: 256

Reserved blocks uid: 0 (user root)

Reserved blocks gid: 0 (group root)

[root@station78 ~]#

四、硬盘的挂载和卸载

1)、挂载与卸载

0818b9ca8b590ca3270a3433284dd417.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值