Solved

How to format usb drive from bash script?

Posted on 2011-03-05
7
1,126 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

856 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