背景:
原服務器是windows操作系統的。在沒有進行格式化的情況下,重新安裝了linux系統。比如centos7后,磁盤該怎么格式化?以下是演示過程。
1. 查看磁盤情況:
# fdisk -l

2. 分析目前分區情況
/dev/sdb1 * 4096 629153791 314574848 7 HPFS/NTFS/exFAT
/dev/sdb2 629153792 1953523711 662184960 f W95 Ext'd (LBA)
/dev/sdb5 629157888 1291862015 331352064 7 HPFS/NTFS/exFAT
/dev/sdb6 1291866112 1953523711 330828800 7 HPFS/NTFS/exFAT
HPFS/NTFS/exFAT:屬於windows支持的文件系統。在使用u盤安裝centos操作系統的時候,留下的文件:

centos7.0開始默認文件系統是xfs。xfs是一種非常優秀的日志文件系統,它是SGI公司設計的。xfs被稱為業界最先進的、最具可升級性的文件系統技術。xfs是一個64位文件系統,最大支持8EB減1字節的單個文件系統,實際部署時取決於宿主操作系統的最大塊限制。對於一個32位Linux系統,文件和文件系統的大小會被限制在16TB。xfs在很多方面確實做的比ext4好,ext4受限制於磁盤結構和兼容問題,可擴展性和scalability確實不如xfs,另外xfs經過很多年發展,各種鎖的細化做的也比較好。
關於ext4,ext3這些文件系統暫時就不多說了。接下來,我們要刪除這些分區,重新分區並且格式化。
3. 刪除不需要的分區:d 刪除指定分區
# fdisk /dev/sdb The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. 歡迎使用 fdisk (util-linux 2.23.2)。 更改將停留在內存中,直到您決定將更改寫入磁盤。 使用寫入命令前請三思。 命令(輸入 m 獲取幫助):m 命令操作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table 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) 命令(輸入 m 獲取幫助):p 磁盤 /dev/sdb:1000.2 GB, 1000204886016 字節,1953525168 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 4096 字節 I/O 大小(最小/最佳):4096 字節 / 4096 字節 磁盤標簽類型:dos 磁盤標識符:0x600451aa 設備 Boot Start End Blocks Id System /dev/sdb1 * 4096 629153791 314574848 7 HPFS/NTFS/exFAT /dev/sdb2 629153792 1953523711 662184960 f W95 Ext'd (LBA) /dev/sdb5 629157888 1291862015 331352064 7 HPFS/NTFS/exFAT /dev/sdb6 1291866112 1953523711 330828800 7 HPFS/NTFS/exFAT 命令(輸入 m 獲取幫助):d 1 分區號 (1,2,5,6,默認 6):1 分區 1 已刪除 命令(輸入 m 獲取幫助):d 分區號 (2,5,6,默認 6):2 分區 2 已刪除
命令(輸入 m 獲取幫助):p
磁盤 /dev/sdb:1000.2 GB, 1000204886016 字節,1953525168 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 4096 字節
I/O 大小(最小/最佳):4096 字節 / 4096 字節
磁盤標簽類型:dos
磁盤標識符:0x600451aa
設備 Boot Start End Blocks Id System
命令(輸入 m 獲取幫助):
4. 重新分區:n增加分區
命令(輸入 m 獲取幫助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p 分區號 (1-4,默認 1):1 起始 扇區 (2048-1953525167,默認為 2048): 將使用默認值 2048 Last 扇區, +扇區 or +size{K,M,G} (2048-1953525167,默認為 1953525167):+100G 分區 1 已設置為 Linux 類型,大小設為 100 GiB 命令(輸入 m 獲取幫助):p 磁盤 /dev/sdb:1000.2 GB, 1000204886016 字節,1953525168 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 4096 字節 I/O 大小(最小/最佳):4096 字節 / 4096 字節 磁盤標簽類型:dos 磁盤標識符:0x600451aa 設備 Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 83 Linux 命令(輸入 m 獲取幫助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盤。
5. 查看分區情況
[root@test_vonedao_83 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 78G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.8G 0 lvm [SWAP] ├─centos-home 253:2 0 20G 0 lvm /home └─centos-opt 253:3 0 164M 0 lvm /opt 這是划分錯誤的邏輯卷和掛載,等下要刪除的。 sdb 8:16 0 931.5G 0 disk └─sdb1 8:17 0 100G 0 part
6.格式化
[root@test_vonedao_83 ~]# mkfs.xfs -i size=512 /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=6553600 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=26214400, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=12800, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
7.掛載,開機自動掛載
[root@test_vonedao_83 ~]# umount /opt/
[root@test_vonedao_83 ~]# mount /dev/sdb1 /opt/ [root@test_vonedao_83 ~]# df -hj df:無效選項 -- j Try 'df --help' for more information. [root@test_vonedao_83 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 devtmpfs 7.7G 0 7.7G 0% /dev tmpfs 7.7G 0 7.7G 0% /dev/shm tmpfs 7.7G 9.0M 7.7G 1% /run tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup /dev/mapper/centos-root 50G 1.3G 49G 3% / /dev/sda1 1014M 151M 864M 15% /boot /dev/mapper/centos-home 20G 607M 20G 3% /home tmpfs 1.6G 0 1.6G 0% /run/user/0 /dev/sdb1 100G 33M 100G 1% /opt [root@test_vonedao_83 ~]# tail /etc/fstab -n 2
#/dev/mapper/centos-opt /opt xfs defaults 0 0
/dev/sdb1 /opt xfs defaults 0 0
