Solved

How to format usb drive from bash script?

Posted on 2011-03-05
7
1,116 Views
Last Modified: 2012-06-27
Hello,

Running Fedora 14 with bash shell.

I have a USB Drive connected that I need to format from the command line.

The drive is always located at /media/OCH

I want to format it to be ext4 format with the same name as before "OCH".

Can you please provide me with the bash command to do this from inside a shell script?

Thanks!
Jason
0
Comment
Question by:SqueezeOJ
  • 4
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
eappiah earned 300 total points
ID: 35043546
mkfs.ext4 /dev/sdx -L OCH


Where x is your USB drive. might be sda , sdb ,sdc.. or hda,hdb,hdc
if's it already mounted type mount to find out.
0
 

Author Comment

by:SqueezeOJ
ID: 35045059
Hi eappiah,

I'll try your solution tomorrow.

Thanks,
Jason
0
 
LVL 2

Assisted Solution

by:Diogo Uchoas
Diogo Uchoas earned 200 total points
ID: 35045888
There are several mkfs commands. Depends on what filesystem you want the format.
First, umount the device.
umount /dev/sdX

Open in new window


For fat32:
mkfs.vfat /dev/sdX

Open in new window

For ext3:
mkfs.ext3 /dev/sdX

Open in new window

For cramfs:
mkfs.cramfs /dev/sdX

Open in new window


and etc...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:SqueezeOJ
ID: 35047571
Something's not working the way I was hoping...

If I run
sudo mkfs.ext4 /dev/sdb1 -L OCH

Open in new window

then I get error:
/dev/sdb1 is mounted; will not make filesystem here!

Open in new window

 (This occurs as root or as a privileged user.)

What am I missing?
0
 
LVL 3

Expert Comment

by:eappiah
ID: 35047786
You need to unmount it first.

Cannot format that is mounted.

"sudo umount /dev/sdb1"
0
 

Author Comment

by:SqueezeOJ
ID: 35049613
That makes sense - but then how do I mount it?
0
 

Author Comment

by:SqueezeOJ
ID: 35049632
Let me clarify....

1. umount...
2. mkfs.ext4...
3 re-mount

How do I re-mount?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using SSH Through A Bastion Host Transparently (Is the topic) 1 46
gdb doesn't stop on breakpoint 2 51
linux installs 6 50
Powershell Timeout - Exchange 3 11
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now