日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

磁盘管理之管理分区

發布時間:2023/12/29 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 磁盘管理之管理分区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

管理分區

列出塊設備
lsblk

創建分區使用:
fdisk 創建MBR分區
gdisk 創建GPT分區
parted 高級分區操作
partprobe-重新設置內存中的內核分區表版本

一查看分區

1查看內存上的分區

看到數字出現了就說明是硬盤已經分區并且生效了,生效就是保存在內存里了。

分區表在兩個地方有,磁盤和內存。下面的命令查看到的內容是來自內存。

只有內存里面保存了內存才可以對硬盤的數據處理,而如果只是放到硬盤上就無法處理了。

磁盤包括硬盤,是樹林和樹的關系。

法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種方法顯示的內容都是一樣,因為都是來自內存的分區表。

對磁盤上的文件進行修改都是先讀取到內存中,在內存里面修改

當使用vim編輯器時修改文件就要w才可以保存在磁盤上。

dd命令是直接在磁盤上把數據修改了,所以內存分區表和磁盤分區表有可能就不同步了。

2查看磁盤上的分區

以第1塊硬盤為例:

255 heads, 63 sectors/track, 26108 cylinders從這里就可以看出是CSH結構,也就是使用了MBR分區類型,這是默認的。

表示255個虛擬磁頭,63個扇區/磁道,26108個柱面。

Units = cylinders of 16065 * 512 = 8225280 bytes 一個柱面的大小

Sector size (logical/physical): 512 bytes / 512 bytes 一個扇區的字節數

I/O size (minimum/optimal): 512 bytes / 512 bytes 每次讀寫的字節數

Device表示硬盤上面的分區,可以看到有5個分區。

*表示此分區為啟動分區,Start 表示開始的柱面,End表示結束的柱面

Blocks表示塊數量,Id表示分區類型ID,System表示分區類型

