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?


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

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),
    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
  • Thats it, thanks a lot! Could you please help me out with the additional steps I have to take to create one partition with an ext3 filesystem that spans the whole USB drive?
    – schmiddl
    Jan 26 '15 at 16:47
  • I always use gparted, but it uses the parted libraries so it's like a gui front end... and it has a "view output" (or similar) that lets you see the results of commands it uses, I think it shows the commands themselves too, so try using it and see if it tells you what commands it does. man parted should have some good explanations too...
    – Xen2050
    Jan 27 '15 at 3:14
  • @schmiddl I tried following gparted myself, it didn't show the exact parted commands, but did describe what it does, so I filled in some blanks
    – Xen2050
    Jan 27 '15 at 10:29
  • Great, works like a charm, thank you so much! There is one more thing: It won't mount automatically. What I did was make a directory in the /media/ folder and manually mount it in the terminal. Is there a terminal command to make the partition mount automatically when I plug the usb stick into the computer?
    – schmiddl
    Jan 27 '15 at 10:41
  • The different desktop environments can do their "own thing" with removable media, in XFCE it's Settings has a "Removable Drives and Media" where you can tell it to mount/browse/autorun when inserted or "hot-plugged". Unity should have similar settings somewhere. I think many use udisks/udisksd, and most file managers have a "disks" listing where you can click-to-mount. Or a program like Disks (gnome-disk-utility) usually works for browsing partitions & mounting/unmounting.
    – Xen2050
    Jan 27 '15 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.