Ubuntu Server 20.04使用parted管理GPT分區

參考資料:https://manpages.ubuntu.com/manpages/focal/man8/parted.8.html


  1. 創建分區步驟:添加硬盤->查看硬盤->parted->創建分區表->創建分區->格式化
# 查看硬盤
fdisk -l
# 輸出
Disk /dev/sdc: 160 GiB, 171798691840 bytes, 335544320 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# 使用parted對/dev/sdc這個硬盤進行分區
parted /dev/sdc
# 進入交互界面
GNU Parted 3.3
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
# 查看分區
(parted) p
Error: /dev/sdc: unrecognised disk label
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 172GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
# 連續輸入兩次tab可以查看命令
align-check  mklabel      print        resizepart   toggle
disk_set     mkpart       quit         rm           unit
disk_toggle  mktable      rescue       select       version
help         name         resize       set
# 創建分區表
mklabel gpt
# 警告數據將會被清空,輸入yes即可
# 創建一個主分區,並以2048扇區起始,使用全部容量(分區對齊)
mkpart primary 2048s 100%
# 分區沒有對齊,不推薦
mkpart primary ext4 0 -1
# 提示分區未對齊,輸入ignore忽略即可
Warning: The resulting partition is not properly aligned for best performance:
34s % 2048s != 0s
Ignore/Cancel? Ignore
# 查看分區對齊情況
align-check opt 1
# 如果輸出1 aligned則表示分區對齊
# 查看分區
print
# 退出parted
quit
# 查看分區情況
fdisk -l
# 輸出
Device     Start       End   Sectors  Size Type
/dev/sdc1     34 335542367 335542334  160G Linux filesystem
# 格式化分區
mkfs.ext4 /dev/sdc1
# 輸出
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 41942791 4k blocks and 10485760 inodes
Filesystem UUID: e6d38d3a-8bb8-46eb-9ede-992cc4ac0482
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks):#區塊按回車保持默認即可
done
Writing superblocks and filesystem accounting information: done
# 創建文件夾
mkdir /data2
# 掛載分區
 mount /dev/sdc1 /data2
  1. 刪除分區步驟:parted->查看分區->刪除分區
# 查看分區掛載情況
df -h
# 如果分區正在掛載,請先卸載
# 比如分區/dev/sdc1掛載在/data2上
umount /dev/sdc1
# 查看需要刪除的分區在哪個硬盤設備上
fdisk -l
# 比如要刪除/dev/sdc1這個分區,/dev/sdc1分區在/dev/sdc硬盤上
parted /dev/sdc
# 輸出
GNU Parted 3.3
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
# 查看分區情況
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 172GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  172GB  172GB  ext4         primary
# 刪除分區,rm後面加分區序號
rm 1
# 退出
quit
# 刪除分區表
wipefs -a /dev/sdc

注意:

無論是創建/刪除分區,如果有掛載關係,都需要更新/etc/fstab文件!

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