linux上mysql分区磁盘位置_linux磁盘分区详解

1.磁盘的分区主要分为基本分区(primary partion)和扩充分区(extension partion)两种,基本分区和扩充分区的数目之和不能大于四个。且基本分区可以马上被使用但不能再分区。扩充分区必须再进行分区后才能使用,也就是说它必须还要进行二次分区。那么由扩充分区再分下去的是什么呢?它就是逻辑分区(logical partion),况且逻辑分区没有数量上限制。

在 Linux 中,每一个硬件设备都映射到一个系统的文件,对于硬盘、光驱等 IDE 或 SCSI 设备也不例外。Linux把各种 IDE 设备分配了一个由 hd 前缀组成的文件;而对于各种 SCSI 设备,则分配了一个由 sd 前缀组成的文件。

对于ide硬盘,驱动器标识符为“hdx~”,其中“hd”表明分区所在设备的类型,这里是指ide硬盘了。“x”为盘号(a为基本盘,b为基本从属盘,c为辅助主盘,d为辅助从属盘),“~”代表分区,前四个分区用数字1到4表示,它们是主分区或扩展分区,从5开始就是逻辑分区。例,hda3表示为第一个ide硬盘上的第三个主分区或扩展分区,hdb2表示为第二个ide硬盘上的第二个主分区或扩展分区。对于scsi硬盘则标识为“sdx~”,scsi硬盘是用“sd”来表示分区所在设备的类型的,其余则和ide硬盘的表示方法一样,不在多说。

在 Linux 中规定,每一个硬盘设备最多能有 4个主分区(其中包含扩展分区)构成,任何一个扩展分区都要占用一个主分区号码,也就是在一个硬盘中,主分区和扩展分区一共最多是 4 个。

Linux 规定了主分区(或者扩展分区)占用 1 至 16 号码中的前 4 个号码。以第一个 IDE 硬盘为例说明,主分区(或者扩展分区)占用了 hda1、hda2、hda3、hda4,而逻辑分区占用了 hda5 到 hda16 等 12 个号码。

因此,Linux 下面每一个硬盘总共最多有 16 个分区。

IDE硬盘最多有64个分区

1.fdisk -l 查看系统分区详细信息

1 [root@test4 ~]# fdisk -l2 Disk /dev/sda: 21.4 GB, 21474836480bytes3 255 heads, 63 sectors/track, 2610cylinders4 Units = cylinders of 16065 * 512 = 8225280bytes5

6 Device Boot Start End Blocks Id System7 /dev/sda1 * 1 13 104391 83Linux8 /dev/sda2 14 2610 20860402+ 8e Linux LVM

注释:这个硬盘的大小是21.4GB,有255个磁面,63个扇区,2610磁柱(cylinders)

每个cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);

Device Boot      Start         End      Blocks  Id  System

/dev/sda1  *           1          13      104391  83  Linux

/dev/sda2              14        1305   10377990   8e  Linux LVM

id和System 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。83是linux。下面的部分会提到;

说明:硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的:

其中* 表示的是a、b、c ... ...

另外x 表示的数字 1、2、3 ... ...

hd大多是IDE硬盘;sd大多是SCSI或移动存储;引导(Boot):表示引导分区,在上面的例子中sda1 是引导分区;

Start (开始):表示的一个分区从Xcylinder(磁柱)开始;

End (结束):表示一个分区到 Ycylinder(磁柱)结束;

2.fdisk  对磁盘进行分区

[root@test4 ~]# fdisk /dev/sda //对sda磁盘进行分区

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remaininmemory only,until you decide to writethem. After that, of course, the previous

content won't be recoverable.

The number of cylindersfor this disk is set to 2597.

There is nothing wrong with that, but this is larger than1024,

and couldincertain setups cause problems with:1) software that runs at boot time(e.g., old versions of LILO)2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2FDISK)

Warning: invalid flag0x0000 of partition table 4 will be corrected by w(rite)

Command (mfor 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 //创建一个新的空白DOS分区表

p print the partition table //打印分区表

q quit without saving changes //退出不保存设置

s create a new empty Sun disklabel

t change a partition's system id //改变分区的ID

u change display/entry units //改变显示的单位

v verify the partition table //检查验证分区表

w write table to disk and exit //保存分区表

x extra functionality (experts only)

Command (mforhelp):n

Command action

e extended//e是扩展分区

p primary partition (1-4) //p是主分区

p

Partition number (1-4): 1 //定义分区数量 --主分区最多只能有四个

First cylinder (1-2597, default 1): 1Last cylinder or+size or +sizeM or +sizeK (1-2597, default 2597): +100M

Command (mfor help): w //保存刚才的配置信息。

The partition table has been altered!Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: 无效的参数.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

[root@test6 ~]# fdisk /dev/sda

The number of cylindersfor this disk is set to 2610.

There is nothing wrong with that, but this is larger than1024,

and couldincertain setups cause problems with:1) software that runs at boot time(e.g., old versions of LILO)2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2FDISK)

Command (mforhelp): n

First cylinder (1710-2610, default 1710):

Using default value1710Last cylinder or+size or +sizeM or +sizeK (1710-2610, default 2610): +100M

