Some strange behaviours of parted

  • 401 views
  • Read

Last night when I made partitions of one large 3T flash disk, I got some issues with the parted command.

The flash disk would be used as an Oracle ASM disk, so I preferred to split it to two partitions and every one would use half of it and the size would less than 2TB.

Below are some examples in my own VM and I only could add a 2TB hark disk.

[root@olinux73 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/sdb: unrecognised disk label
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) help mkpart
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

        PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: btrfs, nilfs2, ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs,
        amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap, linux-swap(new), linux-swap(old)
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example, -1s specifies exactly the last sector.

        'mkpart' makes a partition without creating a new file system on the partition.  FS-TYPE may be specified to set an appropriate partition ID.

So to create two primary partitions, I run below commands:

(parted) mkpart primary 2048s 50%
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1100GB  1100GB               primary

(parted) mkpart primary 1100G 100%
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1100GB  1100GB               primary
 2      1100GB  2199GB  1100GB               primary

(parted) quit
Information: You may need to update /etc/fstab.

[root@olinux73 ~]# partprobe
[root@olinux73 ~]# gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdb: 4294965248 sectors, 2.0 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 39EBA439-3FC3-4D1B-889A-1FA66E9B7850
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 4294965214
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      2147481599   1024.0 GiB  0700  primary
   2      2147481600      4294963199   1024.0 GiB  0700  primary

Please note the partition names were the same!

[root@olinux73 ~]# ls -l /dev/disk/by-partlabel/
total 0
lrwxrwxrwx. 1 root root 10 May 16 02:32 primary -> ../../sdb1
[root@olinux73 ~]# lsblk -o NAME,PARTLABEL
NAME        PARTLABEL
sda
├─sda1
├─sda2
│ ├─ol-root
│ └─ol-swap
└─sda3
sdb
├─sdb1      primary
└─sdb2      primary
sr0

On some systems such thing will cause warning messages in the /var/log/messages file:

May 14 20:51:39 upderp1 systemd: Device dev-disk-by\x2dpartlabel-primary.device appeared twice with different sysfs paths /sys/devices/pci0000:00/0000:00:03.2/0000:06:00.0/nvme/nvme0/nvme0n1/nvme0n1p2 and /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p1
May 14 20:51:39 upderp1 systemd: Device dev-disk-by\x2dpartlabel-primary.device appeared twice with different sysfs paths /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p1 and /sys/devices/pci0000:00/0000:00:03.2/0000:06:00.0/nvme/nvme0/nvme0n1/nvme0n1p2
May 14 20:51:39 upderp1 systemd: Device dev-disk-by\x2dpartlabel-primary.device appeared twice with different sysfs paths /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p2 and /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p1
May 14 20:51:39 upderp1 systemd: Device dev-disk-by\x2dpartlabel-primary.device appeared twice with different sysfs paths /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p2 and /sys/devices/pci0000:00/0000:00:03.2/0000:06:00.0/nvme/nvme0/nvme0n1/nvme0n1p2
May 14 20:51:39 upderp1 systemd: Device dev-disk-by\x2dpartlabel-primary.device appeared twice with different sysfs paths /sys/devices/pci0000:80/0000:80:02.0/0000:82:00.0/nvme/nvme1/nvme1n1/nvme1n1p2 and /sys/devices/pci0000:00/0000:00:03.2/0000:06:00.0/nvme/nvme0/nvme0n1/nvme0n1p1

So we'd better correct this issue:

[root@olinux73 ~]# sgdisk -c 1:sdb1 /dev/sdb
The operation has completed successfully.
[root@olinux73 ~]# sgdisk -c 2:sdb2 /dev/sdb
The operation has completed successfully.
[root@olinux73 ~]# lsblk -o NAME,PARTLABEL
NAME        PARTLABEL
sda
├─sda1
├─sda2
│ ├─ol-root
│ └─ol-swap
└─sda3
sdb
├─sdb1      sdb1
└─sdb2      sdb2
sr0
[root@olinux73 ~]# ls -l /dev/disk/by-partlabel/
total 0
lrwxrwxrwx. 1 root root 10 May 16 05:03 sdb1 -> ../../sdb1
lrwxrwxrwx. 1 root root 10 May 16 05:03 sdb2 -> ../../sdb2

Another issue was that if the partition had been formatted before, and then I removed it and created a new partition, the filesystem information would be kept.

[root@olinux73 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  1100GB  1100GB  ext4         sdb1
 2      1100GB  2199GB  1100GB               sdb2

(parted) rm 2
(parted) rm 1
(parted) mkpart primary 2048s 100%
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  2199GB  2199GB  ext4         primary

(parted) quit

It was not a big issue if I would create a new filesystem on it, but I created it for Oracle ASM usage and it took me one hour to figure out I need to sweep the filesystem first or the installation program would never find it!

  • by Published on 16/05/2018 05:14:28
  • Repost please keep this link: https://www.dbcloudsvc.com/blogs/linux/some-strange-behaviours-of-parted/
匿名

Comment

Anonymous Write

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Decide