磁盤管理之分區管理
磁盤一般指的是計算的硬盤,它是計算機五大部件之一,主要用來存儲數據。所有它是計算機不可或缺的部件之一。
常見的硬盤分為固態和機械二種:
固態: 固態硬盤是用固態電子存儲芯片陣列而制成的硬盤,由控制單元和存儲單元(FLASH芯片、DRAM芯片)組成。但是造價較高。
優勢:讀寫性能好 低功率、無噪音、防震性能好等、
缺點:售價較高、容量小
機械:機械硬盤其實是許多的盤片、機械手臂、磁頭與主軸馬達所組成。在主軸馬達的轉動下由可伸展機械臂的磁頭在盤片進行讀寫操作。
轉速:轉速的快慢是標示硬盤檔次的重要參數之一,硬盤的轉速越快,硬盤尋找文件的速度也就越快,相對的硬盤的傳輸速度也就得到了提高。單位表示為RPM,RPM是Revolutions Per minute的縮寫,是轉/每分鐘。RPM值越大,內部傳輸率就越快,訪問時間就越短,硬盤的整體性能也就越好。
扇區(Sector):每個機械硬盤的每個扇區大小都為512bytes。
磁道(Track):當磁盤旋轉時,磁頭若保持在一個位置上,則每個磁頭都會在磁盤表 面劃出一個圓形軌跡,這些圓形軌跡就叫做磁道。
柱面(Cylinkder):盤片上的同一磁道組成的面
當你拿到一個全新的硬盤你要先對它進行分區,為什么要分區?可能有些人會問這個問題。因為一塊大容量硬盤好如一個大柜子,要在這個柜子里存放各種文件,有很多種方法,但為了便于管理和使用,一般都會把大柜子分成一個一個的相對獨立的“隔間”或“抽屜”,絕不會就把大柜子當做一個大抽屜來使用。分區還可以有利于病毒的防治和數據的安全等等。。。
無論是windows還是linux,目前支持的分區結構只有兩種,一種是基于blos檢查啟動的mbr結構,另一種是基于uefi(統一擴展固件接口)的opt分區結構。當然,目前廣泛的還是使用的mbr結構。
MBR,全稱為Master Boot Record,即硬盤的主引導記錄。盤的0柱面、0磁頭、1扇區稱為主引導扇區(也叫主引導記錄MBR)。它由三個部分組成,主引導程序、硬盤分區表DPT(Disk Partition table)和分區有效標志。在總共512字節的主引導扇區里主引導程序(boot loader)占446個字節,第二部分是Partition table區(分區表),即DPT,占64個字節,硬盤中分區有多少以及每一分區的大小都記在其中。第三部分是magic number,占2個字節,固定為0xAA55或0x55AA。
磁盤分區
查看磁盤分區: lsblk
[root@Cloud /]#lsblk #顯示磁盤分區信息 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /media sda 8:0 0 200G 0 disk ├─sda1 8:1 0 200M 0 part /boot └─sda2 8:2 0 60G 0 part ├─vg0-root (dm-0) 253:0 0 20G 0 lvm / ├─vg0-swap (dm-1) 253:1 0 2G 0 lvm [SWAP] ├─vg0-usr (dm-2) 253:2 0 10G 0 lvm /usr └─vg0-var (dm-3) 253:3 0 20G 0 lvm /var sdb 8:16 0 15G 0 disk /mnt/one sdc 8:32 0 20G 0 disk lsblk列出的信息NAME 設備名 MAJ:MIN 主版本號 :次版本號 RM 是否為可移動設備 顯示1位移動設備 SIZE 大小 RO 只讀 TYPE 磁盤、分區類型 MOUNTPOINT 掛載點
磁盤分區工具 fdisk
[root@Cloud ~]#fdisk -l /dev/sdb #x -l 列出/dev/sdb的分區信息 不加參數為所有磁盤 Disk /dev/sdb: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 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: 0x00000000 [root@Cloud ~]#fdisk /dev/sdb #對/dev/sdb進去分區等管理 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#MBR分區如果你分區不想使用它可以做到類型格式化的作用 p print the partition table #顯示分區列表 q quit without saving changes #退出不保存 s create a new empty Sun disklabel t change a partition's system id #分區類型,常用82,83 8e 等 u change display/entry units v verify the partition table w write table to disk and exit #保存并退出 x extra functionality (experts only)
顯示所有分區
[root@Cloud ~]#fdisk -l #顯示所有分區 Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x000efd6b 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 /dev/sda3 7859 7990 1059291 83 Linux Disk /dev/sdb: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 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: 0x8e7a48c2 Device Boot Start End Blocks Id System Disk /dev/sdc: 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: 0xb3173c06 Device Boot Start End Blocks Id System /dev/sdc1 1 393 3156741 83 Linux Disk /dev/mapper/vg0-root: 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: 0x00000000 Disk /dev/mapper/vg0-swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0x00000000 Disk /dev/mapper/vg0-usr: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x00000000 Disk /dev/mapper/vg0-var: 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: 0x00000000
支持的分區
Command (m for help): l 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- #swap分區 2 XENIX root 3c PartitionMagic 83 Linux #常用分區 c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM #邏輯卷 df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1
新增為邏輯分區
Command (m for help): n First cylinder (7991-8122, default 7991): Using default value 7991 Last cylinder, +cylinders or +size{K,M,G} (7991-8122, default 8122): +1G Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x000efd6b 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 /dev/sda3 7859 7990 1059291 83 Linux /dev/sda4 7991 8122 1060290 5 Extended /dev/sda5 7991 8122 1060258+ 83 Linux
刪除分區
Command (m for help): d Partition number (1-5): 1 Command (m for help): d Partition number (1-5): 2 Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x000efd6b Device Boot Start End Blocks Id System /dev/sda3 7859 7990 1059291 83 Linux /dev/sda4 7991 8122 1060290 5 Extended /dev/sda5 7991 8122 1060258+ 83 Linux
有些時候對硬盤分區的時候如果硬盤已經被掛載使用了,再對它進行分區的話,有時內核會識別不到我們新建的分區 所有要用命令
內核識別新增分區:
partx-a -n M:N /dev/DEVICE
kpartx-a /dev/DEVICE -f: force
內核識別刪除分區:
partx -d /dev/DEVICE
CentOS 5,7: 使用partprobe
?partprobe[/dev/DEVICE]
原創文章,作者:ladsdm,如若轉載,請注明出處:http://www.www58058.com/43720