磁盘分区知识总结

简介:

1.1磁盘存储逻辑结构
主分区(primary)、扩展分区(extend)、逻辑分区  
备份命令:dd if=/dev/sda of=mbr.bin bs=512 count=1 

一块磁盘的分区表占有64btyes大小,每个分区占用16个字节,因此一块磁盘仅支持四个分区表信息,即主分区+扩展分区的总量不超过4个。

1.2磁盘分区的注意事项点
1)任意多个主分区,1<=主分区数<=4 
2)扩展分区和主分区可以组合,但1<=主分区数+扩展<=4 

常规分区方案:
方案一:集群架构中的某个节点,数据有多少或者不重要。
/boot 启动引导主分区 linux引导程序
swap  sawp主分区     物理内存的两倍
/     根分区        剩余磁盘大小给/

方案二:数据库及存储,有大量的重要的数据
/boot 100M
/ 50-200GB 
swap 物理内存的1.5-2.0倍  
/data 剩余硬盘大小,放数据库及存储数据的 

方案三:门户级别或大型网站
/boot 100M
swap 物理内存的1.5倍
/ 50-200GB 
剩余的空间保留,不在进行分区,将来分给那个部门,根据需求分区,此方法灵活 

1.3分区标号

/dev/sda 
/dev/sdb 
........
/dev/sda1 
/dev/sda2 
.........

1.4文件系统
文件系统是指对一个存储设备上的数据和元素进行组织的一种机制 
常用的文件系统类型:ext2 ext3 ext4 NTFS FAT32 FAT 等

文件系统小结:
1)文件系统是指对一个存储设备上的数据和元素进行组织的一种机制 
2)分区必须只能有一种文件系统
3)分区必须格式化创建文件系统才能存放数据  
4)linux常用的文件系统类型:ext2 ext3 ext4 zfs xfs Reiserfs等


查看支持的文件系统:ls -l /lib/modules/2.6.32-504.el6.i686/kernel/fs/
[root@chen ~]# ls -l /lib/modules/2.6.32-504.el6.i686/kernel/fs/
总用量 124
drwxr-xr-x. 2 root root  4096 3月  27 21:47 autofs4
drwxr-xr-x. 2 root root  4096 3月  27 21:47 btrfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 cachefiles
drwxr-xr-x. 2 root root  4096 3月  27 21:47 cifs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 configfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 cramfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 dlm
drwxr-xr-x. 2 root root  4096 3月  27 21:47 ecryptfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 exportfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 ext2
drwxr-xr-x. 2 root root  4096 3月  27 21:47 ext3
drwxr-xr-x. 2 root root  4096 3月  27 21:47 ext4
drwxr-xr-x. 2 root root  4096 3月  27 21:47 fat
drwxr-xr-x. 2 root root  4096 3月  27 21:47 fscache
drwxr-xr-x. 2 root root  4096 3月  27 21:47 fuse
drwxr-xr-x. 2 root root  4096 3月  27 21:47 gfs2
drwxr-xr-x. 2 root root  4096 3月  27 21:47 jbd
drwxr-xr-x. 2 root root  4096 3月  27 21:47 jbd2
drwxr-xr-x. 2 root root  4096 3月  27 21:47 jffs2
drwxr-xr-x. 2 root root  4096 3月  27 21:47 lockd
-rwxr--r--. 1 root root 12616 10月 15 2014 mbcache.ko
drwxr-xr-x. 2 root root  4096 3月  27 21:47 nfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 nfs_common
drwxr-xr-x. 2 root root  4096 3月  27 21:47 nfsd
drwxr-xr-x. 2 root root  4096 3月  27 21:47 nls
drwxr-xr-x. 2 root root  4096 3月  27 21:47 squashfs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 ubifs
drwxr-xr-x. 2 root root  4096 3月  27 21:47 udf
[root@chen ~]# 

dumpe2fs /dev/sda1 查看文件系统inode和block结构   

3.磁盘分区讲解 

假设我们的需求是分6个区 
1P+1E(5 6 7 8 9)
/dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8 /dev/sdb9
2p+1E(5 6 7 8)
3p+1E(5 6 7)

1)关机增加一块新的硬盘
2)使用命令fdisk -cu /dev/sdb进行分区  

man partprobe  partprobe - inform the OS of partition table changes  ---通知内核分区表的变化  

[root@chen ~]# fdisk -cu /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2a97a4a9.
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 0x0000 of partition table 4 will be corrected by w(rite)

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

dumpe2fs ----dumpe2fs - dump ext2/ext3/ext4 filesystem information  导出文件系统信息  

fdisk -l          -----------查看磁盘分区 
fdisk  -cu /dev/sdb  -------- 分区命令    
partprobe  /dev/sdb   -------通知内核分区表的变化(分区完成后执行此命令)  

