Solved

How to format usb drive from bash script?

Posted on 2011-03-05
7
1,130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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