Writing a script that creates a 1GB file with zeros using dd

I am new to Linux. Using latest version of Ubuntu.

I want to make a script that creates a 1GB file filled with zeros using dd and then formats the file as vfat with a label of "MYFILE".

If anyone can help me it would be appreciated.

This link here seems pretty useful, let us know what you could brew from it :slight_smile:

Yeh, I got how to make the file filled with zero's in my script, but how can I format the file using vfat and assign a label of 'MYFILE' and then use pv to write the image to a usb drive?

confused :confused:

You can't "format the file using vfat". The underlying file system determines the way a file is stored. File systems include ufs (unix file system), ext(2,3,4) (extended fs, linux), vfat (msdos), and others.
If you use e.g. a preformatted external disk, chances are it was formatted as vfat.

What do you want to achieve?

Okay, so for a assignment I was told to write a script that creates a 1GB file filled with zeros using dd and then format the file as vfat with a label of ASSIGN1.

I was able to write the script to make a file called 'myFile' that contained 0's like this

dd if=/dev/zero of=myFile bs=1M count=1024

And then I also put in a like to format the file as vfat like this:

mkfs.vfat

I am not sure if I did that correctly and I have no idea how to assign the label. Please help?

Yes you can use mkfs.vfat to create a vfat-Filesystem in a file and also to label this filesystem(Of whatever use that maybe). Just have a look at the mkfs.vfat - man-page( man mkfs.vfat ) for the options for formatting and labelling.

After that you may use dd again to copy your file directly to a USB-Device. (Take care not to overwrite any of the currently used disks). :slight_smile:

Yeh, I did look it up and I still don't understand. I am really new to Linux. If you could help me out how to give it a label would be helpful. Also for using dd on the USB can that be implemented into the script too?

What assignment? May you please clarify?

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.