分区工具:parted (可在命令换行或脚本执行,此分区直接生效)

mkfs - build a Linux file system(格式化)

mkfs -t ext4   -I 1024 -b 8192  /dev/sdb1 
mkfs.ext4 -I1024 /dev/sdb1 
     -t:指定文件类型
     -I:指定inode节点大小(默认256)
     -b:指定block的大小  (最大4096) 

[root@chen ~]# mkfs.ext4 /dev/sdb1 (格式化)
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

正在写入inode表: 完成                            
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@chen ~]# tune2fs -c -1 /dev/sdb1 (取消时间过期)
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[root@chen ~]# 
[root@chen ~]# mount /dev/sdb1 /mnt (挂载)
[root@chen ~]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda3      ext4    18G  1.6G   16G  10% /
tmpfs          tmpfs  504M     0  504M   0% /dev/shm
/dev/sda1      ext4   190M   26M  155M  14% /boot
/dev/sdb1      ext4   969M  1.3M  918M   1% /mnt
[root@chen ~]# 

磁盘分区、格式化和挂载小结:
1)fsdisk -cu /dev/sdb 
2)mkfs.ext4 /dev/sdb1或  mkfs -t ext4 /dev/sdb1 
  tune2fs -c -1 /dev/sdb1  partprobe  /dev/sdb

3)mount -t ext4 /dev/sdb1 测试是否挂载成功 mount -a 
4)df -Th  df -i  cat /proc/mounts 
5)du -sh 查看内存大小

如何使用UUID使得开机自动挂载和修改挂载表/etc/fstab 
开机自动挂载:vi /etc/fstab  
/dev/sdb1  /mnt /ext4  defaults   0  0   

UUID=ccb0bb71-79fa-4670-8df1-0bc177936cac /mnt/ ext4  defaults,noexec   0 0

blkid -----查看uuid
[root@chen mnt]# blkid
/dev/sda1: UUID="e0617ba5-095a-4474-bdc8-b3167dd8f58e" TYPE="ext4" 
/dev/sda2: UUID="96be0e54-978f-41c1-8dc5-faf45eca854b" TYPE="swap" 
/dev/sda3: UUID="90d3bc5a-e19d-483b-ac91-a096be544704" TYPE="ext4" 
/dev/sdb1: UUID="ccb0bb71-79fa-4670-8df1-0bc177936cac" TYPE="ext4" 
[root@chen mnt]# vi /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Sun Mar 27 21:40:41 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=90d3bc5a-e19d-483b-ac91-a096be544704 /                       ext4    def
aults        1 1
UUID=e0617ba5-095a-4474-bdc8-b3167dd8f58e /boot                   ext4    def
aults        1 2
UUID=96be0e54-978f-41c1-8dc5-faf45eca854b swap                    swap    def
aults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
#/dev/cdrom             /mnt/cdrom           iso9660    defaults        0 0
#UUID=ccb0bb71-79fa-4670-8df1-0bc177936cac /mnt/ ext4  defaults,noexec   0 0
除此外把挂载信息写入到/etc/rc.local等同在/etc/fstab 



本文转自chengong1013 51CTO博客,原文链接:http://blog.51cto.com/purify/1791658,如需转载请自行联系原作者
相关文章
|
18天前
|
存储 数据管理 数据安全/隐私保护
如何给移动硬盘分区?(移动硬盘分区详细指南)
本文介绍了如何对移动硬盘进行分区,以提高数据管理和安全性。首先解释了硬盘分区的基本概念和好处,包括提升管理效率、保障数据安全和优化硬盘利用。接着,提供了两种分区方法:一是使用Windows磁盘管理器,适合基础操作;二是使用DiskGenius软件,功能更强大且用户友好。对于已有分区的移动硬盘,可通过调整现有分区或拆分来增加新分区。整个过程中,建议先备份数据,并谨慎操作。
|
5月前
|
存储 安全 Linux
Linux文件系统和磁盘分区
Linux文件系统和磁盘分区
45 0
|
8月前
|
IDE 安全 Linux
2.2磁盘分区
2.2磁盘分区
65 0
|
10月前
|
Linux
【磁盘管理】fdisk命令 – 管理磁盘分区
fdisk命令来自于英文词组“Partition table manipulator for Linux”的缩写,其功能是用于管理磁盘的分区信息。如果一套几百平米的房子内部没有墙壁,虽然看起来会很敞亮,但是各种声音、气味、物品会随意充斥在整个房子内,让人极不舒适,因此需要用墙壁按照功能进行划分,例如卧室、厕所、厨房、阳台等等。
171 0
|
10月前
|
存储 运维 Oracle
Linux系统管理--硬盘、卷组、逻辑卷和文件系统
增加两个20GB的硬盘,注意新增加的硬盘不能取代原来安装了操作系统的0号硬盘,不然无法启动。