1.1 fdisk 磁盤分區工具
受mbr分區表限制,只能給小於2T的磁盤劃分分區,
語法:
[fdisk] [option] [device]
參數:
-l 顯示全部磁盤分區的信息
1.1 交互式分區實踐node
[root@lvs ~]# ls /dev/sd* [root@lvs ~]# fdisk /dev/sdb Command (m for help): m Command action Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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'). -c 提示使用-c關閉dos兼容模式 -u 提示-u 參數使用扇區爲單位分區 Command (m for help): m m 是幫助 Command action a toggle a bootable flag #設置引導分區 b edit bsd disklabel #編輯bsd分區 c toggle the dos compatibility flag #設置dos兼容扇區 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 #建立一個新的dos分區表 p print the partition table #打印分區表 q quit without saving changes #退出不保存更改 s create a new empty Sun disklabel #建立新的sun卷標 t change a partition's system id #更改分區系統id u change display/entry units #改變顯示/條目的單位 v verify the partition table #驗證分區表 w write table to disk and exit #將操做寫入分區表並退出程序 x extra functionality (experts only) #額外的功能 Command (m for help): n #新創建一個分區 Command action e extended 擴展分區 p primary partition (1-4) 建立主分區 p 建立一個主分區,須要人工輸入p後回車 Partition number (1-4): 1 設置主分區編號1 First cylinder (1-261083, default 1): 1G 設置柱起面,默認爲1 Last cylinder, +cylinders or +size{K,M,G} (1-261083, default 261083): 100G #設置結束柱面 Command (m for help): p 打印分過的分區表 Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes 255 heads, 63 sectors/track, 261083 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: 0xc4682775 Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux Command (m for help): n 再創建一個分區表 Command action e extended p primary partition (1-4) e 建立一個擴展分區 Partition number (1-4): 2 設置分區編號爲2 First cylinder (101-261083, default 101): Using default value 101 Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083): Using default value 261083 Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes 255 heads, 63 sectors/track, 261083 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: 0xc4682775 Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 261083 2096345947+ 5 Extended Command (m for help): n 再創建一個分區 Command action l logical (5 or over) 分了擴展分區,這裏自動變爲邏輯分區 p primary partition (1-4) p Partition number (1-4): 3 No free sectors available 不能再建立主分區,沒有磁盤空間了 Command (m for help): n 再新建一個分區 Command action l logical (5 or over) p primary partition (1-4) l 新創建一個邏輯分區 First cylinder (101-261083, default 101): Using default value 101 Last cylinder, +cylinders or +size{K,M,G} (101-261083, default 261083): 400G Command (m for help): p 打印分區表 Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes 255 heads, 63 sectors/track, 261083 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: 0xc4682775 Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 261083 2096345947+ 5 Extended /dev/sdb5 101 400 2409718+ 83 Linux Command (m for help): n 新創建一個分區 Command action l logical (5 or over) p primary partition (1-4) l 新創建一個邏輯分區 First cylinder (401-261083, default 401): 401 Last cylinder, +cylinders or +size{K,M,G} (401-261083, default 261083): Using default value 261083 Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes 255 heads, 63 sectors/track, 261083 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: 0xc4682775 Device Boot Start End Blocks Id System /dev/sdb1 1 100 803218+ 83 Linux /dev/sdb2 101 261083 2096345947+ 5 Extended /dev/sdb5 101 400 2409718+ 83 Linux /dev/sdb6 401 261083 2093936166 83 Linux Command (m for help): w 將操做寫入分區表生效並退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@lvs ~]# ls /dev/sd* 查看分區後的狀態 /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6 /dev/sdc [root@lvs ~]# partprobe /dev/sdb 執行該命令通知內核分區表已經更改,此部是不重啓讓分區表生效的命令 [root@lvs ~]# 1.2格式化磁盤 [root@lvs ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 50288 inodes, 200804 blocks 10040 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=209715200 7 block groups 32768 blocks per group, 32768 fragments per group 7184 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 執行這個命令能夠避免磁盤掛自動檢查磁盤。 1.3掛載磁盤分區 [root@lvs ~]# df -h 顯示磁盤使用的狀況 Filesystem Size Used Avail Use% Mounted on /dev/sda2 79G 3.4G 71G 5% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 194M 29M 155M 16% /boot [root@lvs ~]# mount /dev/sdb1 /mnt磁盤只能掛了才能使用,將磁盤掛載到/mnt下 [root@lvs ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 79G 3.4G 71G 5% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 194M 29M 155M 16% /boot /dev/sdb1 773M 17M 717M 3% /mnt [root@lvs ~]# vim /etc/fstab /dev/sdb1 /mnt ext4 defaults 0 0
在用交互指令d刪除分區時要當心,看好分區的序號,若是刪除了擴展分區,那麼擴展分區之下的邏輯分區都會被刪除,所在在操做時要當心,若是不當心刪除錯誤,按q退出,這樣以前的操做就會失效,若是輸入(w保存指令)則會保存全部修改vim