Some strange behaviours of parted

NeilZhang
NeilZhang
管理员
140
文章
106.8千
浏览
Linux评论401字数 925阅读3分5秒阅读模式

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.

  1. [root@olinux73 ~]# parted /dev/sdb
  2. GNU Parted 3.1
  3. Using /dev/sdb
  4. Welcome to GNU Parted! Type 'help' to view a list of commands.
  5. (parted) print
  6. Error: /dev/sdb: unrecognised disk label
  7. Model: ATA VBOX HARDDISK (scsi)
  8. Disk /dev/sdb: 2199GB
  9. Sector size (logical/physical): 512B/512B
  10. Partition Table: unknown
  11. Disk Flags:
  12. (parted) mklabel gpt
  13. (parted) help mkpart
  14. mkpart PART-TYPE [FS-TYPE] START END make a partition
  15.  
  16. PART-TYPE is one of: primary, logical, extended
  17. 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,
  18. amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap, linux-swap(new), linux-swap(old)
  19. 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.
  20.  
  21. '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:

  1. (parted) mkpart primary 2048s 50%
  2. (parted) print
  3. Model: ATA VBOX HARDDISK (scsi)
  4. Disk /dev/sdb: 2199GB
  5. Sector size (logical/physical): 512B/512B
  6. Partition Table: gpt
  7. Disk Flags:
  8.  
  9. Number Start End Size File system Name Flags
  10. 1 1049kB 1100GB 1100GB primary
  11.  
  12. (parted) mkpart primary 1100G 100%
  13. (parted) print
  14. Model: ATA VBOX HARDDISK (scsi)
  15. Disk /dev/sdb: 2199GB
  16. Sector size (logical/physical): 512B/512B
  17. Partition Table: gpt
  18. Disk Flags:
  19.  
  20. Number Start End Size File system Name Flags
  21. 1 1049kB 1100GB 1100GB primary
  22. 2 1100GB 2199GB 1100GB primary
  23.  
  24. (parted) quit
  25. Information: You may need to update /etc/fstab.
  26.  
  27. [root@olinux73 ~]# partprobe
  28. [root@olinux73 ~]# gdisk -l /dev/sdb
  29. GPT fdisk (gdisk) version 0.8.6
  30.  
  31. Partition table scan:
  32. MBR: protective
  33. BSD: not present
  34. APM: not present
  35. GPT: present
  36.  
  37. Found valid GPT with protective MBR; using GPT.
  38. Disk /dev/sdb: 4294965248 sectors, 2.0 TiB
  39. Logical sector size: 512 bytes
  40. Disk identifier (GUID): 39EBA439-3FC3-4D1B-889A-1FA66E9B7850
  41. Partition table holds up to 128 entries
  42. First usable sector is 34, last usable sector is 4294965214
  43. Partitions will be aligned on 2048-sector boundaries
  44. Total free space is 4029 sectors (2.0 MiB)
  45.  
  46. Number Start (sector) End (sector) Size Code Name
  47. 1 2048 2147481599 1024.0 GiB 0700 primary
  48. 2 2147481600 4294963199 1024.0 GiB 0700 primary

Please note the partition names were the same!

  1. [root@olinux73 ~]# ls -l /dev/disk/by-partlabel/
  2. total 0
  3. lrwxrwxrwx. 1 root root 10 May 16 02:32 primary -> ../../sdb1
  4. [root@olinux73 ~]# lsblk -o NAME,PARTLABEL
  5. NAME PARTLABEL
  6. sda
  7. ├─sda1
  8. ├─sda2
  9. ├─ol-root
  10. └─ol-swap
  11. └─sda3
  12. sdb
  13. ├─sdb1 primary
  14. └─sdb2 primary
  15. sr0

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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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:

  1. [root@olinux73 ~]# sgdisk -c 1:sdb1 /dev/sdb
  2. The operation has completed successfully.
  3. [root@olinux73 ~]# sgdisk -c 2:sdb2 /dev/sdb
  4. The operation has completed successfully.
  5. [root@olinux73 ~]# lsblk -o NAME,PARTLABEL
  6. NAME PARTLABEL
  7. sda
  8. ├─sda1
  9. ├─sda2
  10. ├─ol-root
  11. └─ol-swap
  12. └─sda3
  13. sdb
  14. ├─sdb1 sdb1
  15. └─sdb2 sdb2
  16. sr0
  17. [root@olinux73 ~]# ls -l /dev/disk/by-partlabel/
  18. total 0
  19. lrwxrwxrwx. 1 root root 10 May 16 05:03 sdb1 -> ../../sdb1
  20. 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.

  1. [root@olinux73 ~]# parted /dev/sdb
  2. GNU Parted 3.1
  3. Using /dev/sdb
  4. Welcome to GNU Parted! Type 'help' to view a list of commands.
  5. (parted) print
  6. Model: ATA VBOX HARDDISK (scsi)
  7. Disk /dev/sdb: 2199GB
  8. Sector size (logical/physical): 512B/512B
  9. Partition Table: gpt
  10. Disk Flags:
  11.  
  12. Number Start End Size File system Name Flags
  13. 1 1049kB 1100GB 1100GB ext4 sdb1
  14. 2 1100GB 2199GB 1100GB sdb2
  15.  
  16. (parted) rm 2
  17. (parted) rm 1
  18. (parted) mkpart primary 2048s 100%
  19. (parted) print
  20. Model: ATA VBOX HARDDISK (scsi)
  21. Disk /dev/sdb: 2199GB
  22. Sector size (logical/physical): 512B/512B
  23. Partition Table: gpt
  24. Disk Flags:
  25.  
  26. Number Start End Size File system Name Flags
  27. 1 1049kB 2199GB 2199GB ext4 primary
  28.  
  29. (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!

 最后更新:2018-6-10
  • 本文由 NeilZhang 发表于16/05/2018 05:14:28
  • Repost please keep this link: https://www.dbcloudsvc.com/blogs/linux/some-strange-behaviours-of-parted/
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定