Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Question about dd. Swap files!

I'm made/making a swap file. I put it on a secondary drive. I followed instruction to use this command:

 

 dd if=/dev/zero of=/location/of/swap/file bs=1024 count=16487332

 

https://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/s2-swap-creating-file.html

 

The location of swap file is on my secondary drive. The /dev/zero is on the main drive. I'm trying to figure out what IF does and what it matters to swap that it has a link in some manner to /dev/zero. Does it still make all the data go through the main drive. Or does it minimally address this file to find the location of the swap.

 

I read some stuff on what /dev/zero is and it has to do with providing a stream of 0's or something along with /null or something. Does this only effect this process when initially creating the swap file. I'm assuming it's using it to make a file to all 0's to make the swap file initially. Does this ever get used when and after swap is created creating any wear on the drive?

https://unix.stackexchange.com/questions/254384/difference-between-dev-null-and-dev-zero

 

I'm assuming it basically is read only from the /dev/zero location. And I'm assuming only on creation of the file. But I want to make sure this doesn't have something odd behind it where the swap file is referencing it in practice somehow as part of the function creating any write/wear on the primary drive. Anyone have any insight?

Link to comment
Share on other sites

Link to post
Share on other sites

/dev/zero is only used in the creation. Also, /dev/zero is not a location in the drive, but is provided by the kernel

Intel Core i3-10100 - Gigabyte Z490M - HyperX DDR4 16GB  - 500W - 1x 1080p - macOS 12 Monterey, Windows 11

Intel Core i5-4210U - Acer Aspire E5-573G - 8GB - 768p - macOS 11 Big Sur, Windows 11
iPhone 12 - iOS 15

Link to comment
Share on other sites

Link to post
Share on other sites

I only use Arch now, but I can tell you what dd does.  The if in dd stands for Input File.  dd will write the raw bits from that to your output file, of.  When using /dev/zero, you are writing all zeros to the output file, which is why you have to be very careful when using dd.

 

In Arch, you create a swap partition when you partition the drive.  Then you use the same commands in your link, mkswap and swapon.  It's different again at the end because arch uses genfstab to automatically generate the fstab file.  No difference except convenience there.

 

To answer your question, using /dev/zero in dd will only write the zeros when you use the command.  After that, your OS will use the swap file and it won't be just 0s anymore.

Link to comment
Share on other sites

Link to post
Share on other sites

in Unix OSes everything is a file, the /dev directory does not exist in your disk, files in there are populated virtually when you startup your PC, /dev/zero is just an infinite 0 spammer, that is used when you need to completely wipe something or create something, it's clean because it will overwrite everything with dd and safer for swap files because you'll be sure that nothing fishy is going to happen with random data inside a file. Anyway mkswap should take care of it there are simpler ways to do that

 

 

Also note that the swapfile on your secondary drive must be mounted before the swapfile is enabled and the real location is something like

internal hd -> /

external hd -> /media/hdd/

swap file -> /media/hdd/swapfile.file

 

where swapfile is created with dd using if=/dev/zero of=/media/hdd/swapfile.file

Link to comment
Share on other sites

Link to post
Share on other sites

You can create swap by either creating a partition for it or just use a swap file. 2nd one is more convinet if you will to resize the size if swap in the future. 

 

Oh, you are creating a swap file. Well, there is a video out there for that on YouTube. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×