[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的分區表,512字節無法克隆數據。

硬盤沒有分區就沒有分區類型

二分區工具parted的使用

parted是一個磁盤分區和分區大小調整程序。

它允許你創建,銷毀,調整大小,移動和復制ext2、linux-swap、FAT、FAT32和reiserfs分區。

它可以創建,調整大小,并移動Macintosh HFS parti-以及檢測jfs、ntfs、ufs和xfs分區。它有助于為新操作創建空間系統,重新組織磁盤使用,并將數據復制到新的硬盤。

注意parted的操作都是實時生效的,小心使用

用法:parted [選項]... [設備 [命令 [參數]...]...]

parted /dev/sdb mklabel gpt|msdos

parted /dev/sdb print

parted /dev/sdb mkpart primary 1 200 (默認M)
parted /dev/sdb rm 1
parted -l

1顯示幫助

注意是交互式的,輸入help顯示了幫助內容

[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創建分區表,定義分區類型

mklabel,mktable LABEL-TYPE create a new disklabel (partition table)

parted /dev/sdb mklabel gpt|msdos

msdos就是MBR分區。

[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兼容模式。強烈推薦

關閉模式(命令“c”)并將顯示單元更改為扇區(命令“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分區類型

注意GPT分區和MBR是不能兼容的,也不能轉換。

[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 

出現警告,因為fdisk只支持對小于2TB的磁盤進行分區

[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'上檢測到GPT (GUID分區表)!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上就沒有警報,因為使用MBR分區

[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上創建分區,分區大小為1000M

在前面已經指定為GPT分區類型了

                    
[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.

創建了分區之后就同步到內存的分區表里面了

[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 

創建的不合適,可以刪除

[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代表分區的序號

[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查看或者創建MBR分區,在使用parted刪除了分區之后要重新指定類型

[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

內存也把分區刪除了

[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 

三分區工具gdisk的使用

類fdisk 的GPT分區工具

使用gdisk對分區進行管理

1顯示幫助

和parted一樣是交互式的

報警,是因為剛才設置成了MBR分區類型

[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!
***************************************************************

發現無效的GPT和有效的MBR;將MBR轉換為GPT格式

在內存中。這個操作具有潛在的破壞性!

如果不希望轉換MBR分區,請鍵入“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打印分區表

p print the partition table

現在沒有分區

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創建分區,分區類型為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類型的也會顯示,但是會警告

[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創建分區

在sdb上創建新分區

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

會顯示默認要創建的分區,default 2

比如已經創建了第1個分區,那么就會顯示默認創建第2個分區,也可以自定義。

First sector (34-209715166, default = 1953792) or {+-}size{KMGTP}: 這個表示開始的扇區

顯示扇區的位置,和前面的分區有關,默認是從前1個分區的下1個扇劃分default = 1953792。

創建分區的開始扇區也可以使用括號里面的扇區,從34開始,但是最多只能到2047,因為第1個分區的扇區是從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

使用默認的直接回車即可,接著就顯示結束扇區

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表示結束扇區的最大范圍,也就把所有的空間都分光了。

Last sector (1953792-209715166, default = 209715166) or {+-}size{KMGTP}:

這個最好不要選擇默認,因為默認是以扇區為單位的,所以直接指定分區的空間大小會更方便,不過要寫上數據存儲單位。

+1G表示的是從前一個分區的最后一個扇區開始增加1G大小的分區。

-表示往前面的扇區劃分,因為被其他分區占用分不了,+表示往后面的扇區劃分。

下面顯示的是標簽,提醒一下是做什么的。

回車就是選擇默認

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存盤退出

注意不論是刪除和增加都要存盤才會使結果生效

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刪除分區

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查看高級選項

高級選項

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

四分區工具fdisk的使用

fdisk的子命令,和sed一樣,也是有子命令的

1查看幫助

顯示報警是因為之前使用的是GPT分區類型

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

修改分區表類型,修改成fdisk支持的MBR

即使把分區刪除了,分區結構或者分區表類型還是之前的GPT或者MBR。

要想修改原來的分區表類型可以使用mklabel,這樣之前的分區類型就會被替換了。

[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

現在轉換成了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查看分區

[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表示的是以柱面為單位劃分分區,可以修改成以扇區為單位

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關閉dos兼容模式

下面顯示的是以柱面為單位的。

不在柱面的邊界會出現報警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

如果不想看到報警信息加上c,也就關閉了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上修改分區單位

修改成了扇區單位

不想看到報警信息加上c,關閉了dos兼容模式,而且以扇區為單位劃分的就加上u,兩個選項可以合并寫

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

通過柱面的數量計算出分區的大小,比如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版本修改分區單位

劃分分區是以柱面還是扇區看個人習慣,扇區是最小單位,感覺細了些。

在7里面fdisk默認就是以扇區的方式

在虛擬機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

如果硬盤沒有顯示就只能重啟服務了

[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上只顯示扇區,相當于默認就加上了cu選項

[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只顯示扇區
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc4a044a6

   Device Boot      Start         End      Blocks   Id  System

在6上不僅顯示扇區還顯示柱面,磁頭

[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

現在轉換成了以柱面為單位了

[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

注意選項只要不是加在命令前面就有效

[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版本的硬盤上創建分區

在6版本的sda硬盤上創建分區

[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屬于擴展分區的一部分,擴展分區的范圍是9055-26109,所以9316之后的內容是在擴展分區里面。

注意4個分區已經分出來了,最后一個是擴展分區。要創建新分區只能在這4個分區里面分。

可以跳過9316,從1000開始,那么9316-10000之間的柱面是閑置的。

接著是柱面的結束位置,默認到最后,如果覺得空間大了,可以指定大小,可以以柱面為單位,直接寫上20000,就表示分區是從10000到20000.

因為一個柱面是8M,10000個柱面就是80000M,也就是80G。

更方便的寫法就是數字+存儲單位。+size{K,M,G}

設置分區是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個柱面

為什么在上面劃分分區時不會詢問選擇什么樣的分區類型,是主分區還是擴展分區邏輯分區呢?

因為4個分區已經分完了,所以逼上梁山沒有選擇只能分邏輯分區。

繼續在硬盤上劃分分區

選擇默認的9316

(9316-9999, default 9999)表示結束的柱面是9999,分區大小就是683個柱面的大小,也就是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.因為分區最大空間是5G左右。
Last cylinder, +cylinders or +size{K,M,G} (9316-9999, default 9999): 

接受默認的,那么就只能劃分出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
/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分區刪除了,那么第7分區就變成6了

說明了分區的設備標識是不穩定的

這樣就會在磁盤上涉及到分區配置文件的修改產生問題。

刪除了分區設備名就變了。

創建完文件系統之后有生成UUID,是唯一穩定不變的。

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分區刪除了,繼續創建分區

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

再創建分區

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版本上存盤

存盤。

出現了報錯,重讀分區表失敗了,也就是從磁盤同步到內存里時失敗了。

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.

查看磁盤和內存的分區

查看磁盤的分區表只有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

下面的查看內存分區表的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


查看硬盤設備名稱: [root@centos65 ~]# ls /dev/sda* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5

五在不同版本上同步分區表

注意在不同版本上是不同的。

查看內核是否已經識別新的分區:
cat /proc/partations

centos6通知內核重新讀取硬盤分區表
新增分區用
partx -a /dev/DEVICE
kpartx -a /dev/DEVICE -f: force

刪除分區用
partx -d --nr M-N /dev/DEVICE
CentOS 5,7: 使用partprobe
partprobe [/dev/DEVICE]

1在6版本上同步增加的分區表

通過上面查看磁盤和內存的分區不同步,這樣就無法管理新創建的分區了。

注意在生產中雖然重啟服務可以實現同步,但是機器啟動是很慢的,這樣就會給企業或公司帶來很大的損失。

要實現同步可以使用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上同步就比較麻煩,要先考慮是增加分區還是刪除分區造成不同步的

如果是增加就使用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版本上同步刪除的分區表

刪除剛才創建的分區。

在6上如果是因為刪除分區造成不同步就使用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

刪除分區用partx -d --nr M-N /dev/DEVICE
也可以一個個同步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版本上同步分區表

在7上創建新的分區并且實現同步

First sector (153098240-419430399, default 153098240):

為什么默認從153098240開始進行分區,而不是153096191?

因為之間的空間存儲了分區的一些信息,比如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并不能夠實現磁盤和內存分區的同步
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 實現同步了

[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

把分區刪除了

[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

六直接存盤立即生效的情況

如果是新的硬盤就不存在分區問題

注意如果是一臺主機的第1塊硬盤必須要有一個主分區,但是對于第2塊硬盤就不需要了,主分區可有可無。

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

創建擴展分區,并且編號是1,因為擴展分區里面還要分很多的小的邏輯分區,所以擴展分區的空間是比較大的,

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

現在出現了邏輯分區,因為之前創建了擴展分區。出現邏輯分區的必要條件是已經創建了擴展分區。

創建邏輯分區,只能是在擴展分區的范圍里面分。

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

創建主分區

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   #注意此時是在干凈的硬盤上創建分區,所以w可以同步成功,舊的硬盤因為已經有分區就會同步失敗。
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腳本批量創建分區

通過寫腳本批量創建分區,就要分析前面創建分區的步驟。注意硬盤要求是還未分區的

使用腳本創建分區的情況在生產里面用的不多。

第1步:輸入n并且要回車,寫到命令行n

第2步:輸入p并且要回車,寫到命令行p

第2步:輸入1并且要回車,寫到命令行1

第3步:直接回車接收默認值,寫到命令行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 

上面使用了標準輸入重定向,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 

對于舊硬盤就要在腳本后面加上partx -a /dev/sdc或者partprobe /dev/sdc

注意要學會總結,遇到交互式命令比如fdisk是可以接收鍵盤輸入的的,那么就可以使用到重定向甚至多行重定向,并且寫入到腳本里面。

因為不同步,返回值是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 
[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/

本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接,否則保留追究法律責任的權利。

總結

以上是生活随笔為你收集整理的磁盘管理之管理分区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。