Solved

How to format usb drive from bash script?

Posted on 2011-03-05
7
1,139 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

729 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