sgdisk基本用法

sgdisk基本用法
简介
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
1
2
-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
1
2
3
4
5
6
7
8
创建一个从默认起始地址开始的10G的分区:
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
1
2
3
4
5
6
7
8
9
查看分区详情
root@ceph1:~$ sgdisk --help | grep info
  -i, --info=partnum                 show detailed information on partition
1
2
-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: ''

1
2
3
4
5
6
7
8
修改分区的 type code
root@ceph1:~$ sgdisk --help | grep typecode
  -t, --typecode=partnum:{hexcode|GUID}        change partition type code
1
2
-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: ''
1
2
3
4
5
6
7
8
9
10
11
修改分区名
root@ceph1:~$ sgdisk --help | grep change-name
  -c, --change-name=partnum:name             change partition's name
1
2
-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'
1
2
3
4
5
6
7
8
9
10
11
清除分区数据
root@ceph1:~$ sgdisk --help | grep zap
  -z, --zap                  zap (destroy) GPT (but not MBR) data structures
1
2
清除第一分区:
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.
1
2
3
4
5
6
删除分区
root@ceph1:~$ sgdisk --help | grep delete
  -d, --delete=partnum                 delete a partition
1
2
-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
————————————————
版权声明:本文为CSDN博主「ygtff」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ygtlovezf/article/details/76269800

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值