2

After deleting the partitions from a USB stick and then re-inserting the disk I see the following from dmesg:

[99341.658055] sd 4:0:0:0: [sdb] 15771720 512-byte logical blocks: (8.07 GB/7.52 GiB)
[99341.658670] sd 4:0:0:0: [sdb] Write Protect is off
[99341.658678] sd 4:0:0:0: [sdb] Mode Sense: 00 00 00 00
[99341.658684] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[99341.668175] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[99341.668187]  sdb

Now how do I create a partition /dev/sdb1 of the full size of the disk from the command line?

fdisk and parted ask stupid questions like the start and end of partition. I want the partition simply to full the entire disk. Most people I know resort to using gparted, which I don't want. I just want a simple one liner to create a full sized partition.

The next command I probably want to run after creating the partition is mkfs.ext4 /dev/sdb1.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
hendry
  • 9,725
  • 18
  • 81
  • 139

4 Answers4

5
parted -s /dev/sdb mkpart primary 0% 100%
Gabriel
  • 2,313
  • 9
  • 29
  • 41
3

You may be able to use sfdisk, just omit the partition size and start.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
3

I've previously scripted fdisk like:

echo "
n
p
1
...
" | fdisk /dev/sdb

Note when creating partitions on usb keys align on 1MB. Other wise performance can be affected.

pixelbeat
  • 30,615
  • 9
  • 51
  • 60
2

The parted program has an option:

-s, --script - never prompt the user.

That ought to make it easier to script.

unwind
  • 391,730
  • 64
  • 469
  • 606