磁盘管理之管理分区
管理分區(qū)
列出塊設(shè)備
lsblk
創(chuàng)建分區(qū)使用:
fdisk 創(chuàng)建MBR分區(qū)
gdisk 創(chuàng)建GPT分區(qū)
parted 高級(jí)分區(qū)操作
partprobe-重新設(shè)置內(nèi)存中的內(nèi)核分區(qū)表版本
一查看分區(qū)
1查看內(nèi)存上的分區(qū)
看到數(shù)字出現(xiàn)了就說明是硬盤已經(jīng)分區(qū)并且生效了,生效就是保存在內(nèi)存里了。
分區(qū)表在兩個(gè)地方有,磁盤和內(nèi)存。下面的命令查看到的內(nèi)容是來自內(nèi)存。
只有內(nèi)存里面保存了內(nèi)存才可以對(duì)硬盤的數(shù)據(jù)處理,而如果只是放到硬盤上就無法處理了。
磁盤包括硬盤,是樹林和樹的關(guān)系。
法1
[root@centos65 ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sdb /dev/sdc /dev/sdd [root@centos65 ~]# ll /dev/sd* brw-rw----. 1 root disk 8, 0 Jan 23 22:50 /dev/sda brw-rw----. 1 root disk 8, 1 Jan 23 22:51 /dev/sda1 brw-rw----. 1 root disk 8, 2 Jan 23 22:51 /dev/sda2 brw-rw----. 1 root disk 8, 3 Jan 23 22:51 /dev/sda3 brw-rw----. 1 root disk 8, 4 Jan 23 22:50 /dev/sda4 brw-rw----. 1 root disk 8, 5 Jan 23 22:50 /dev/sda5 brw-rw----. 1 root disk 8, 16 Jan 23 23:27 /dev/sdb brw-rw----. 1 root disk 8, 32 Jan 23 23:00 /dev/sdc brw-rw----. 1 root disk 8, 48 Jan 23 23:00 /dev/sdd
法2:
[root@centos65 ~]# cat /proc/partitions major minor #blocks name 8 0 209715200 sda 8 1 1048576 sda1 8 2 51200000 sda2 8 3 20480000 sda3 8 4 1 sda4 8 5 2097152 sda5 8 16 104857600 sdb 8 32 83886080 sdc 8 48 62914560 sdd
法3:
[root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
注意
上面的3種方法顯示的內(nèi)容都是一樣,因?yàn)槎际莵碜詢?nèi)存的分區(qū)表。
對(duì)磁盤上的文件進(jìn)行修改都是先讀取到內(nèi)存中,在內(nèi)存里面修改
當(dāng)使用vim編輯器時(shí)修改文件就要w才可以保存在磁盤上。
dd命令是直接在磁盤上把數(shù)據(jù)修改了,所以內(nèi)存分區(qū)表和磁盤分區(qū)表有可能就不同步了。
2查看磁盤上的分區(qū)
以第1塊硬盤為例:
255 heads, 63 sectors/track, 26108 cylinders從這里就可以看出是CSH結(jié)構(gòu),也就是使用了MBR分區(qū)類型,這是默認(rèn)的。
表示255個(gè)虛擬磁頭,63個(gè)扇區(qū)/磁道,26108個(gè)柱面。
Units = cylinders of 16065 * 512 = 8225280 bytes 一個(gè)柱面的大小
Sector size (logical/physical): 512 bytes / 512 bytes 一個(gè)扇區(qū)的字節(jié)數(shù)
I/O size (minimum/optimal): 512 bytes / 512 bytes 每次讀寫的字節(jié)數(shù)
Device表示硬盤上面的分區(qū),可以看到有5個(gè)分區(qū)。
*表示此分區(qū)為啟動(dòng)分區(qū),Start 表示開始的柱面,End表示結(jié)束的柱面
Blocks表示塊數(shù)量,Id表示分區(qū)類型ID,System表示分區(qū)類型
[root@centos65 ~]# 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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris Disk /dev/sdb: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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/sdd: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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
這是克隆了sda的分區(qū)表,512字節(jié)無法克隆數(shù)據(jù)。
硬盤沒有分區(qū)就沒有分區(qū)類型
二分區(qū)工具parted的使用
parted是一個(gè)磁盤分區(qū)和分區(qū)大小調(diào)整程序。
它允許你創(chuàng)建,銷毀,調(diào)整大小,移動(dòng)和復(fù)制ext2、linux-swap、FAT、FAT32和reiserfs分區(qū)。
它可以創(chuàng)建,調(diào)整大小,并移動(dòng)Macintosh HFS parti-以及檢測(cè)jfs、ntfs、ufs和xfs分區(qū)。它有助于為新操作創(chuàng)建空間系統(tǒng),重新組織磁盤使用,并將數(shù)據(jù)復(fù)制到新的硬盤。
注意parted的操作都是實(shí)時(shí)生效的,小心使用
用法:parted [選項(xiàng)]... [設(shè)備 [命令 [參數(shù)]...]...]
parted /dev/sdb mklabel gpt|msdos
parted /dev/sdb print
parted /dev/sdb mkpart primary 1 200 (默認(rèn)M)
parted /dev/sdb rm 1
parted -l
1顯示幫助
注意是交互式的,輸入help顯示了幫助內(nèi)容
[root@centos65 ~]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) help align-check TYPE N check partition N for TYPE(min|opt) alignment check NUMBER do a simple check on the file system cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER mkpart PART-TYPE [FS-TYPE] START END make a partition mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system move NUMBER START END move partition NUMBER name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resize NUMBER START END resize partition NUMBER and its file system rm NUMBER delete partition NUMBER select DEVICE choose the device to edit set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted
2創(chuàng)建分區(qū)表,定義分區(qū)類型
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
parted /dev/sdb mklabel gpt|msdos
msdos就是MBR分區(qū)。
[root@centos65 ~]# parted /dev/sdc mklabel msdos Information: You may need to update /etc/fstab. [root@centos65 ~]# parted /dev/sdc print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 85.9GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags
注意
[root@centos65 ~]# fdisk  /dev/sdc
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
警告:不推薦dos兼容模式。強(qiáng)烈推薦
關(guān)閉模式(命令“c”)并將顯示單元更改為扇區(qū)(命令“u”)。
Command (m for help): p Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x0009eebb Device Boot Start End Blocks Id System
在sdb硬盤上定義GPT分區(qū)類型
注意GPT分區(qū)和MBR是不能兼容的,也不能轉(zhuǎn)換。
[root@centos65 ~]# parted mklabel /dev/sdb gpt Error: Could not stat device mklabel - No such file or directory. Retry/Cancel? c [root@centos65 ~]# parted /dev/sdb mklabel gpt Information: You may need to update /etc/fstab. [root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags
[root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
出現(xiàn)警告,因?yàn)閒disk只支持對(duì)小于2TB的磁盤進(jìn)行分區(qū)
[root@centos65 ~]# fdisk /dev/sdb WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
警告:在'/dev/sdb'上檢測(cè)到GPT (GUID分區(qū)表)!util fdisk不支持GPT。使用GNU Parted。
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sdb: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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 Device Boot Start End Blocks Id System /dev/sdb1 1 13055 104857599+ ee GPT
在sdc上就沒有警報(bào),因?yàn)槭褂肕BR分區(qū)
[root@centos65 ~]# fdisk /dev/sdc -l Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x00088833 Device Boot Start End Blocks Id System
在sdb上創(chuàng)建分區(qū),分區(qū)大小為1000M
在前面已經(jīng)指定為GPT分區(qū)類型了
[root@centos65 ~]# parted /dev/sdb mkpart primary 1 1000 Warning: You requested a partition from 1000kB to 1000MB. The closest location we can manage is 1000MB to 1000MB.
我們能管理的最近的位置是1000MB到1000MB。 Is this still acceptable to you? Yes/No? yes Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? ^C Information: You may need to update /etc/fstab.
創(chuàng)建了分區(qū)之后就同步到內(nèi)存的分區(qū)表里面了
[root@centos65 ~]# parted /dev/sdb mkpart primary 1 1000 Information: You may need to update /etc/fstab. [root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB primary [root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 953M 0 part sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
創(chuàng)建的不合適,可以刪除
[root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB primary
rm  partition——Delete partition.
parted  /dev/sdb rm 1 其中1代表分區(qū)的序號(hào)
[root@centos65 ~]# parted    /dev/sdb    rm  1
Information: You may need to update /etc/fstab.                           
                     
[root@centos65 ~]# parted    /dev/sdb    print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start  End  Size  File system  Name  Flags
注意如果要使用fdisk查看或者創(chuàng)建MBR分區(qū),在使用parted刪除了分區(qū)之后要重新指定類型
[root@centos65 ~]# parted /dev/sdb    rm  1
Information: You may need to update /etc/fstab.                           
[root@centos65 ~]# parted /dev/sdb   print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start  End  Size  File system  Name  Flags
[root@centos65 ~]# fdisk  /dev/sdb
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): ^C
[root@centos65 ~]# parted /dev/sdb mklabel   msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? y                                                                 
Information: You may need to update /etc/fstab.                           
[root@centos65 ~]# fdisk  /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000c381a
   Device Boot      Start         End      Blocks   Id  System
