Solved

How to format usb drive from bash script?

Posted on 2011-03-05
7
1,111 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.

759 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

17 Experts available now in Live!

Get 1:1 Help Now