1.使用fdisk創建6個分區[1P+1E(5L)] //dev/sdb1 /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8 /deb/sdb9 1 [root@server ~]# fdisk -l 2 3 Disk /dev/sda: 8589 MB, 8589.....
1.使用fdisk創建6個分區[1P+1E(5L)] //dev/sdb1 /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8 /deb/sdb9
1 [root@server ~]# fdisk -l 2 3 Disk /dev/sda: 8589 MB, 8589934592 bytes 4 255 heads, 63 sectors/track, 1044 cylinders 5 Units = cylinders of 16065 * 512 = 8225280 bytes 6 Sector size (logical/physical): 512 bytes / 512 bytes 7 I/O size (minimum/optimal): 512 bytes / 512 bytes 8 Disk identifier: 0x000aec72 9 10 Device Boot Start End Blocks Id System 11 /dev/sda1 * 1 26 204800 83 Linux 12 Partition 1 does not end on cylinder boundary. 13 /dev/sda2 26 91 524288 82 Linux swap / Solaris 14 Partition 2 does not end on cylinder boundary. 15 /dev/sda3 91 1045 7658496 83 Linux 16 17 Disk /dev/sdb: 1073 MB, 1073741824 bytes 18 255 heads, 63 sectors/track, 130 cylinders 19 Units = cylinders of 16065 * 512 = 8225280 bytes 20 Sector size (logical/physical): 512 bytes / 512 bytes 21 I/O size (minimum/optimal): 512 bytes / 512 bytes 22 Disk identifier: 0x00000000
2.fdisk -cu /dev/sdb開始分區
1 [root@server ~]# fdisk -cu /dev/sdb //-c:表示丟棄DOS相容模式,切換到mode模式; -u:表示從柱面分區改為扇區分區 2 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel 3 Building a new DOS disklabel with disk identifier 0x94c5ab35. 4 Changes will remain in memory only, until you decide to write them. 5 After that, of course, the previous content won't be recoverable. 6 7 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 8 9 Command (m for help):
3.輸入m查看幫助
1 Command (m for help): m 2 Command action 3 a toggle a bootable flag 4 b edit bsd disklabel 5 c toggle the dos compatibility flag 6 d delete a partition //刪除創建的分區 7 l list known partition types //列出分區類型 8 m print this menu //查看幫助 9 n add a new partition //創建新分區 10 o create a new empty DOS partition table 11 p print the partition table //列印分區表 12 q quit without saving changes 13 s create a new empty Sun disklabel 14 t change a partition's system id 15 u change display/entry units 16 v verify the partition table 17 w write table to disk and exit //寫入分區表保存 18 x extra functionality (experts only) 19 20 Command (m for help):
4.分出一個10M的主分區
1 Command (m for help): n 2 Command action 3 e extended //代表擴展分區 4 p primary partition (1-4) //代表主分區 5 p //選擇p 主分區 6 Partition number (1-4): 1 7 First sector (2048-2097151, default 2048): //預設2048開始 8 Using default value 2048 9 Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +10M 10 11 Command (m for help): p 12 13 Disk /dev/sdb: 1073 MB, 1073741824 bytes 14 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 15 Units = sectors of 1 * 512 = 512 bytes 16 Sector size (logical/physical): 512 bytes / 512 bytes 17 I/O size (minimum/optimal): 512 bytes / 512 bytes 18 Disk identifier: 0x94c5ab35 19 20 Device Boot Start End Blocks Id System 21 /dev/sdb1 2048 22527 10240 83 Linux
5.將剩餘的空間全部分配給擴展分區
1 Command (m for help): n 2 Command action 3 e extended 4 p primary partition (1-4) 5 e 6 Partition number (1-4): 2 //分區編號選擇為2 7 First sector (22528-2097151, default 22528): //預設預設大小 8 Using default value 22528 9 Last sector, +sectors or +size{K,M,G} (22528-2097151, default 2097151): //預設預設大小 10 Using default value 2097151 11 12 Command (m for help): p //列印 13 14 Disk /dev/sdb: 1073 MB, 1073741824 bytes 15 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 16 Units = sectors of 1 * 512 = 512 bytes 17 Sector size (logical/physical): 512 bytes / 512 bytes 18 I/O size (minimum/optimal): 512 bytes / 512 bytes 19 Disk identifier: 0x94c5ab35 20 21 Device Boot Start End Blocks Id System 22 /dev/sdb1 2048 22527 10240 83 Linux 23 /dev/sdb2 22528 2097151 1037312 5 Extended 24 25 Command (m for help): n
6.接著將擴展分區分成5個邏輯分區,首先創建第1個大小為10M的邏輯分區
1 Command (m for help): n 2 Command action 3 l logical (5 or over) 4 p primary partition (1-4) 5 l //選擇創建邏輯分區 6 First sector (24576-2097151, default 24576): //預設開始直接回車 7 Using default value 24576 8 Last sector, +sectors or +size{K,M,G} (24576-2097151, default 2097151): +10M //輸入分區大小10M 9 10 Command (m for help): p //列印分區 11 12 Disk /dev/sdb: 1073 MB, 1073741824 bytes 13 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 14 Units = sectors of 1 * 512 = 512 bytes 15 Sector size (logical/physical): 512 bytes / 512 bytes 16 I/O size (minimum/optimal): 512 bytes / 512 bytes 17 Disk identifier: 0x94c5ab35 18 19 Device Boot Start End Blocks Id System 20 /dev/sdb1 2048 22527 10240 83 Linux 21 /dev/sdb2 22528 2097151 1037312 5 Extended 22 /dev/sdb5 24576 45055 10240 83 Linux //分區表從5開始,代表邏輯分區
7.接著創建擴展分區中第2個大小為10M的邏輯分區
1 Command (m for help): n 2 Command action 3 l logical (5 or over) 4 p primary partition (1-4) 5 l 6 First sector (47104-2097151, default 47104): 7 Using default value 47104 8 Last sector, +sectors or +size{K,M,G} (47104-2097151, default 2097151): +10M 9 10 Command (m for help): p 11 12 Disk /dev/sdb: 1073 MB, 1073741824 bytes 13 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 14 Units = sectors of 1 * 512 = 512 bytes 15 Sector size (logical/physical): 512 bytes / 512 bytes 16 I/O size (minimum/optimal): 512 bytes / 512 bytes 17 Disk identifier: 0x94c5ab35 18 19 Device Boot Start End Blocks Id System 20 /dev/sdb1 2048 22527 10240 83 Linux 21 /dev/sdb2 22528 2097151 1037312 5 Extended 22 /dev/sdb5 24576 45055 10240 83 Linux 23 /dev/sdb6 47104 67583 10240 83 Linux
8.接著創建擴展分區中第3個大小為10M的邏輯分區
1 Command (m for help): n 2 Command action 3 l logical (5 or over) 4 p primary partition (1-4) 5 l 6 First sector (69632-2097151, default 69632): 7 Using default value 69632 8 Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 9 2^N: K (KibiByte), M (MebiByte), G (GibiByte) 10 Last sector, +sectors or +size{K,M,G} (69632-2097151, default 2097151): = 11 Last sector, +sectors or +size{K,M,G} (69632-2097151, default 2097151): +10M 12 13 Command (m for help): p 14 15 Disk /dev/sdb: 1073 MB, 1073741824 bytes 16 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 17 Units = sectors of 1 * 512 = 512 bytes 18 Sector size (logical/physical): 512 bytes / 512 bytes 19 I/O size (minimum/optimal): 512 bytes / 512 bytes 20 Disk identifier: 0x94c5ab35 21 22 Device Boot Start End Blocks Id System 23 /dev/sdb1 2048 22527 10240 83 Linux 24 /dev/sdb2 22528 2097151 1037312 5 Extended 25 /dev/sdb5 24576 45055 10240 83 Linux 26 /dev/sdb6 47104 67583 10240 83 Linux 27 /dev/sdb7 69632 90111 10240 83 Linux
9.接著創建擴展分區中第4個大小為10M的邏輯分區
1 Command (m for help): n 2 Command action 3 l logical (5 or over) 4 p primary partition (1-4) 5 l 6 First sector (92160-2097151, default 92160): 7 Using default value 92160 8 Last sector, +sectors or +size{K,M,G} (92160-2097151, default 2097151): +10M 9 10 Command (m for help): p 11 12 Disk /dev/sdb: 1073 MB, 1073741824 bytes 13 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 14 Units = sectors of 1 * 512 = 512 bytes 15 Sector size (logical/physical): 512 bytes / 512 bytes 16 I/O size (minimum/optimal): 512 bytes / 512 bytes 17 Disk identifier: 0x94c5ab35 18 19 Device Boot Start End Blocks Id System 20 /dev/sdb1 2048 22527 10240 83 Linux 21 /dev/sdb2 22528 2097151 1037312 5 Extended 22 /dev/sdb5 24576 45055 10240 83 Linux 23 /dev/sdb6 47104 67583 10240 83 Linux 24 /dev/sdb7 69632 90111 10240 83 Linux 25 /dev/sdb8 92160 112639 10240 83 Linux
10.接著創建擴展分區中第5個邏輯分區,將剩餘空間都分配
1 Command (m for help): n 2 Command action 3 l logical (5 or over) 4 p primary partition (1-4) 5 l 6 First sector (114688-2097151, default 114688): 7 Using default value 114688 8 Last sector, +sectors or +size{K,M,G} (114688-2097151, default 2097151): 9 Using default value 2097151 10 11 Command (m for help): p 12 13 Disk /dev/sdb: 1073 MB, 1073741824 bytes 14 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 15 Units = sectors of 1 * 512 = 512 bytes 16 Sector size (logical/physical): 512 bytes / 512 bytes 17 I/O size (minimum/optimal): 512 bytes / 512 bytes 18 Disk identifier: 0x94c5ab35 19 20 Device Boot Start End Blocks Id System 21 /dev/sdb1 2048 22527 10240 83 Linux 22 /dev/sdb2 22528 2097151 1037312 5 Extended 23 /dev/sdb5 24576 45055 10240 83 Linux 24 /dev/sdb6 47104 67583 10240 83 Linux 25 /dev/sdb7 69632 90111 10240 83 Linux 26 /dev/sdb8 92160 112639 10240 83 Linux 27 /dev/sdb9 114688 2097151 991232 83 Linux
11.將/dev/sdb9改為LVM分區(即動態調整)
1 Command (m for help): t 2 Partition number (1-9): 9 //要修改的分區標識 3 Hex code (type L to list codes): 8e //代表LVM,可用l查詢對應的Id 4 Changed system type of partition 9 to 8e (Linux LVM) 5 6 Command (m for help): p 7 8 Disk /dev/sdb: 1073 MB, 1073741824 bytes 9 255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors 10 Units = sectors of 1 * 512 = 512 bytes 11 Sector size (logical/physical): 512 bytes / 512 bytes 12 I/O size (minimum/optimal): 512 bytes / 512 bytes 13 Disk identifier: 0x94c5ab35 14 15 Device Boot Start End Blocks Id System 16 /dev/sdb1 2048 22527 10240 83 Linux 17 /dev/sdb2 22528 2097151 1037312 5 Extended 18 /dev/sdb5 24576 45055 10240 83 Linux 19 /dev/sdb6 47104 67583 10240 83 Linux 20 /dev/sdb7 69632 90111 10240 83 Linux 21 /dev/sdb8 92160 112639 10240 83 Linux 22 /dev/sdb9 114688 2097151 991232 8e Linux LVM
12.分區結尾工作
1 Command (m for help): w //寫入分區表 2 The partition table has been altered! 3 4 Calling ioctl() to re-read partition table. 5 Syncing disks. 6 [root@server ~]# partprobe /dev/sdb //將分區表的修改結果告訴內核,這樣可用忽略重啟系統
至此分區工作結束!!