天天看點

磁盤分區知識總結

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 剩餘硬碟大小,放資料庫及存儲資料的 

方案三:門戶級别或大型網站

swap 實體記憶體的1.5倍

剩餘的空間保留,不在進行分區,将來分給那個部門,根據需求分區,此方法靈活 

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 ~]# 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

磁盤分區、格式化和挂載小結:

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,如需轉載請自行聯系原作者

繼續閱讀