parted mktable error. but gparted "create partition table" works?

I am trying to automate formatting of USB drives. What I do is:

  1. Unmount USB drive
  2. terminal: sudo parted /dev/sdb1 mktable msdos

This is when I get the following error:

Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdb1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use.  You should reboot now
before making further changes.

When I create a partition table on the same USB stick in GParted I don't have to reboot!

What do I have to enter into the terminal so I don't have to reboot? I mean GParted is simply the GUI to parted right?


Solution 1:

First, it looks like you're trying to create a partition table, on a partition
/dev/sdb1
instead of on the disk itself
/dev/sdb

I'm guessing that could lead to some strange errors... are you really trying to create 64 partitions on a USB drive, or that could be a strange error.

After sorting out the partition table, I think these commands should work:

  1. Create MBR (msdos) partition table

    sudo parted /dev/sdb mktable msdos
    
  2. Make a partition (a primary partition, with FS ID ext3, starting at 1MB & using 100% of space) (If start at 0% or 0MB, it's not aligned to MB's and complains):

    sudo parted /dev/sdb mkpart primary ext3 1 100%
    
  3. Apparently gparted does a wipefs on new or existing partitions when they're formatted, to avoid problems with old filesystem signatures. So could do this too:

    sudo wipefs -a /dev/sdb1
    
  4. Then make the filesystem on the first partition (sdb1) just created (-L label is optional, see the mkfs.ext3/mke2fs man page for lots of options):

    sudo mkfs.ext3 -L "NewLabel" /dev/sdb1
    

Here's the built-in help from parted <dummydevicefile> help mkpart (seems more detailed than the man/info page):

mkpart PART-TYPE [FS-TYPE] START END     make a partition

    PART-TYPE is one of: primary, logical, extended  
    FS-TYPE is one of: zfs, btrfs, ext4, ext3, ext2, fat32, fat16, hfsx,
    hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs,
    freebsd-ufs, 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.