How do I specify to use gigabytes for dd command?

So I want to create a swapfile

I ran this command sudo dd if=/dev/zero of=/swap bs=1024 count=16G but I ended up running out of space because the count did not stop how much to write to that file for some reason. It might because I have the G in front of the 16 or something? Any idea how do I insert it directly in gigabyte measurement or did I do something else wrong?

man dd

Might be the problem of using a multiplier of 1024 instead of 1000?

Do you have a swap file or swap partition?
And how big is it?

You may also find this helpful

If you want 16GB you want:

If you’re using it for hibernation - make sure it’s BIGGER. I would do 17GB in that case.



sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 status=progress

1 Like
man dd | grep GB                           
       GB=1000*1000*1000, G=1024*1024*1024, and so on for T, P, E, Z, Y.  Binary prefixes can be used, too: KiB=K, MiB=M, and so on.


Count doesn’t tell the dd command to create a file of this size, it tells the dd command to create a file made up of that many blocks of the size specified by the bs parameter. In this case your dd command will create a swap file made up of 16G (1610241024*1024) blocks that are each 1024 bytes creating a file that is ‘count * bs’ large, or somewhere around a 16TB file in this case … which is probably not what you want.

The following dd command will create a file that shows up with a size of 17.2 GB in Nautilus…

dd if=/dev/zero of=~/swap bs=1024 count=16M

here is the listing of the created file

-rw-r--r--   1 todd todd 17179869184 Nov 27 08:24  swap

I create a swapfile like this:

dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress.

I have yet to see my computer use any of this swapfile, nor in the past use any of the disk when I created a swap partition. I’m beginning to doubt the need for any swap at all.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.