sgdisk基本用法

摘要:
简介sgdisk是在Linux下操作GPT分区的工具,就像fdisk是操作MBR分区的工具一样。

简介

sgdisk是Linux下操作GPT分区的工具,就像fdisk是操作MBR分区的工具。关于GPT和MBR的区别请参考:
http://www.anchor.com.au/blog/2012/10/the-difference-between-booting-mbr-and-gpt-with-grub/

使用

新建分区

root@ceph1:~$ sgdisk --help | grep new
-n, --new=partnum:start:end                  create new partition

-n 创建一个分区, -n后的参数分别是: 分区号:起始地址:终止地址
分区号如果为0,代表使用第一个可用的分区号;
起始地址和终止地址可以为0,0代表第一个可用地址和最后一个可用地址;
起始地址和终止地址可以为+/-xxx,代表偏移量,+代表在起始地址后的xxx地址,-代表在终止地址前的xxx地址

  • 创建了一个不指定大小、不指定分区号的分区:
root@ceph1:~# sgdisk -n 0:0:0 /dev/vdd
Creating new GPT entries.
The operation has completed successfully.

root@ceph1:~# lsblk | grep vdd
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdd    253:48   0  40G  0 disk
└─vdd1 253:49   0  20G  0 part
  • 创建一个从默认起始地址开始的5G的分区:
root@ceph1:~# sgdisk -n 2:0:+5G /dev/vdd
Creating new GPT entries.
The operation has completed successfully.

root@ceph1:~# lsblk | grep vdd
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdd    253:48   0  40G  0 disk
└─vdd1 253:49   0  20G  0 part
└─vdd2 253:50   0  5G   0 part

查看分区详情

root@ceph1:~$ sgdisk --help | grep info
  -i, --info=partnum                 show detailed information on partition

-i 显示某个分区详情

  • 查看第一分区详情:
root@ceph1:~# sgdisk -i 1 /dev/vdd
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: C7EB237F-9A8F-4938-B010-125B3D6D0D4A
First sector: 2048 (at 1024.0 KiB)
Last sector: 41943006 (at 20.0 GiB)
Partition size: 41940959 sectors (20.0 GiB)
Attribute flags: 0000000000000000
Partition name: ''

 root@ceph1:~# sgdisk --help |grep print
  -p, --print                                                                                     print partition table

 

 root@ceph1:~# sgdisk -p /dev/sdc
Disk /dev/sdc: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 1282C5A8-B97E-4384-B2AD-298168BD782D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 199229373 sectors (95.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   2            2048        10487807   5.0 GiB     8300 

 

修改分区的 type code

root@ceph1:~$ sgdisk --help | grep typecode
  -t, --typecode=partnum:{hexcode|GUID}        change partition type code

-t 修改某个分区的type code

  • 指定第一分区的type code:
root@ceph1:~# sgdisk -t 1:4fbd7e29-9d25-41b8-afd0-062c0ceff05d /dev/vdd
The operation has completed successfully.

root@ceph1:~# sgdisk -i 1 /dev/vdd
Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D (Unknown)
Partition unique GUID: C7EB237F-9A8F-4938-B010-125B3D6D0D4A
First sector: 2048 (at 1024.0 KiB)
Last sector: 41943006 (at 20.0 GiB)
Partition size: 41940959 sectors (20.0 GiB)
Attribute flags: 0000000000000000
Partition name: ''

修改分区名

root@ceph1:~$ sgdisk --help | grep change-name
  -c, --change-name=partnum:name             change partition's name

-c 修改某个分区的分区名

  • 指定第一分区的分区名:
root@ceph1:~# sgdisk  -c 1:"ceph data" /dev/vdd
The operation has completed successfully.

root@ceph1:~# sgdisk -i 1 /dev/vdd
Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D (Unknown)
Partition unique GUID: C7EB237F-9A8F-4938-B010-125B3D6D0D4A
First sector: 2048 (at 1024.0 KiB)
Last sector: 41943006 (at 20.0 GiB)
Partition size: 41940959 sectors (20.0 GiB)
Attribute flags: 0000000000000000
Partition name: 'ceph data'

清除分区数据

root@ceph1:~$ sgdisk --help | grep zap
  -z, --zap                  zap (destroy) GPT (but not MBR) data structures
  • 清除第一分区:
root@ceph1:~# sgdisk -z /dev/vdd1
Creating new GPT entries.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.

删除分区

root@ceph1:~$ sgdisk --help | grep delete
  -d, --delete=partnum                 delete a partition

-d 删除一个分区

  • 删除第一分区:
root@ceph1:~# sgdisk -d 1 /dev/vdd
The operation has completed successfully.

root@ceph1:~# lsblk | grep vdd
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdd    253:48   0  40G  0 disk
└─vdd2 253:50   0  5G   0 part
 
 

免责声明:文章转载自《sgdisk基本用法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Composer教程之基础用法c# 设置桌面背景窗口 SetParent下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

蓝天准系统P150em 980M 修改inf 安装451.67驱动

老机器,老显卡了。 但是980M是的硬件ID是特制的,需要修改,官网驱动说找不到硬件之类,无法安装 最近为了学pytorch,安装cuda10 重装系统。重新回忆一遍。 蓝天这个980M,在设备管理器里查看的硬件ID是 PCIVEN_10DE&DEV_13D7&SUBSYS_71021558&REV_A1 1 下载驱动 https:...

[转]OpenTK学习笔记(1)-源码、官网地址

OpenTK源码下载地址:https://github.com/opentk/opentk OpenTK使用Nuget安装命令:OpenTK:Install-Package OpenTK -Version 3.0.1  OpenTK.GLControl:Install-Package OpenTK.GLControl -Version 3.0.1 Open...

嵌入式Linux问题总结(一) Ubuntu常用命令和编译问题解决方法

  在进行嵌入式Linux的学习笔记的学习过程中,开发过程也遇到很多Ubuntu系统,编译,Makefile语法,设备树,网络以及线程,进程等细节知识,这部分知识十分零散,却是应用开发的基础,如果将其放在学习笔记系列中,又干扰整个开发的节奏,所以就在上个系列的基础上,新增加关于嵌入式Linux问题的总结,这里面记录的可能是常用命令,编译报错的解决方法,特殊...

Finder 快捷键

记录几个常用的 Finder 快捷键: 复制 Finder 里选中的路径:option+cmd+c 地址栏跳到指定路径:shift+cmd+g 增加标签:cmd+t 显示/隐藏 标签栏:shift+cmd+t 显示/隐藏 地址栏:option+cmd+p...

Linux Bond的模式与原理。

原理:   多块网卡虚拟成一张,实现冗余;多张网卡对外显示一张,具有同一个IP;网络配置都会使用Bonding技术做网口硬件层面的冗余,防止单个网口应用的单点故障。   对于多物理网卡的 Bond 网卡而言,其中一块物理网卡会被设置为 Master(主设备),其他的网卡都是 Slave(从设备),Bond 网卡的 MAC 地址取自标志为 Master 的...

Ubuntu 针对 SSD 的优化方案

. . . . . 首先看下 LZ 的分区情况: >$ sudo fdisk -l Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors Units = sectors...