Linux 磁盤管理

安裝Linux的第一步就是創建磁盤系統,而創建系統主要分爲成兩個步驟:

1. 創建分區,2.創建文件系統

創建分區:

常用三個命令fdisk,parted

fdisk:是最常用的

限制:

1. fdisk不支持gpt磁盤, 也就是說它不能劃分大於2T的分區 (例如下圖)

2. 最多劃分15個分區

# fdisk /dev/sdb
 
Warning: invalid flag 0x0000 of partition table 4 willbe corrected by w(rite)
 
WARNING: The size of this disk is 5.9 TB (5908688535552bytes).
DOS partition table format can not be used on drivesfor volumes
larger than (2199023255040 bytes) for 512-byte sectors.Use parted(1) and GUID
partition table format (GPT).


如果需要劃分大於2T的分區,需要用到命令parted下文會有介紹

我們通過下面的例子來劃分個新的分區並且介紹一些常用參數

  1. 查看系統上說有可識別的磁盤, 通過grep命令來過濾所有磁盤信息.

[root@centos~]# fdisk -l | grep "Disk /dev/sd.*"
Disk/dev/sda: 53.7 GB, 53687091200 bytes
Disk/dev/sdb: 21.5 GB, 21474836480 bytes

 

 2.選擇要分區的硬盤

[root@centos ~]# fdisk /dev/sdb
 
WARNING: DOS-compatible mode is deprecated. It'sstrongly recommended to
         switchoff the mode (command 'c') and change display units to
         sectors(command 'u').
 
Command (m for help):

 

3.      依次通過命令n(創建一個新的分區), 4(選擇第幾個分區), +500M(這個分區大小爲500M),w(存儲並且退出)

在輸入w前可以用p命令查看結果,如果不滿意可以直接q退出而不用保存.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (147-2610, default 147): 4
Value out of range.
First cylinder (147-2610, default 147):
Using default value 147
Last cylinder, +cylinders or +size{K,M,G} (147-2610,default 2610): +500M
 
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 witherror 16: Device or resource busy.
The kernel still uses the old table. The new table willbe used at
the next reboot or after you run partprobe(8) orkpartx(8)
Syncing disks.

 

parted命令

查看所有當前分區

[root@centos ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list ofcommands.
(parted) print                                                           
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number Start   End     Size  Type     File system  Flags
 1      32.3kB 115MB   115MB  primary ext4
 2      115MB  658MB   543MB  primary ext4
 3      658MB  1201MB  543MB  primary ext3
 4      1201MB 1736MB  535MB  primary

改變顯示單位爲TB

(parted) unit TB

 

格式化的時候一定要先上一步print出來,這樣就知道從哪裏開始格式化.

(parted) mkpartfs                                                        
WARNING: you are attempting to use parted to operate on(mkpartfs) a file system.
parted's file system manipulation code is not as robustas what you'll find in
dedicated, file-system-specific packages likee2fsprogs.  We recommend
you use parted only to manipulate partition tables,whenever possible.
Support for performing most operations on most types offile systems
will be removed in an upcoming release.
Partition type? primary/extended? primary                               
File system type? [ext2]?                                               
Start? 17367
End? 18367                                                                
Warning: WARNING: the kernel failed to re-read thepartition table on /dev/sdb (Device or resource
busy).  As aresult, it may not reflect all of your changes until after reboot.

 

創建文件系統,

我們可以用–t ext2 ext3 來選擇格式化成不同的文件類型

[root@centos ~]# mke2fs -t ext4 /dev/sdb3

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章