Command (mfor help): wThe partition table has been altered!Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.

[root@test6~]# partprobe /dev/sda //对硬盘进行更新

[root@test6 ~]# fdisk -l

Disk/dev/sda: 21.4 GB, 21474836480bytes255 heads, 63 sectors/track, 2610cylinders

Units= cylinders of 16065 * 512 = 8225280bytes

Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83Linux/dev/sda2 14 274 2096482+ 82 Linux swap /Solaris/dev/sda3 275 404 10442258e Linux LVM/dev/sda4 405 2610 17719695 5Extended/dev/sda5 405 1709 10482381 83Linux/dev/sda6 1710 1722 104391 83Linux

[root@test6~]# mkfs.ext3 /dev/sda6 //需要先进行格式化,才能使用 。mkfs -t ext3 /dev/sda5 (mkfs.ext3 一样效果 -t 指定类型 -b 指定block大小·)

mke2fs 1.39 (29-May-2006)

Filesystem label=OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)26104 inodes, 104388blocks5219 blocks (5.00%) reserved forthe super user

First data block=1Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192fragments per group2008inodes per group

Superblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Writing inode tables:doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information:doneThis filesystem will be automatically checked every23mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@test6~]# mount /dev/sda6 /mnt/sda7/ //进行挂载使用

anaconda-ks.cfg install.log install.log.syslog

[root@test6~]# df -h

文件系统 容量 已用 可用 已用%挂载点/dev/sda5 9.7G 1.1G 8.1G 12% /

/dev/sda1 99M 12M 83M 13% /boot

tmpfs 252M0 252M 0% /dev/shm/dev/hdc 3.9G 3.9G 0 100% /mnt/cdrom/dev/sda6 99M 5.6M 89M 6% /mnt/sda7

1.磁盘管理常用命令

1.1 ls -i 文件名 查看文件存储在哪个innode中

1 [root@test6 ~]# ls -i lstest2 1179659 lstest

1.2 ls -id 文件夹名 查看文件夹存储在哪个innode中

1 [root@test6 ~]# ls -idlstest12 1179661 lstest1

1.3 filefrag -v 文件名 查看文件存储block具体位置

1 [root@test6 ~]# filefrag -v lstest2 Checking lstest3 Filesystem type is: ef534 Filesystem cylinder groups is approximately 78

5 Blocksize of file lstest is 4096

6 File size of lstest is 5 (1blocks)7 First block: 1183744

8 Last block: 1183744

9 lstest: 1 extent found

2.硬盘工具:

2.1 dumpe2fs /dev/sda1 查看分区superblock 和blockgroup等详细信息

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

[root@test6 ~]# dumpe2fs /dev/sda1

dumpe2fs1.39 (29-May-2006)

Filesystem volume name:/boot

Last mounted on:Filesystem UUID: 0c7f5306-fd13-4b13-819f-4b6cab126938

Filesystem magic number:0xEF53Filesystem revision #:1(dynamic)

Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super

Defaultmountoptions: user_xattr acl

Filesystem state: clean

Errors behavior: Continue

Filesystem OS type: Linux

Inode count:26104Block count:104388Reserved block count:5219Free blocks:89552Free inodes:26069First block:1Block size:1024Fragment size:1024Reserved GDT blocks:256Blocks per group:8192Fragments per group:8192Inodes per group:2008Inode blocks per group:251Filesystem created: Tue Mar28 07:57:05 2017Lastmount time: Tue Mar 28 08:29:57 2017Lastwrite time: Tue Mar 28 08:29:57 2017Mount count:3Maximummount count: -1Last checked: Tue Mar28 07:57:05 2017Check interval:0 ()

Reserved blocks uid:0(user root)

Reserved blocks gid:0(group root)

First inode:11Inode size:128Journal inode:8 //ext3 日志inode位置

Default directory hash: tea

Directory Hash Seed: 5e624e4a-049c-4cbf-a65f-8b8a7d08e398

Journal backup: inode blocks

Journal size: 4114k//日志文件大小

Group0: (Blocks 1-8192)

Primary superblock at1, Group descriptors at 2-2Reserved GDT blocks at3-258Block bitmap at259 (+258), Inode bitmap at 260 (+259)

Inode table at261-511 (+260)1023 free blocks, 1990 free inodes, 2directories

Free blocks:4642-5664Free inodes:19-2008Group1: (Blocks 8193-16384)

Backup superblock at8193, Group descriptors at 8194-8194Reserved GDT blocks at8195-8450Block bitmap at8451 (+258), Inode bitmap at 8452 (+259)

Inode table at8453-8703 (+260)4583 free blocks, 2008 free inodes, 0directories

Free blocks:11802-16384Free inodes:2009-4016Group2: (Blocks 16385-24576)

Block bitmap at16385 (+0), Inode bitmap at 16386 (+1)

Inode table at16387-16637 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:16638-24576Free inodes:4017-6024Group3: (Blocks 24577-32768)

Backup superblock at24577, Group descriptors at 24578-24578Reserved GDT blocks at24579-24834Block bitmap at24835 (+258), Inode bitmap at 24836 (+259)

