一、磁盤管理總體分類
1)磁盤結構
2)分區類型
3)管理分區
4)管理文件系統
5)掛載設備
6)管理虛擬內存
………………………………………………………………………………………………………………………
重要分類模塊詳解
………………………………………………………………………………………………………………………
1、磁盤常用術語
head:磁頭 track:磁道 sector:扇區 cylinder:柱面
2、分區種類
1)主引導記錄(MBR)
MBR: Master Boot Record,1982年,使用32位表示扇區數,分區不超過2T如何分區:按柱面0磁道0扇區:512bytes 446bytes: boot loader 64bytes:分區表 16bytes: 標識一個分區 2bytes: 55AA 4個主分區;3主分區+1擴展(N個邏輯分區)
2)GPT
GPT:GUID patition table (GUID分區表) 支持128個分區,使用64位,支 持8Z( 512Byte/block )64Z ( 4096Byte/block)使用128位UUID 表示磁盤和分區 GPT分區表自動備份在頭 和尾兩份,并有CRC校驗位UEFI (統一擴展固件接口)硬件支持GPT
3、常用分區管理工具
lsblk命令:
lsblk – list block devices
演示:
[root@centos6 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 120G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 80G 0 part / ├─sda3 8:3 0 20G 0 part /testdir ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 4G 0 part [SWAP] └─sda6 8:6 0 5G 0 part sdb 8:16 0 120G 0 disk sdc 8:32 0 20G 0 disk sdd 8:48 0 20G 0 disk sde 8:64 0 20G 0 disk [root@centos6 ~]#
fdisk命令:
fdisk – Partition table manipulator for Linux
fdisk -cu device fdisk device
常用子命令:
d delete a partition #刪除分區表
l list known partition types #列出分區類型
m print this menu #打印幫助信息
n add a new partition #添加一個新的分區
p print the partition table #打印分區表
q quit without saving changes #不保存退出
t change a partition's system id #改變一個分區的系統ID
w write table to disk and exit #將分區表寫入系統
partx/partprobe命令:通知內核重新讀取硬盤分區表信息
partx -a /dev/device 例如:partx -a /dev/sda1
kpartx -a /dev/device -f:force
刪除分區:
partx -d –nr # /dev/device #號表示刪除的第幾塊分區
partx -d –nr 7 /dev/sda
CentOS5.x CentOS7.x使用:partprobe命令即可
查看內核是否已經識別新的分區:cat /proc/partitations
………………………………………………………………………………………………………………………
演示:
………………………………………………………………………………………………………………………
[root@centos6 ~]# fdisk -l /dev/sda 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: 0x000813f2 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 10469 83886080 83 Linux /dev/sda3 10469 13080 20971520 83 Linux /dev/sda4 13080 15666 20765696 5 Extended /dev/sda5 13081 13603 4194304 82 Linux swap / Solaris /dev/sda6 13604 13865 2104515 83 Linux /dev/sda7 13866 13997 1060258+ 83 Linux [root@centos6 ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 83886080 sda2 8 3 20971520 sda3 8 4 1 sda4 8 5 4194304 sda5 8 16 125829120 sdb 8 32 20971520 sdc 8 48 20971520 sdd 8 64 20971520 sde [root@centos6 ~]# partx -a /dev/sda sda sda1 sda2 sda3 sda4 sda5 [root@centos6 ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 [root@centos6 ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 [root@centos6 ~]# !cat cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 83886080 sda2 8 3 20971520 sda3 8 4 1 sda4 8 5 4194304 sda5 8 6 2104515 sda6 8 7 1060258 sda7 8 16 125829120 sdb 8 32 20971520 sdc 8 48 20971520 sdd 8 64 20971520 sde [root@centos6 ~]#
………………………………………………………………………………………………………………………
二、創建文件系統
mkfs命令:創建一個linux文件系統
mkfs – build a Linux file system
用法:
mkfs.fs_type /dev/device #fs_type{ext4 xfs btrfs vfat}
mkfs.fs_type /dev/device -L 'LABEL' #指定卷標
………………………………………………………………………………………………………………………
演示:
[root@centos6 ~]# mkfs.ext4 /dev/sda6 -L 'MYDATE' mke2fs 1.41.12 (17-May-2010) 文件系統標簽=MYDATE 操作系統:Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131648 inodes, 526128 blocks 26306 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=541065216 17 block groups 32768 blocks per group, 32768 fragments per group 7744 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 正在寫入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@centos6 ~]# blkdi -bash: blkdi: command not found [root@centos6 ~]# blkid /dev/sda2: UUID="240533cf-b37f-4460-974f-702bab867da5" TYPE="ext4" /dev/sda1: UUID="4e245c68-a392-4ce9-9a99-5d32d8d43872" TYPE="ext4" /dev/sda3: UUID="86aa7b74-24df-4043-ba83-f3b41a99ce0e" TYPE="ext4" /dev/sda5: UUID="f8ef48ef-b141-48e5-9735-ff9089bd54ba" TYPE="swap" /dev/sda6: UUID="b153fa9a-5b82-4bbc-b580-9170ab88b4a6" TYPE="ext4" LABEL="MYDATE" [root@centos6 ~]#
………………………………………………………………………………………………
mke2fs命令:創建ext系列文件系統
mke2fs – create an ext2/ext3/ext4 filesystem
選項:
-t{ext2|ext3|ext4} #指定文件類型
-b{1024|2048|4096} #指定塊大小
-L 'LABEL' #指定卷標
-j #相當于mke2fs -t ext3,mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
-i #: 為數據空間中每多少個字節創建一個inode;此大 小不應該小于block的大小
-N #: 為數據空間創建杜少而過inode
-m #: 為管理員預留的空間占總空間的百分比,默認為5%
blkid命令:
blkid – command-line utility to locate/print block device attributes
選項:
-U:UUID #按UUID來查找到相應的設備
-L:LABEL #按卷標查找到相應的設備名
e2label命令:
用法:e2label device LABEL
e2lable deveice
tune2fs命令:重新設定文件系統的超級塊可調參數的屬性值
選項:
-L 'LABEL':修改卷標
-j 將ext2升級到ext3
-o 調整文件系統掛載選項,acl,取消為^acl
-m #:修預留給管理員的空間百分比
dumpe2fs命令:
-h:查看超級塊信息(分組信息),分區用分組管理
例如:dumpe2fs -h /dev/sda8 tune2fs -l /dev/sda8
文件修復和檢測:
常發生于死機或者非正常關機之后,常發生于死機或者非正常關機之后
fsck: File System
Check fsck.FS_TYPE
fsck -t FS_TYPE
演示:
………………………………………………………………………………………………
[root@centos6 ~]# mke2fs -t ext4 -b 2048 -L 'MAN' -m 1 /dev/sda8 mke2fs 1.41.12 (17-May-2010) 文件系統標簽=MAN 操作系統:Linux 塊大小=2048 (log=1) 分塊大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 804864 inodes, 6438032 blocks 64380 blocks (1.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=544210944 393 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312, 5619712 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@centos6 ~]# mount /dev/sda8 /mnt [root@centos6 ~]# tune2fs -l /dev/sda8 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: MAN Last mounted on: <not available> Filesystem UUID: 8528b2b5-4dc3-48c9-91f5-a0d096442b36 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery 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: 804864 Block count: 6438032 Reserved block count: 64380 Free blocks: 6297100 Free inodes: 804853 First block: 0 Block size: 2048 Fragment size: 2048 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Mon Aug 22 22:43:55 2016 Last mount time: Mon Aug 22 22:44:44 2016 Last write time: Mon Aug 22 22:44:44 2016 Mount count: 1 Maximum mount count: 30 Last checked: Mon Aug 22 22:43:55 2016 Check interval: 15552000 (6 months) Next check after: Sat Feb 18 22:43:55 2017 Lifetime writes: 262 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: c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c Journal backup: inode blocks [root@centos6 ~]# blkid /dev/sda8 /dev/sda8: LABEL="MAN" UUID="8528b2b5-4dc3-48c9-91f5-a0d096442b36" TYPE="ext4" [root@centos6 ~]# blkid -U "8528b2b5-4dc3-48c9-91f5-a0d096442b36" /dev/sda8 [root@centos6 ~]# blkid -L MAN /dev/sda8 [root@centos6 ~]# [root@centos6 ~]# e2label /dev/sda8 HUMAN [root@centos6 ~]# e2label /dev/sda8 HUMAN [root@centos6 ~]# tune2fs -L 'BABY' /dev/sda8 tune2fs 1.41.12 (17-May-2010) [root@centos6 ~]# tune2fs -o acl /dev/sda8 tune2fs 1.41.12 (17-May-2010) [root@centos6 ~]# tune2fs -l /dev/sda8 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: BABY Last mounted on: <not available> Filesystem UUID: 8528b2b5-4dc3-48c9-91f5-a0d096442b36 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 804864 Block count: 6438032 Reserved block count: 64380 Free blocks: 6297100 Free inodes: 804853 First block: 0 Block size: 2048 Fragment size: 2048 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Mon Aug 22 22:43:55 2016 Last mount time: Mon Aug 22 22:44:44 2016 Last write time: Mon Aug 22 23:01:13 2016 Mount count: 1 Maximum mount count: 30 Last checked: Mon Aug 22 22:43:55 2016 Check interval: 15552000 (6 months) Next check after: Sat Feb 18 22:43:55 2017 Lifetime writes: 262 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: c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c Journal backup: inode blocks [root@centos6 ~]# tune2fs -m 5 /dev/sda8 tune2fs 1.41.12 (17-May-2010) Setting reserved blocks percentage to 5% (321901 blocks) [root@centos6 ~]# tune2fs -l /dev/sda8
………………………………………………………………………………………………
三、掛載文件系統
mount命令:
用法:
mount DEVICE MOUNT_POINT
mount [-fnrsvw] [-t vfstype] [-o options] device dir
掛載方式:
1)設備文件 例如:mount /dev/sda5 /mnt
2)卷標 例如:mount -L 'MYDATE' /mnt
3)UUID 例如:mount -U '40d51666-7a52-4613-bac9-0a1f27afeee8'/mnt
選項:
-t:指定文件類型
-r:只讀掛載
-w:讀寫掛載
-n:不更新/etc/mtab
-a:自定掛載/etc/fstab定義的設備
-L:卷標
-U:uuid
-B:綁定目錄到另一個目錄上
查看內核最終到的掛載的所有設備:cat /proc/mounts
-o options:(掛載文件系統的選項),多個選項使用逗號分隔 async:異步模式 sync:同步模式,內存更改時,同時寫磁盤 atime/noatime:包含目錄和文件 diratime/nodiratime:目錄的訪問時間戳 auto/noauto:是否支持自動掛載,是否支持-a選項 exec/noexec:是否支持將文件系統上運行應用程序 dev/nodev:是否支持在此文件系統上使用設備文件 suid/nosuid:不否支持suid和sgid權限 remount:重新掛載 ro:只讀 rw:讀寫 user/nouser:是否允許普通用戶掛載此設備,默認管理員才能掛載 acl:啟用此文件系統上的acl功能 Defaults:相當于rw, nosuid, dev, exec, auto, nouser, async
umount命令:
umount DEVICE
umount MOUNT_POINT
………………………………………………………………………………………………
四、掛載至配置文件
/etc/fstab 每行定義一個要掛載的文件系統說明
[root@centos6 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Aug 11 03:07:57 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=240533cf-b37f-4460-974f-702bab867da5 / ext4 defaults 1 1 UUID=4e245c68-a392-4ce9-9a99-5d32d8d43872 /boot ext4 defaults 1 2 UUID=86aa7b74-24df-4043-ba83-f3b41a99ce0e /testdir ext4 defaults 1 2 UUID=f8ef48ef-b141-48e5-9735-ff9089bd54ba swap swap defaults 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 #要掛載的設備或為文件系統 #掛載點 #文件類型 #選項 #轉儲 #自檢 [root@centos6 ~
………………………………………………………………………………………………
本文出自小耳朵,小編乏了,洪荒之力已用完,覺得文章還可以記得點贊哦:)!!!
原創文章,作者:alren,如若轉載,請注明出處:http://www.www58058.com/40656