Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partition a USB stick programmatically under Linux [closed]

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.

like image 544
hendry Avatar asked May 15 '26 14:05

hendry


2 Answers

parted -s /dev/sdb mkpart primary 0% 100%
like image 69
Gabriel Avatar answered May 18 '26 03:05

Gabriel


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

like image 35
Hasturkun Avatar answered May 18 '26 05:05

Hasturkun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!