Inode table at24837-25087 (+260)7439 free blocks, 1991 free inodes, 1directories

Free blocks:25193-25600, 25609-26112, 26121-26624, 26632-27136, 27144-27648, 27657-28160, 28168-28672, 28683-29184, 29192-29696, 29704-30208, 30218-31744, 31804-32768Free inodes:6042-8032Group4: (Blocks 32769-40960)

Block bitmap at32769 (+0), Inode bitmap at 32770 (+1)

Inode table at32771-33021 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:33022-40960Free inodes:8033-10040Group5: (Blocks 40961-49152)

Backup superblock at40961, Group descriptors at 40962-40962Reserved GDT blocks at40963-41218Block bitmap at41219 (+258), Inode bitmap at 41220 (+259)

Inode table at41221-41471 (+260)7681 free blocks, 2008 free inodes, 0directories

Free blocks:41472-49152Free inodes:10041-12048Group6: (Blocks 49153-57344)

Block bitmap at49153 (+0), Inode bitmap at 49154 (+1)

Inode table at49155-49405 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:49406-57344Free inodes:12049-14056Group7: (Blocks 57345-65536)

Backup superblock at57345, Group descriptors at 57346-57346Reserved GDT blocks at57347-57602Block bitmap at57603 (+258), Inode bitmap at 57604 (+259)

Inode table at57605-57855 (+260)7681 free blocks, 2008 free inodes, 0directories

Free blocks:57856-65536Free inodes:14057-16064Group8: (Blocks 65537-73728)

Block bitmap at65537 (+0), Inode bitmap at 65538 (+1)

Inode table at65539-65789 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:65790-73728Free inodes:16065-18072Group9: (Blocks 73729-81920)

Backup superblock at73729, Group descriptors at 73730-73730Reserved GDT blocks at73731-73986Block bitmap at73987 (+258), Inode bitmap at 73988 (+259)

Inode table at73989-74239 (+260)7681 free blocks, 2008 free inodes, 0directories

Free blocks:74240-81920Free inodes:18073-20080Group10: (Blocks 81921-90112)

Block bitmap at81921 (+0), Inode bitmap at 81922 (+1)

Inode table at81923-82173 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:82174-90112Free inodes:20081-22088Group11: (Blocks 90113-98304)

Block bitmap at90113 (+0), Inode bitmap at 90114 (+1)

Inode table at90115-90365 (+2)7939 free blocks, 2008 free inodes, 0directories

Free blocks:90366-98304Free inodes:22089-24096Group12: (Blocks 98305-104387)

Block bitmap at98305 (+0), Inode bitmap at 98306 (+1)

Inode table at98307-98557 (+2)5830 free blocks, 2008 free inodes, 0directories

Free blocks:98558-104387Free inodes:24097-26104

View Code

2.2 fsck /dev/sda 检查硬盘情况 -C 显示检查过程 -f 强制检查

2.3 badblocks /dev/sda5 检查硬盘坏道 -sv 显示进度和结果

df 查看文件系统(-h 以合适的单位示系统大小 -T 显示系统类型)

du 查看文件夹大小,包含文件夹里面文件

du -s 仅仅查看文件夹大小

du -h 以M方式显示大小,方便查看

fuser -mv /mnt 当显示 设备正在忙的时候,可以使用这个命令查看使用进程

tune2fs -l /dev/sda 查看磁盘参数(-h 查看可选选项,进行选项更改)

1 [root@test6 ~]# tune2fs -l /dev/sda52 tune2fs 1.39 (29-May-2006)3 Filesystem volume name: / //卷标

4 Last mounted on:

5 Filesystem UUID: 4b64bcce-0acc-40f2-85e6-07e198152c206 Filesystem magic number: 0xEF53

7 Filesystem revision #: 1(dynamic)8 Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file9 Default mountoptions: user_xattr acl10 Filesystem state: clean11 Errors behavior: Continue12 Filesystem OS type: Linux13 Inode count: 2621440

14 Block count: 2620595

15 Reserved block count: 131029

16 Free blocks: 2257390

17 Free inodes: 2582833

18 First block: 0

19 Block size: 4096

20 Fragment size: 4096

21 Reserved GDT blocks: 639

22 Blocks per group: 32768

23 Fragments per group: 32768

24 Inodes per group: 32768

25 Inode blocks per group: 1024

26 Filesystem created: Tue Mar 28 07:57:02 2017

27 Last mount time: Tue Mar 28 08:29:56 2017

28 Last write time: Tue Mar 28 08:29:56 2017

29 Mount count: 3

30 Maximum mount count: -1 //超过最大次数,则需要对分区进行自检

31 Last checked: Tue Mar 28 07:57:02 2017

32 Check interval: 0 ()33 Reserved blocks uid: 0(user root)34 Reserved blocks gid: 0(group root)35 First inode: 11

36 Inode size: 128

37 Journal inode: 8

38 First orphan inode: 163883

39 Default directory hash: tea40 Directory Hash Seed: 8633f5c3-e870-428e-8ce3-7d636f0ef80a41 Journal backup: inode blocks

e21able /dev/sda7 aa 卷标的另一种改法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值