第三部:磁盤分區(qū) # fdisk創(chuàng)建分區(qū)
[root@kylin-xu ~]# fdisk /dev/sdb
Command (m for help): m # 查看菜單
Help:
d delete a partition # 刪除一個(gè)分區(qū)
l list known partition types # 顯示分區(qū)類型
n add a new partition # 創(chuàng)建新的分區(qū)
p print the partition table # 輸出分好的分區(qū)表
m print this menu # 打印菜單
w write table to disk and exit #保存并且推出
q quit without saving changes# 退出不保存
Command (m for help): n # 創(chuàng)建分區(qū)
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p # 指定類型,默認(rèn)是primary
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): +5G
Created a new partition 1 of type 'Linux' and of size 5 GiB.
Command (m for help): n # 第二個(gè)分區(qū)
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-41943039, default 41943039): +10G
Created a new partition 2 of type 'Linux' and of size 10 GiB.
Command (m for help): d # 刪除分區(qū)
Partition number (1-4, default 4):
Command (m for help): n # 創(chuàng)建一個(gè)擴(kuò)展分區(qū)
Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e):
Using default response e.
Selected partition 4
First sector (33556480-41943039, default 33556480):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (33556480-41943039, default 41943039):
Created a new partition 4 of type 'Extended' and of size 4 GiB.
Command (m for help): p # 查看創(chuàng)建的分區(qū)類型
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5fbfe031
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 10487807 10485760 5G 83 Linux
/dev/sdb2 10487808 31459327 20971520 10G 83 Linux
/dev/sdb3 31459328 33556479 2097152 1G 83 Linux
/dev/sdb4 33556480 41943039 8386560 4G 5 Extended
Command (m for help): n # 創(chuàng)建邏輯分區(qū)
All primary partitions are in use.
Adding logical partition 6
First sector (35657728-41943039, default 35657728):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (35657728-41943039, default 41943039):
Created a new partition 6 of type 'Linux' and of size 3 GiB.
Command (m for help): w # 保存分區(qū)
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@kylin-xu ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 59G 0 part
├─klas-root 253:0 0 38.3G 0 lvm /
├─klas-swap 253:1 0 2G 0 lvm [SWAP]
└─klas-backup 253:2 0 18.7G 0 lvm /backup
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
├─sdb2 8:18 0 10G 0 part
├─sdb3 8:19 0 1G 0 part
├─sdb4 8:20 0 1K 0 part
├─sdb5 8:21 0 1G 0 part
└─sdb6 8:22 0 3G 0 part
sr0 11:0 1 4.3G 0 rom
# 如果我們使用分區(qū)完成后,使用lsblk查看不到我們分區(qū)的內(nèi)容,這是由于lsblk是查看內(nèi)存中的信息,又可能我們分區(qū)完成后,內(nèi)存沒(méi)有更新,這是我們需要手動(dòng)刷新下
[root@kylin-xu ~]# partprobe
非交互式創(chuàng)建分區(qū)
[root@kylin-xu ~]# echo -e 'p
n
+1G
p
' | fdisk /dev/sdb
#
表示回車
# parted創(chuàng)建分區(qū)
(parted) mklabel gpt # 將磁盤類型修改為gpt格式
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 4295GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
(parted) mkpart # 創(chuàng)建分區(qū)
Partition name? []? primary # 分區(qū)的名稱 自定義叫啥都行
File system type? [ext2]? xfs
Start? 0
End? 500G
Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s
Ignore/Cancel? I
(parted) print
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500GB 500GB xfs primary
(parted) mkpart
Partition name? []? parimary
File system type? [ext2]? xfs
Start? 500G
End? 1000G
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 4295GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 500GB 500GB primary
2 500GB 1000GB 500GB xfs parimary
(parted) mkpart primary xfs 1000G 4000G # 非交互式分區(qū)
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 4295GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
(parted) quit # 退出parted分區(qū)
parted重要的子命令
help [COMMAND] # 打印菜單幫助
mklabel,mktable LABEL-TYPE # 創(chuàng)建分區(qū)表類型
mkpart PART-TYPE [FS-TYPE] START END # 創(chuàng)建分區(qū)
print [devices|free|list,all|NUMBER] # 查看分區(qū)表
quit # 退出
rm NUMBER # 刪除分區(qū)
第六步:寫入/etc/fstab,開(kāi)機(jī)自動(dòng)掛載
vim /etc/fstab
/dev/sdb1 /mnt/xfs xfs defaults 0 0
卸載分區(qū)
[root@kylin-xu xfs]# touch 123
[root@kylin-xu xfs]# cd
[root@kylin-xu ~]# umount /mnt/xfs
[root@kylin-xu ~]# df -Th | grep /mnt/xfs
[root@kylin-xu ~]# ll /mnt/xfs
total 0
# 我們將分區(qū)卸載之后,我們創(chuàng)建的內(nèi)容也會(huì)消失,
# 我們重新掛載上之后就又會(huì)出現(xiàn)
[root@kylin-xu ~]# mount /dev/sdb1 /mnt/xfs
[root@kylin-xu ~]# ll /mnt/xfs
total 0
-rw-r--r-- 1 root root 0 Nov 20 04:08 123
我們?cè)诒硎緇ogical parted時(shí)盡量不要使用路徑去表示,要使用UUID
4、Ubuntu中進(jìn)行磁盤分區(qū)
# 添加磁盤
root@xu-ubuntu:~# for i in `ls /sys/class/scsi_host/` ; do echo '- - -' > /sys/class/scsi_host/${i}/scan; done
root@xu-ubuntu:~# fdisk /dev/sdb -l
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
在Ubuntu中磁盤分區(qū)使用的是gpt分區(qū)
root@xu-ubuntu:~# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.8
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries in memory.
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C4537E56-7D8E-4F18-916F-4C63377E3032
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 41942973 sectors (20.0 GiB)
Number Start (sector) End (sector) Size Code Name
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +4G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C4537E56-7D8E-4F18-916F-4C63377E3032
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 33554365 sectors (16.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 8390655 4.0 GiB 8300 Linux filesystem
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.
評(píng)論