Public bug reported:

1)
root@oil-maas-node-2:~# lsb_release -rd 
Description:    Ubuntu 12.04.4 LTS
Release:        12.04

2)
root@oil-maas-node-2:~# apt-cache policy gdisk
gdisk:
  Installed: 0.8.1-1build1
  Candidate: 0.8.1-1build1
  Version table:
 *** 0.8.1-1build1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/universe amd64 Packages
        100 /var/lib/dpkg/status

3) sgdisk --zap-all --clear --mbrtogpt should remove all partitions and
GPT table signatures

4) partitions are removed, but the GPT table signature is still present
as detected by fdisk and pvcreate

5) Verbose details here:

I'm reusing real disks between ceph and cinder in openstack installs,
ceph creates GPT tables for large disks (>2TB);  when we reinstall with
cinder, it uses pvcreate to make a large volume.  pvcreate fails due to
a GPT signature remaining on the disk.  The bug is in sgdisk which is
used in the ceph/cinder charms to clear the disk.    While sgdisk does
clean out the GPT tables, it doesn't remove the GTP signatures, fdisk
and pvcreate detect this.

Using dd and some math to calculate where the GPT tables live, I can
manually clear them up to allow fdisk and pvcreate see a clean disk.
Here is the workflow:

# ceph install will run: 
% ceph-disk-prepare /dev/vdb
Information: Moved requested sector from 34 to 2048 in
order to align on 2048-sector boundaries.
The operation has completed successfully.
Information: Moved requested sector from 2097153 to 2099200 in
order to align on 2048-sector boundaries.
The operation has completed successfully.
meta-data=/dev/vdb1              isize=2048   agcount=4, agsize=1245119 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=4980475, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
The operation has completed successfully.
% parted /dev/vdb print

Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name          Flags
 2      1049kB  1074MB  1073MB               ceph journal
 1      1075MB  21.5GB  20.4GB  xfs          ceph data


# here you can see fdisk detect the GTP table after a successful 
ceph-prepare-disk
% fdisk -l /dev/vdb 

WARNING: GPT (GUID Partition Table) detected on '/dev/vdb'! The util
fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/vdb: 21.5 GB, 21474836480 bytes
256 heads, 63 sectors/track, 2600 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1    41943039    20971519+  ee  GPT


# let's use the sgdisk command in the ceph/cinder charm to wipe out the disk
% cat zapdisk.sh
#!/bin/bash -x

sgdisk --zap-all --clear --mbrtogpt $1
% bash -x zapdisk.sh /dev/vdb

+ sgdisk --zap-all --clear --mbrtogpt /dev/vdb
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
The operation has completed successfully.

# parted shows that it's call clear
% parted /dev/vdb print

Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags


# But fdisk still sees the GPT signature.
% fdisk -l /dev/vdb 
WARNING: GPT (GUID Partition Table) detected on '/dev/vdb'! The util fdisk 
doesn't support GPT. Use GNU Parted.


Disk /dev/vdb: 21.5 GB, 21474836480 bytes
256 heads, 63 sectors/track, 2600 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1    41943039    20971519+  ee  GPT


# now let's try to create a PV with the same disk;  this is what cinder charm 
would do to initialize storage.
# note the 'Partition table signature found'
% pvcreate -d -vvv /dev/vdb

        Processing: pvcreate -d -vvv /dev/vdb
        O_DIRECT will be used
      Setting global/locking_type to 1
      Setting global/wait_for_locks to 1
      File-based locking selected.
      Setting global/locking_dir to /var/lock/lvm
      metadata/pvmetadatasize not found in config: defaulting to 255
      metadata/pvmetadatacopies not found in config: defaulting to 1
      Locking /var/lock/lvm/P_orphans WB
        _do_flock /var/lock/lvm/P_orphans:aux WB
        _do_flock /var/lock/lvm/P_orphans WB
        _undo_flock /var/lock/lvm/P_orphans:aux
        Opened /dev/vdb RO
      /dev/vdb: size is 41943040 sectors
        /dev/vdb: block size is 4096 bytes
        /dev/vdb: Skipping: Partition table signature found
        Closed /dev/vdb
        /dev/vdb: Skipping (cached)
        Matcher built with 3 dfa states
      Setting devices/ignore_suspended_devices to 0
      Setting devices/cache_dir to /etc/lvm/cache
      Setting devices/write_cache_state to 1
        Opened /dev/vdb RO
      /dev/vdb: size is 41943040 sectors
        /dev/vdb: block size is 4096 bytes
        /dev/vdb: Skipping: Partition table signature found
        Closed /dev/vdb
  Device /dev/vdb not found (or ignored by filtering).
      Unlocking /var/lock/lvm/P_orphans
        _undo_flock /var/lock/lvm/P_orphans


# Here is a script that will properly wipe the GPT tables and signatures
% cat ddwipe.sh

#!/bin/bash

DEV="${1}"
END="$(sudo blockdev --getsz ${DEV})"
GPT_END=$(($END - 100))
dd if=/dev/zero of=${DEV} bs=1M count=1
dd if=/dev/zero of=${DEV} bs=512 seek=${GPT_END}

% bash -x ddwipe.sh /dev/vdb

