views:

246

answers:

3

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.

+2  A: 

The parted program has an option:

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

That ought to make it easier to script.

unwind
+3  A: 

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

Hasturkun
yes `sudo sfdisk /dev/sdb` and pressing enter a lot of times seems to work!
hendry
+1  A: 

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