內(nèi)存也把分區(qū)刪除了
[root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
三分區(qū)工具gdisk的使用
類fdisk 的GPT分區(qū)工具
使用gdisk對(duì)分區(qū)進(jìn)行管理
1顯示幫助
和parted一樣是交互式的
報(bào)警,是因?yàn)閯偛旁O(shè)置成了MBR分區(qū)類型
[root@centos65 ~]# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! ***************************************************************
發(fā)現(xiàn)無效的GPT和有效的MBR;將MBR轉(zhuǎn)換為GPT格式
在內(nèi)存中。這個(gè)操作具有潛在的破壞性!
如果不希望轉(zhuǎn)換MBR分區(qū),請(qǐng)鍵入“q”GPT格式!
Command (? for help): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu
2打印分區(qū)表
p print the partition table
現(xiàn)在沒有分區(qū)
Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): CCCA39F5-8CD6-4F25-B42E-277BF4956DF3 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 209715133 sectors (100.0 GiB) Number Start (sector) End (sector) Size Code Name
使用parted創(chuàng)建分區(qū),分區(qū)類型為GPT
[root@centos65 ~]# parted /dev/sdb mklabel gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? y Information: You may need to update /etc/fstab. [root@centos65 ~]# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT.
[root@centos65 ~]# parted /dev/sdb mkpart primary 1 1000 Information: You may need to update /etc/fstab. [root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB primary
[root@centos65 ~]# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 957106F8-950F-49F1-BE76-4E637A2A3567 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 207763389 sectors (99.1 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1953791 953.0 MiB 0700 primary
sda是MBR類型的也會(huì)顯示,但是會(huì)警告
[root@centos65 ~]# gdisk /dev/sda GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! ***************************************************************
Command (? for help): p Disk /dev/sda: 419430400 sectors, 200.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): E742544D-FD2C-467B-808B-1F34B879B5BC Partition table holds up to 128 entries First usable sector is 34, last usable sector is 419430366 Partitions will be aligned on 2048-sector boundaries Total free space is 269778877 sectors (128.6 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 104499199 48.8 GiB 8300 Linux filesystem 3 104499200 145459199 19.5 GiB 8300 Linux filesystem 5 145463296 149657599 2.0 GiB 8200 Linux swap
[root@centos65 ~]# fdisk  /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
3使用gdisk創(chuàng)建分區(qū)
在sdb上創(chuàng)建新分區(qū)
n add a new partition
Command (? for help): n
Partition number (2-128, default 2): 3
First sector (34-209715166, default = 1953792) or {+-}size{KMGTP}: 
會(huì)顯示默認(rèn)要?jiǎng)?chuàng)建的分區(qū),default 2
比如已經(jīng)創(chuàng)建了第1個(gè)分區(qū),那么就會(huì)顯示默認(rèn)創(chuàng)建第2個(gè)分區(qū),也可以自定義。
First sector (34-209715166, default = 1953792) or {+-}size{KMGTP}: 這個(gè)表示開始的扇區(qū)
顯示扇區(qū)的位置,和前面的分區(qū)有關(guān),默認(rèn)是從前1個(gè)分區(qū)的下1個(gè)扇劃分default = 1953792。
創(chuàng)建分區(qū)的開始扇區(qū)也可以使用括號(hào)里面的扇區(qū),從34開始,但是最多只能到2047,因?yàn)榈?個(gè)分區(qū)的扇區(qū)是從2048開始的。
Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): B9D45D7D-405D-4EC1-BE1D-DC9CA5406FD0 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 207763389 sectors (99.1 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1953791 953.0 MiB 0700 primary
使用默認(rèn)的直接回車即可,接著就顯示結(jié)束扇區(qū)
Command (? for help): n
Partition number (2-128, default 2): 3
First sector (34-209715166, default = 1953792) or {+-}size{KMGTP}: 
Last sector (1953792-209715166, default = 209715166) or {+-}size{KMGTP}: 
209715166表示結(jié)束扇區(qū)的最大范圍,也就把所有的空間都分光了。
Last sector (1953792-209715166, default = 209715166) or {+-}size{KMGTP}:
這個(gè)最好不要選擇默認(rèn),因?yàn)槟J(rèn)是以扇區(qū)為單位的,所以直接指定分區(qū)的空間大小會(huì)更方便,不過要寫上數(shù)據(jù)存儲(chǔ)單位。
+1G表示的是從前一個(gè)分區(qū)的最后一個(gè)扇區(qū)開始增加1G大小的分區(qū)。
-表示往前面的扇區(qū)劃分,因?yàn)楸黄渌謪^(qū)占用分不了,+表示往后面的扇區(qū)劃分。
下面顯示的是標(biāo)簽,提醒一下是做什么的。
回車就是選擇默認(rèn)
Command (? for help): n
Partition number (2-128, default 2): 3
First sector (34-209715166, default = 1953792) or {+-}size{KMGTP}: 
Last sector (1953792-209715166, default = 209715166) or {+-}size{KMGTP}: +G
Last sector (1953792-209715166, default = 209715166) or {+-}size{KMGTP}: +1G        
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot   
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM           
a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap        
a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID  
a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap   
a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum  
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+      
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
Press the <Enter> key to see more codes: ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): B9D45D7D-405D-4EC1-BE1D-DC9CA5406FD0 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 205666237 sectors (98.1 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1953791 953.0 MiB 0700 primary 3 1953792 4050943 1024.0 MiB 8300 Linux filesystem
4存盤退出
注意不論是刪除和增加都要存盤才會(huì)使結(jié)果生效
Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully. [root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk ├─sdb1 8:17 0 953M 0 part └─sdb3 8:19 0 1G 0 part sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
5刪除分區(qū)
Command (? for help): d Partition number (1-3): 3 Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): B9D45D7D-405D-4EC1-BE1D-DC9CA5406FD0 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 207763389 sectors (99.1 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1953791 953.0 MiB 0700 primary
6查看高級(jí)選項(xiàng)
高級(jí)選項(xiàng)
Command (? for help): x Expert command (? for help): ? a set attributes c change partition GUID d display the sector alignment value e relocate backup data structures to the end of the disk g change disk GUID h recompute CHS values in protective/hybrid MBR i show detailed information on a partition l set the sector alignment value m return to main menu n create a new protective MBR o print protective MBR data p print the partition table q quit without saving changes r recovery and transformation options (experts only) s resize partition table t transpose two partition table entries u replicate partition table on new device v verify disk w write table to disk and exit z zap (destroy) GPT data structures and exit ? print this menu
選擇存盤退出
Command (? for help): p Disk /dev/sdb: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 957106F8-950F-49F1-BE76-4E637A2A3567 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 205666237 sectors (98.1 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 1953791 953.0 MiB 0700 primary 3 1953792 4050943 1024.0 MiB 8300 Linux filesystem Command (? for help): d Partition number (1-3): 3 Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdb. The operation has completed successfully. [root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 953M 0 part sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk [root@centos65 ~]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB primary
四分區(qū)工具fdisk的使用
fdisk的子命令,和sed一樣,也是有子命令的
1查看幫助
顯示報(bào)警是因?yàn)橹笆褂玫氖荊PT分區(qū)類型
[root@centos65 ~]# fdisk   /dev/sdb
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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)
修改分區(qū)表類型,修改成fdisk支持的MBR
即使把分區(qū)刪除了,分區(qū)結(jié)構(gòu)或者分區(qū)表類型還是之前的GPT或者M(jìn)BR。
要想修改原來的分區(qū)表類型可以使用mklabel,這樣之前的分區(qū)類型就會(huì)被替換了。
[root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 1000MB 999MB primary [root@centos65 ~]# parted /dev/sdb mklabel msdos Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? y Information: You may need to update /etc/fstab. [root@centos65 ~]# parted /dev/sdb print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 107GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags
現(xiàn)在轉(zhuǎn)換成了MBR,原來的GPT類型也沒有了
[root@centos65 ~]# fdisk  /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0006ff87
   Device Boot      Start         End      Blocks   Id  System
[root@centos65 ~]# fdisk /dev/sdb -l Disk /dev/sdb: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x000d8fb4 Device Boot Start End Blocks Id System
2查看分區(qū)
[root@centos65 ~]# fdisk   /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
DOS-compatible mode表示的是以柱面為單位劃分分區(qū),可以修改成以扇區(qū)為單位
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
3關(guān)閉dos兼容模式
下面顯示的是以柱面為單位的。
不在柱面的邊界會(huì)出現(xiàn)報(bào)警Partition 1 does not end on cylinder boundary.
[root@centos65 ~]# fdisk   /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
如果不想看到報(bào)警信息加上c,也就關(guān)閉了dos兼容模式
[root@centos65 ~]# fdisk   /dev/sda  -c
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
[root@centos65 ~]# fdisk  /dev/sdb  -c
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0006ff87
   Device Boot      Start         End      Blocks   Id  System
4在6上修改分區(qū)單位
修改成了扇區(qū)單位
不想看到報(bào)警信息加上c,關(guān)閉了dos兼容模式,而且以扇區(qū)為單位劃分的就加上u,兩個(gè)選項(xiàng)可以合并寫
Blocks是以k為單位
[root@centos65 ~]# fdisk /dev/sda -cu Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 cylinders, total 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 104499199 51200000 83 Linux /dev/sda3 104499200 145459199 20480000 83 Linux /dev/sda4 145459200 419430399 136985600 5 Extended /dev/sda5 145463296 149657599 2097152 82 Linux swap / Solaris
通過柱面的數(shù)量計(jì)算出分區(qū)的大小,比如sda1的大小131柱面x8M就是1G
[root@centos65 ~]# fdisk   /dev/sda  
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
[root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
5在7版本修改分區(qū)單位
劃分分區(qū)是以柱面還是扇區(qū)看個(gè)人習(xí)慣,扇區(qū)是最小單位,感覺細(xì)了些。
在7里面fdisk默認(rèn)就是以扇區(qū)的方式
在虛擬機(jī)72上添加硬盤
[root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sr0 11:0 1 4.2G 0 rom /mnt
如果硬盤沒有顯示就只能重啟服務(wù)了
[root@centos72 ~]# echo '- - -' > /sys/class/scsi_host/host2/scan [root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sr0 11:0 1 4.2G 0 rom /mnt [root@centos72 ~]# Connection closed by foreign host. Disconnected from remote host(192.168.137.72:22) at 17:24:51. Type `help' to learn how to use Xshell prompt. [c:~]$ ssh 192.168.137.72 Connecting to 192.168.137.72:22... Connection established. To escape to local shell, press Ctrl+Alt+]. WARNING! The remote SSH server rejected X11 forwarding request. Last login: Thu Feb 21 17:22:43 2019 from 192.168.137.34 [root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sr0 11:0 1 4.2G 0 rom /mnt
在7上只顯示扇區(qū),相當(dāng)于默認(rèn)就加上了cu選項(xiàng)
[root@centos72 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xc4a044a6. Command (m for help): p Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes只顯示扇區(qū) I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xc4a044a6 Device Boot Start End Blocks Id System
在6上不僅顯示扇區(qū)還顯示柱面,磁頭
[root@centos65 ~]# fdisk   /dev/sda  
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
可以修改成以柱面為單位
[root@centos72 ~]# fdisk --help fdisk: invalid option -- '-' Usage: fdisk [options] <disk> change partition table fdisk [options] -l <disk> list partition table(s) fdisk -s <partition> give partition size(s) in blocks Options: -b <size> sector size (512, 1024, 2048 or 4096) -c[=<mode>] compatible mode: 'dos' or 'nondos' (default) -h print this help text -u[=<unit>] display units: 'cylinders' or 'sectors' (default) -v print program version -C <number> specify the number of cylinders -H <number> specify the number of heads -S <number> specify the number of sectors per track
現(xiàn)在轉(zhuǎn)換成了以柱面為單位了
[root@centos72 ~]# fdisk   /dev/sda    -u=cylinders
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
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 label type: dos
Disk identifier: 0x000c7076
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
/dev/sda2             131        6658    52428800   83  Linux
/dev/sda3            6658        9269    20971520   83  Linux
/dev/sda4            9269       26109   135265280    5  Extended
/dev/sda5            9269        9530     2097152   82  Linux swap / S
注意選項(xiàng)只要不是加在命令前面就有效
[root@centos72 ~]# fdisk       -u=cylinders   /dev/sda
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
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 label type: dos
Disk identifier: 0x000c7076
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
/dev/sda2             131        6658    52428800   83  Linux
/dev/sda3            6658        9269    20971520   83  Linux
/dev/sda4            9269       26109   135265280    5  Extended
/dev/sda5            9269        9530     2097152   82  Linux swap / Solaris
和6是一樣的
[root@centos65 ~]# fdisk   /dev/sda  -c
WARNING: cylinders as display units are deprecated. Use command 'u' to
         change units to sectors.
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
6在6版本的硬盤上創(chuàng)建分區(qū)
在6版本的sda硬盤上創(chuàng)建分區(qū)
[root@centos65 ~]# fdisk   /dev/sda  
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
Command (m for help): n
First cylinder (9316-26109, default 9316): 
9316屬于擴(kuò)展分區(qū)的一部分,擴(kuò)展分區(qū)的范圍是9055-26109,所以9316之后的內(nèi)容是在擴(kuò)展分區(qū)里面。
注意4個(gè)分區(qū)已經(jīng)分出來了,最后一個(gè)是擴(kuò)展分區(qū)。要?jiǎng)?chuàng)建新分區(qū)只能在這4個(gè)分區(qū)里面分。
可以跳過9316,從1000開始,那么9316-10000之間的柱面是閑置的。
接著是柱面的結(jié)束位置,默認(rèn)到最后,如果覺得空間大了,可以指定大小,可以以柱面為單位,直接寫上20000,就表示分區(qū)是從10000到20000.
因?yàn)橐粋€(gè)柱面是8M,10000個(gè)柱面就是80000M,也就是80G。
更方便的寫法就是數(shù)字+存儲(chǔ)單位。+size{K,M,G}
設(shè)置分區(qū)是1G,那么直接寫上+1G即可
[root@centos65 ~]# fdisk   /dev/sda  
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
Command (m for help): n
First cylinder (9316-26109, default 9316): 10000
Last cylinder, +cylinders or +size{K,M,G} (10000-26109, default 26109): +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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6           10000       10131     1060290   83  Linux
劃分了131個(gè)柱面
為什么在上面劃分分區(qū)時(shí)不會(huì)詢問選擇什么樣的分區(qū)類型,是主分區(qū)還是擴(kuò)展分區(qū)邏輯分區(qū)呢?
因?yàn)?個(gè)分區(qū)已經(jīng)分完了,所以逼上梁山?jīng)]有選擇只能分邏輯分區(qū)。
繼續(xù)在硬盤上劃分分區(qū)
選擇默認(rèn)的9316
(9316-9999, default 9999)表示結(jié)束的柱面是9999,分區(qū)大小就是683個(gè)柱面的大小,也就是5464M,差不多5G
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6           10000       10131     1060290   83  Linux
Command (m for help): n
First cylinder (9316-26109, default 9316): 
Using default value 9316
Last cylinder, +cylinders or +size{K,M,G} (9316-9999, default 9999): +10G
Value out of range.因?yàn)榉謪^(qū)最大空間是5G左右。
Last cylinder, +cylinders or +size{K,M,G} (9316-9999, default 9999): 
接受默認(rèn)的,那么就只能劃分出5G左右的分區(qū)了。對(duì)此不滿就把此分區(qū)刪除重新創(chuàng)建
注意夾縫問題,也就是上面出現(xiàn)空間不足的問題。起始值和結(jié)束值要好好觀察,三思而后行。
分區(qū)一旦分好了就不能改變大小了,除非刪除重新創(chuàng)建。
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6           10000       10131     1060290   83  Linux
/dev/sda7            9316        9999     5488104+  83  Linux
Partition table entries are not in disk order
Command (m for help): d
Partition number (1-7): 7
Command (m for help): n
First cylinder (9316-26109, default 9316): 10132
Last cylinder, +cylinders or +size{K,M,G} (10132-26109, default 26109): +10G
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6           10000       10131     1060290   83  Linux
/dev/sda7           10132       11437    10490413+  83  Linux
把第6分區(qū)刪除了,那么第7分區(qū)就變成6了
說明了分區(qū)的設(shè)備標(biāo)識(shí)是不穩(wěn)定的
這樣就會(huì)在磁盤上涉及到分區(qū)配置文件的修改產(chǎn)生問題。
刪除了分區(qū)設(shè)備名就變了。
創(chuàng)建完文件系統(tǒng)之后有生成UUID,是唯一穩(wěn)定不變的。
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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris /dev/sda6 10000 10131 1060290 83 Linux /dev/sda7 10132 11437 10490413+ 83 Linux Command (m for help): d Partition number (1-7): 6 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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris /dev/sda6 10132 11437 10490413+ 83 Linux
把第6分區(qū)刪除了,繼續(xù)創(chuàng)建分區(qū)
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6           10132       11437    10490413+  83  Linux
Command (m for help): d
Partition number (1-6): 6
Command (m for help): n
First cylinder (9316-26109, default 9316):    
Using default value 9316
Last cylinder, +cylinders or +size{K,M,G} (9316-26109, default 26109): +10G
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6            9316       10621    10484351   83  Linux
再創(chuàng)建分區(qū)
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6            9316       10621    10484351   83  Linux
Command (m for help): n
First cylinder (10622-26109, default 10622): 
Using default value 10622
Last cylinder, +cylinders or +size{K,M,G} (10622-26109, default 26109): +6G
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6            9316       10621    10484351   83  Linux
/dev/sda7           10622       11405     6297448+  83  Linux
7在6版本上存盤
存盤。
出現(xiàn)了報(bào)錯(cuò),重讀分區(qū)表失敗了,也就是從磁盤同步到內(nèi)存里時(shí)失敗了。
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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris /dev/sda6 9316 10621 10484351 83 Linux /dev/sda7 10622 11405 6297448+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
查看磁盤和內(nèi)存的分區(qū)
查看磁盤的分區(qū)表只有1種方法:
[root@centos65 ~]# fdisk /dev/sda -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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris /dev/sda6 9316 10621 10484351 83 Linux /dev/sda7 10622 11405 6297448+ 83 Linux
下面的查看內(nèi)存分區(qū)表的3種方法:
[root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
[root@centos65 ~]# cat /proc/partitions major minor #blocks name 8 0 209715200 sda 8 1 1048576 sda1 8 2 51200000 sda2 8 3 20480000 sda3 8 4 1 sda4 8 5 2097152 sda5 8 16 104857600 sdb 8 32 83886080 sdc 8 48 62914560 sdd
查看硬盤設(shè)備名稱: [root@centos65 ~]# ls /dev/sda* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
五在不同版本上同步分區(qū)表
注意在不同版本上是不同的。
查看內(nèi)核是否已經(jīng)識(shí)別新的分區(qū):
cat /proc/partations
centos6通知內(nèi)核重新讀取硬盤分區(qū)表
新增分區(qū)用
partx -a /dev/DEVICE
kpartx -a /dev/DEVICE -f: force
刪除分區(qū)用
partx -d --nr M-N /dev/DEVICE
CentOS 5,7: 使用partprobe
partprobe [/dev/DEVICE]
1在6版本上同步增加的分區(qū)表
通過上面查看磁盤和內(nèi)存的分區(qū)不同步,這樣就無法管理新創(chuàng)建的分區(qū)了。
注意在生產(chǎn)中雖然重啟服務(wù)可以實(shí)現(xiàn)同步,但是機(jī)器啟動(dòng)是很慢的,這樣就會(huì)給企業(yè)或公司帶來很大的損失。
要實(shí)現(xiàn)同步可以使用partprobe,但是在6上不生效,適合5和7版本。
[root@centos65 ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Error: Invalid partition table - recursive partition on /dev/sr0. [root@centos65 ~]# ls /dev/sda* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 [root@centos65 ~]# cat /proc/partitions major minor #blocks name 8 0 209715200 sda 8 1 1048576 sda1 8 2 51200000 sda2 8 3 20480000 sda3 8 4 1 sda4 8 5 2097152 sda5 8 16 104857600 sdb 8 32 83886080 sdc 8 48 62914560 sdd
在6上同步就比較麻煩,要先考慮是增加分區(qū)還是刪除分區(qū)造成不同步的
如果是增加就使用partx -a
[root@centos65 ~]# 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@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 2G 0 part [SWAP] ├─sda6 8:6 0 10G 0 part └─sda7 8:7 0 6G 0 part sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk
2在6版本上同步刪除的分區(qū)表
刪除剛才創(chuàng)建的分區(qū)。
在6上如果是因?yàn)閯h除分區(qū)造成不同步就使用partx -d --nr M-N /dev/DEVICE
[root@centos65 ~]# fdisk   /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
/dev/sda6            9316       10621    10484351   83  Linux
/dev/sda7           10622       11405     6297448+  83  Linux
Command (m for help): d
Partition number (1-7): 7  
Command (m for help): d
Partition number (1-6): 6
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0    2G  0 part [SWAP]
├─sda6   8:6    0   10G  0 part 
└─sda7   8:7    0    6G  0 part 
sdb      8:16   0  100G  0 disk 
sdc      8:32   0   80G  0 disk 
sdd      8:48   0   60G  0 disk 
[root@centos65 ~]# fdisk   /dev/sda  -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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
刪除分區(qū)用partx -d --nr  M-N  /dev/DEVICE
也可以一個(gè)個(gè)同步partx -d  --nr  M  /dev/DEVICE
[root@centos65 ~]# partx -d --nr 6-7 /dev/sda [root@centos65 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom /mnt sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 48.8G 0 part / ├─sda3 8:3 0 19.5G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sdc 8:32 0 80G 0 disk sdd 8:48 0 60G 0 disk [root@centos65 ~]# fdisk /dev/sda -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: 0x0000c75a Device Boot Start End Blocks Id System /dev/sda1 * 1 131 1048576 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 131 6505 51200000 83 Linux /dev/sda3 6505 9055 20480000 83 Linux /dev/sda4 9055 26109 136985600 5 Extended /dev/sda5 9055 9316 2097152 82 Linux swap / Solaris
3在7版本上同步分區(qū)表
在7上創(chuàng)建新的分區(qū)并且實(shí)現(xiàn)同步
First sector (153098240-419430399, default 153098240):
為什么默認(rèn)從153098240開始進(jìn)行分區(qū),而不是153096191?
因?yàn)橹g的空間存儲(chǔ)了分區(qū)的一些信息,比如MBR,EBR
[root@centos72 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c7076 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 106956799 52428800 83 Linux /dev/sda3 106956800 148899839 20971520 83 Linux /dev/sda4 148899840 419430399 135265280 5 Extended /dev/sda5 148901888 153096191 2097152 82 Linux swap / Solaris Command (m for help): n All primary partitions are in use Adding logical partition 6 First sector (153098240-419430399, default 153098240):
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c7076
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   106956799    52428800   83  Linux
/dev/sda3       106956800   148899839    20971520   83  Linux
/dev/sda4       148899840   419430399   135265280    5  Extended
/dev/sda5       148901888   153096191     2097152   82  Linux swap / Solaris
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (153098240-419430399, default 153098240): 
Using default value 153098240
Last sector, +sectors or +size{K,M,G} (153098240-419430399, default 419430399): +10G
Partition 6 of type Linux and of size 10 GiB is set
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c7076
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   106956799    52428800   83  Linux
/dev/sda3       106956800   148899839    20971520   83  Linux
/dev/sda4       148899840   419430399   135265280    5  Extended
/dev/sda5       148901888   153096191     2097152   82  Linux swap / Solaris
/dev/sda6       153098240   174069759    10485760   83  Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (174071808-419430399, default 174071808): 
Using default value 174071808
Last sector, +sectors or +size{K,M,G} (174071808-419430399, default 419430399): +6G
Partition 7 of type Linux and of size 6 GiB is set
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c7076
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   106956799    52428800   83  Linux
/dev/sda3       106956800   148899839    20971520   83  Linux
/dev/sda4       148899840   419430399   135265280    5  Extended
/dev/sda5       148901888   153096191     2097152   82  Linux swap / Solaris
/dev/sda6       153098240   174069759    10485760   83  Linux
/dev/sda7       174071808   186654719     6291456   83  Linux
Command (m for help): w注意使用w并不能夠?qū)崿F(xiàn)磁盤和內(nèi)存分區(qū)的同步
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos72 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   50G  0 part /
├─sda3   8:3    0   20G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
sr0     11:0    1  4.2G  0 rom  /mnt
partprobe 實(shí)現(xiàn)同步了
[root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sr0 11:0 1 4.2G 0 rom /mnt [root@centos72 ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 512B 0 part ├─sda5 8:5 0 2G 0 part [SWAP] ├─sda6 8:6 0 10G 0 part └─sda7 8:7 0 6G 0 part sdb 8:16 0 100G 0 disk sr0 11:0 1 4.2G 0 rom /mnt
把分區(qū)刪除了
[root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 512B 0 part ├─sda5 8:5 0 2G 0 part [SWAP] ├─sda6 8:6 0 10G 0 part └─sda7 8:7 0 6G 0 part sdb 8:16 0 100G 0 disk sr0 11:0 1 4.2G 0 rom /mnt [root@centos72 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c7076 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 106956799 52428800 83 Linux /dev/sda3 106956800 148899839 20971520 83 Linux /dev/sda4 148899840 419430399 135265280 5 Extended /dev/sda5 148901888 153096191 2097152 82 Linux swap / Solaris /dev/sda6 153098240 174069759 10485760 83 Linux /dev/sda7 174071808 186654719 6291456 83 Linux Command (m for help): d Partition number (1-7, default 7): 7 Partition 7 is deleted Command (m for help): d Partition number (1-6, default 6): 6 Partition 6 is deleted Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@centos72 ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@centos72 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 20G 0 part /app ├─sda4 8:4 0 512B 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 100G 0 disk sr0 11:0 1 4.2G 0 rom /mnt
六直接存盤立即生效的情況
如果是新的硬盤就不存在分區(qū)問題
注意如果是一臺(tái)主機(jī)的第1塊硬盤必須要有一個(gè)主分區(qū),但是對(duì)于第2塊硬盤就不需要了,主分區(qū)可有可無。
[root@centos65 ~]# fdisk   /dev/sdb 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
創(chuàng)建擴(kuò)展分區(qū),并且編號(hào)是1,因?yàn)閿U(kuò)展分區(qū)里面還要分很多的小的邏輯分區(qū),所以擴(kuò)展分區(qū)的空間是比較大的,
[root@centos65 ~]# fdisk   /dev/sdb 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-13054, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +50G
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
Command (m for help): 
現(xiàn)在出現(xiàn)了邏輯分區(qū),因?yàn)橹皠?chuàng)建了擴(kuò)展分區(qū)。出現(xiàn)邏輯分區(qū)的必要條件是已經(jīng)創(chuàng)建了擴(kuò)展分區(qū)。
創(chuàng)建邏輯分區(qū),只能是在擴(kuò)展分區(qū)的范圍里面分。
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-13054, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +50G
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1-6528, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6528, default 6528): +10G
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
/dev/sdb5               1        1306    10490382   83  Linux
創(chuàng)建主分區(qū)
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
/dev/sdb5               1        1306    10490382   83  Linux
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (6529-13054, default 6529): 
Using default value 6529
Last cylinder, +cylinders or +size{K,M,G} (6529-13054, default 13054): +5G
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
/dev/sdb2            6529        7182     5253255   83  Linux
/dev/sdb5               1        1306    10490382   83  Linux
Command (m for help): w   #注意此時(shí)是在干凈的硬盤上創(chuàng)建分區(qū),所以w可以同步成功,舊的硬盤因?yàn)橐呀?jīng)有分區(qū)就會(huì)同步失敗。
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
sdd      8:48   0   60G  0 disk 
七使用shell腳本批量創(chuàng)建分區(qū)
通過寫腳本批量創(chuàng)建分區(qū),就要分析前面創(chuàng)建分區(qū)的步驟。注意硬盤要求是還未分區(qū)的
使用腳本創(chuàng)建分區(qū)的情況在生產(chǎn)里面用的不多。
第1步:輸入n并且要回車,寫到命令行n
第2步:輸入p并且要回車,寫到命令行p
第2步:輸入1并且要回車,寫到命令行1
第3步:直接回車接收默認(rèn)值,寫到命令行1
第4步:+10G并且回車,寫到命令行+10G
第5步:輸入w并且回車,寫到命令行w
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
sdd      8:48   0   60G  0 disk 
[root@centos65 ~]# echo   -e     'n
p
1
+10G
w
'    |  fdisk   /dev/sdc
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): First cylinder (1-10443, default 1): Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): 
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
└─sdc1   8:33   0   10G  0 part 
sdd      8:48   0   60G  0 disk 
上面使用了標(biāo)準(zhǔn)輸入重定向,fdisk接收鍵盤輸入
還可以多行重定向
[root@centos65 ~]# fdisk   /dev/sdc  <<EOF
> n
> p
> 2
> 
> +6G
> w
> EOF
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): First cylinder (1307-10443, default 1307): Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-10443, default 10443): 
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
├─sdc1   8:33   0   10G  0 part 
└─sdc2   8:34   0    6G  0 part 
sdd      8:48   0   60G  0 disk 
對(duì)于舊硬盤就要在腳本后面加上partx -a /dev/sdc或者partprobe /dev/sdc
注意要學(xué)會(huì)總結(jié),遇到交互式命令比如fdisk是可以接收鍵盤輸入的的,那么就可以使用到重定向甚至多行重定向,并且寫入到腳本里面。
因?yàn)椴煌剑祷刂凳?
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
├─sdc1   8:33   0   10G  0 part 
└─sdc2   8:34   0    6G  0 part 
sdd      8:48   0   60G  0 disk 
[root@centos65 ~]# fdisk   /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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: 0x0000c75a
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        6505    51200000   83  Linux
/dev/sda3            6505        9055    20480000   83  Linux
/dev/sda4            9055       26109   136985600    5  Extended
/dev/sda5            9055        9316     2097152   82  Linux swap / Solaris
Command (m for help): n
First cylinder (9316-26109, default 9316): 
Using default value 9316
Last cylinder, +cylinders or +size{K,M,G} (9316-26109, default 26109): +1G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos65 ~]# echo   $?
1
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
├─sdc1   8:33   0   10G  0 part 
└─sdc2   8:34   0    6G  0 part 
sdd      8:48   0   60G  0 disk 
如果寫腳本就可以判斷是否同步
如果返回值不是0就要在后面加上同步的操作。
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
├─sdc1   8:33   0   10G  0 part 
└─sdc2   8:34   0    6G  0 part 
sdd      8:48   0   60G  0 disk 
[root@centos65 ~]# fdisk   /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000d8fb4
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        6528    52436128+   5  Extended
/dev/sdb2            6529        7182     5253255   83  Linux
/dev/sdb5               1        1306    10490382   83  Linux
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7183-13054, default 7183): 
Using default value 7183
Last cylinder, +cylinders or +size{K,M,G} (7183-13054, default 13054): +2G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos65 ~]# echo   $?
0
[root@centos65 ~]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  3.7G  0 rom  /mnt
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 19.5G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
├─sdb1   8:17   0    1K  0 part 
├─sdb2   8:18   0    5G  0 part 
├─sdb3   8:19   0    2G  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0   80G  0 disk 
├─sdc1   8:33   0   10G  0 part 
└─sdc2   8:34   0    6G  0 part 
sdd      8:48   0   60G  0 disk 
 
作者:wang618
 
出處:https://www.cnblogs.com/wang618/
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文鏈接,否則保留追究法律責(zé)任的權(quán)利。
總結(jié)
 
                            
                        - 上一篇: 虚拟机如何设置静态IP
- 下一篇: Defraggler磁盘碎片整理工具,让