+ DEV=/dev/vdb
++ sudo blockdev --getsz /dev/vdb
+ END=41943040
+ GPT_END=41942940
+ dd if=/dev/zero of=/dev/vdb bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00194759 s, 538 MB/s
+ dd if=/dev/zero of=/dev/vdb bs=512 seek=41942940
dd: writing `/dev/vdb': No space left on device
101+0 records in
100+0 records out
51200 bytes (51 kB) copied, 0.00659633 s, 7.8 MB/s

# confirm the wipe in parted...  
% parted /dev/vdb print
Error: /dev/vdb: unrecognised disk label

# fdisk doesn't print the GPT warning any more
% fdisk -l /dev/vdb 
Disk /dev/vdb doesn't contain a valid partition table

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


# and pvcreate now works correctly.
% pvcreate -d -vvv /dev/vdb

        Processing: pvcreate -d -vvv /dev/vdb
        O_DIRECT will be used
      Setting global/locking_type to 1
      Setting global/wait_for_locks to 1
      File-based locking selected.
      Setting global/locking_dir to /var/lock/lvm
      metadata/pvmetadatasize not found in config: defaulting to 255
      metadata/pvmetadatacopies not found in config: defaulting to 1
      Locking /var/lock/lvm/P_orphans WB
        _do_flock /var/lock/lvm/P_orphans:aux WB
        _do_flock /var/lock/lvm/P_orphans WB
        _undo_flock /var/lock/lvm/P_orphans:aux
        Opened /dev/vdb RO
      /dev/vdb: size is 41943040 sectors
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
      /dev/vdb: size is 41943040 sectors
        Opened /dev/vdb RO O_DIRECT
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
        Using /dev/vdb
        Opened /dev/vdb RO O_DIRECT
        /dev/vdb: block size is 4096 bytes
      /dev/vdb: No label detected
        Closed /dev/vdb
        Opened /dev/vdb RW O_EXCL O_DIRECT
        Closed /dev/vdb
      /dev/vdb: size is 41943040 sectors
        Opened /dev/vdb RO O_DIRECT
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
      /dev/vdb: size is 41943040 sectors
        Opened /dev/vdb RW O_DIRECT
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
      /dev/vdb: size is 41943040 sectors
      Setting devices/data_alignment to 0
      Device /dev/vdb queue/minimum_io_size is 512 bytes.
      Device /dev/vdb queue/optimal_io_size is 0 bytes.
      /dev/vdb: Setting PE alignment to 128 sectors.
      Device /dev/vdb alignment_offset is 0 bytes.
      /dev/vdb: Setting PE alignment offset to 0 sectors.
        Opened /dev/vdb RW O_DIRECT
        Wiping /dev/vdb at 4096 length 1
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
    Set up physical volume for "/dev/vdb" with 41943040 available sectors
      Scanning for labels to wipe from /dev/vdb
        Opened /dev/vdb RW O_DIRECT
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
    Zeroing start of device /dev/vdb
        Opened /dev/vdb RW O_DIRECT
        Wiping /dev/vdb at sector 0 length 4 sectors
        /dev/vdb: block size is 4096 bytes
        Closed /dev/vdb
      Writing physical volume data to disk "/dev/vdb"
        lvmcache: /dev/vdb: now in VG #orphans_lvm2 (#orphans_lvm2)
        Creating metadata area on /dev/vdb at sector 8 size 376 sectors
      /dev/vdb: setting pe_start=384 (orig_pe_start=384, pe_align=128, 
pe_align_offset=0, adjustment=0)
        Opened /dev/vdb RW O_DIRECT
        /dev/vdb: block size is 4096 bytes
        /dev/vdb: Preparing PV label header 
Crb9aw-5dC5-c2OG-GUbO-8Fdv-Tp0S-HaeUSB size 21474836480 with da1 (384s, 0s) 
mda1 (8s, 376s)
      /dev/vdb: Writing label to sector 1 with stored offset 32.
      Unlocking /var/lock/lvm/P_orphans
        _undo_flock /var/lock/lvm/P_orphans
        Closed /dev/vdb
  Physical volume "/dev/vdb" successfully created

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: gdisk 0.8.1-1build1
ProcVersionSignature: Ubuntu 3.2.0-54.82-generic 3.2.50
Uname: Linux 3.2.0-54-generic x86_64
ApportVersion: 2.0.1-0ubuntu17.6
Architecture: amd64
Date: Mon Apr  7 16:14:51 2014
Ec2AMI: ami-0000002d
Ec2AMIManifest: FIXME
Ec2AvailabilityZone: serverstack-az-1
Ec2InstanceType: m1.medium
Ec2Kernel: aki-00000002
Ec2Ramdisk: ari-00000002
MarkForUpload: True
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: gdisk
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: gdisk (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug ec2-images precise

-- 
You received this bug notification because you are a member of Ubuntu
Server Team, which is subscribed to gdisk in Ubuntu.
https://bugs.launchpad.net/bugs/1303903

Title:
  sgdisk zap/clear doesn't wipe all GPT tables

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gdisk/+bug/1303903/+subscriptions

-- 
Ubuntu-server-bugs mailing list
Ubuntu-server-bugs@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-server-bugs

Reply via email to