185

I added a new hard drive (/dev/sdb) to Ubuntu Server 16, ran parted /dev/sdb mklabel gpt and sudo parted /dev/sdb mkpart primary ext4 0G 1074GB. All went fine. Then I tried to mount the drive

mkdir /mnt/storage2
mount /dev/sdb1 /mnt/storage2

It resulted in

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

I tried mount -t ext4 /dev/sdb1 /mnt/storage2 with identical outcome. I've done this stuff many times before and have never ran into anything like this. I've already read this mount: wrong fs type, bad option, bad superblock on /dev/sdb on CentOS 6.0 to no avail.

fdisk output regarding the drive

Disk /dev/sdb: 1000 GiB, 1073741824000 bytes, 2097152000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0E136427-03AF-48E2-B56B-A467E991629F

Device     Start        End    Sectors  Size Type
/dev/sdb1   2048 2097149951 2097147904 1000G Linux filesystem 
5
  • 26
    Hint for anyone else coming across this: run dmesg, it may give you more information on what your problem actually is. Oct 1, 2019 at 15:53
  • To add to the suggestion by @WinstonEwert, run dmesg without piping it to grep. The messages I needed to see had no mention of my device, label, or mount point (other than dm-0 which I was not looking for)! Sep 18, 2020 at 20:00
  • dmesg told me I had "default" in /etc/fstab, "unrecognized option", when it should have been "defaults".
    – VikingGlen
    Jul 20, 2021 at 6:03
  • If you came to this question through a search, but your problem involves NFS, see NFS does not work. mount: wrong fs type, bad option, bad superblock. Jun 13 at 17:46
  • I added a new drive to the server and I accidently swapped the SATA cables from some drives. That was the problem for me. Switched them back to the way they were and it was all fixed.
    – Kevin
    Aug 1 at 18:55

17 Answers 17

199

WARNING: This will wipe out your drive!


You still need to create a (new) file system (aka "format the partition"). 

Double-check that you really want to overwrite the current content of the specified partition! Replace XY accordingly, but double check that you are specifying the correct partition, e.g., sda2, sdb1:

mkfs.ext4 /dev/sdXY

parted / mkpart does not create a file system.  The Parted User's Manual shows:

2.4.5 mkpart

Command: mkpart [part-type fs-type name] start end

    Creates a new partition, without creating a new file system on that partition.

    [Emphasis added.]

9
  • 118
    This will wipe out your current drive !!
    – SudarP
    Jan 26, 2019 at 2:03
  • 1
    @Kosta you must run the command as a superuser (i.e. sudo) May 13, 2019 at 12:54
  • 4
    @SudarP it wipes out the /dev/sdb1 device. Not your current. Just execute if you are sure of what you are doing (linux.die.net/man/8/mkfs.ext4)
    – tremendows
    Aug 2, 2019 at 7:56
  • 1
    @tremendows, rudimeier: I agree that the command is appropriate for the OP, but also agree with SudarP that a command like this that can mess up an existing filesystem should come with a prominent warning. Other people reading question may have intended /dev/sdc1 or somesuch and could seriously regret executing this command. May 23, 2020 at 12:28
  • 1
    It's important to mention that the "device" that gets wiped is only the partition that is selected, not the entire drive. So mkfs.ext4 /dev/sda4 will keep sda1-sda3 intact. So, as clarified, it will not wipe your current drive, unless you attempt to wipe it by missing to provide the device number in the command, in which case a prompt will ask for confirmation. May 11 at 18:13
39

I had this problem with /dev/sda on Ubuntu 16.04 I solved it by booting into a live usb and doing the following:

To see your disks use lsblk

If you can see your drive thats good, run fdisk -l to see if the system can use it.

Run this command to attempt to repair bad superblocks on the drive.

fsck /dev/sda1 (replace /dev/sda1 with the drive you want to fix).

When it asks to repair blocks select yes by pressing 'y'

Allow fsck to repair all bad blocks.

Then I was able to mount the device using

sudo mount /dev/sda /media/ubuntu

This solved it for me.

8
  • Trying this, I get a permission denied error for both fdisk -l and the fsck command. Is there a workaround?
    – NoVa
    Apr 22, 2019 at 5:37
  • 1
    @NoVa This may be out of date, but in generaly permission denied means you must precede the command with sudo such that you have root permisions.
    – CtrlAltF2
    May 17, 2020 at 19:06
  • 1
    You are assuming the file system is ext. Sep 3, 2020 at 9:34
  • No, clean, 1801983/9043968 files, 33913312/36160000 blocks. This only for certain condition. May 9, 2021 at 12:36
  • If you have a corrupted ubuntu installation and you are trying to recover it by booting from an external device, this is the answer. I was about to dump my ubuntu HD and this saved me. Thank you!
    – Sakis
    Oct 14, 2021 at 17:01
11

In my case, the solution was install nfs-utils on the client side.

CentOS/Red Hat:

yum install nfs-utils

Ubuntu/Debian:

apt update
apt install nfs-kernel-server
3
  • 2
    For Arch: sudo pacman -S nfs-utils
    – cajomar
    Jan 5, 2021 at 13:53
  • then what should I do after installing nfs-utils? May 9, 2021 at 12:37
  • @AdiPrasetyo Nothing, just install it.
    – Feriman
    May 9, 2021 at 18:11
8

I have a different process for this that replaced the bad superblock with one of the alternatives. FSCK can be a "lossy" process because FSCK may want to remove too much data or to remove data from a sensitive location (e.g. data directory for a data base) so there are times when I don't want to use it or it doesn't work.

You can sudo yourself silly or just become root for the process. Just remember that when you are root, Linux assumes that you know what you're doing when you issue commands. If so directed, it will speedily delivery Mr. Bullet to Mr. Foot. Like many other things, with great power comes great responsibility. That concludes my warning on running your system as root.

sudo -s

fdisk -l

Figure out which device - assuming /dev/sdc1 for this example along with EXT4 as its the most common for this explanation.

fsck -N /dev/sdc1

Your device and your file system (ZFS, UFS, XFS, etc.) may vary so know what you have first. Do not assume it's EXT4. Ignoring this step can cause you problems later if it's NOT an EXT4 file system.

fsck.ext4 -v /dev/sdc1

Get your error message which says the superblock is bad. You don't want to do this if your superblock is OK.

mke2fs -n /dev/sdc1

This will output the alternate superblocks stored on your partition.

*Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208*

Pick an alternate superblock - keep in mind that the first one is the default and its bad so let's not use that one. You will also want to pick one from the list you get from your partition. Do not use the example. Your superblocks may be stored elsewhere.

e2fsck -b 98304 /dev/sdc1

Reboot and see if this worked. If not try the next superblock on the list. I've had to go the third or fourth one a couple of times.

e2fsck -b 163840 /dev/sdc1

Now try the command to validate the disk again. See if you get the same messabout about bad superblocks.

fsck.ext4 -v /dev/sdc1

Keep trying until you either run out of superblocks or it works. If you run out, you likely have bigger issues and I hope you have good backups. You can try running FSCK at that point.

2
  • 5
    I urge people to wait for 1 day or 2 for accepting answers.
    – Israr
    Nov 8, 2019 at 6:45
  • Thank you for an answer that doesn't require formatting the drive. :) May 22 at 19:16
4

for me the problem was that the mount command contained options (umask, uid) which was not accepted (probably due to the device has ext4 file system)

sudo mount /dev/sda1 /media/ssd -o uid=pi,gid=pi
mount: /media/ssd: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.
sudo mount /dev/sda1 /media/ssd -o umask=000
mount: /media/ssd: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.

After removing the options, it worked

sudo mount /dev/sda1 /media/ssd
df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda1      ext4      220G   61M  208G   1% /media/ssd

After mount the permissions or ownership can be set to able to have write permissions for non root users.

sudo chown -R pi:pi /media/ssd
1
  • 1
    I had the same issue after upgrading from Ubuntu 16 to Ubuntu 20. Removing the option nobarrier from /etc/fstab on a XFS partition solved it.
    – pietrop
    Jul 6, 2021 at 9:46
3
# create mount dir
sudo mkdir /hdd6T

# new file system
sudo mkfs.ext4 /dev/sdc

# mount drive
sudo mount /dev/sdc /hdd6T/

# change ownership to specified user
sudo chown your-user /hdd6T/
2
  • 7
    The question already says mkdir and mount, and the accepted answer says mkfs.ext4.  You’ve added chown, which has nothing to do with the question, so you aren’t really contributing any useful new information. Apr 7, 2019 at 4:18
  • Step by step answer for those who cannot figure out. +1 Feb 16 at 8:51
2

I know this is an old question but in case this helps anyone that stumbles across this.

I was attempting to connect and NFS mount but was failing and getting the same error as OP.

After installing the dependencies I was good to go:

sudo apt install nfs-common

1
2

Unbelievable. I see this come up All the time. I can manually mount with the mount command no problem. When I try to mount -a I get the same bad fs type error. I looked at the /etc/fstab carefully and saw I spelled default not defaults. It is the spelling that gets me.

1
  • Same here I had "default" instead of "defaults" in /etc/fstab.
    – BV45
    Jun 25 at 19:08
2

To get a usable volume out of a new disk, you have to carry the following steps:

  1. Create a partition table on the disk, aka disklabel. there are two possible formats, msdos or gpt.
  2. Create as many partitions as desired from the disk space. each partition is essentially defined by a begin/end addresses and partition type. The filesystem type is not definitely not a partition attribute, although some commands like parted may use it to set the partition type. Each partition will be considered as a block device on the system and accessible as a block file like /dev/sdb1.
  3. Create a filesystem on the desired partition, which actually means organizing the partition raw space in a way suitable to store files/folders/links, etc., i.e. the file hierarchy. The filesystem attributes are stored in the superblock, which is generally one disk block at the very beginning in the partition space.

Given this short introduction, you'll notice that you still have to go through the third step. You may use for this mkfs.ext4 /dev/sdb1.

3
  • From the question, it looks like the OP already did your steps 1 and 2. If you believe that there’s an error in the commands he used, say so. And rudimeier’s answer (which is accepted and has nearly 200 votes) already covers your step 3.  Please don’t post duplicate answers. Do you have any new information or advice to contribute? Jun 13 at 17:24
  • The question clearly states that the disk is new. So no need for warning twice in bold text that the disk will be wiped/content overwritten! If editing other's solution were possible I would suggested modifications.. I also wanted to add a summary of the full procedure of how to make a usable space out of a new disk. Nothing new. btw, would you please point me to some resources on why SE bot put this question on the top (no filtering)? Thanks. Jun 14 at 13:49
  • If this question floated to the top of the list on the ‘‘front page’’, it’s probably because JingChen posted a new answer.   (You know; the one you commented on.) Jun 14 at 21:17
1

I had to install ntfs-3g.

The message appeared in dolphin. With installing ntfs-3g, dolphin can mount it properly.

1
  • This is the only solution that worked for me. I was trying to mount an external hard drive and getting that error.
    – betelgeuse
    Nov 6 at 5:47
1

In case you want to mount a disk in linux mint. here is how is my secondary disk looks like linux mint disk management

You just need to create partition from the menu and most done automatically, and mount options came automatically, disk is mounted under /media/ extended partition

0
1

In my case I wasn't paying attention, and was trying to mount /dev/sda /mnt instead of mount /dev/sda1 /mnt. Be careful out there!

1

My HD shows up in Gparted as unallocated but it isn't showing up in File (same thing in windows Disk management and File explorer)

I am used testdisk to recreate the partition table and I was able to recover my HD and all the date without formatting it.

  1. In the terminal enter testdisk
  2. Then choose create a log
  3. Then select the HD Choose the partition type (most probably Intel)
  4. Then select Analyse
  5. If you only had 1 partition in your HD, then just mark the one that shows up as Bootable partition (with the left-right arrow). Then press "Enter" to continue
  6. If you had more you should now do a "deeper search", otherwise choose Write

Unplug your HD and plug it again (this is what they mean, in this case, by "reboot")

0

For me, there was some mysterious file causing this issue.

I had to clear the directory using the following command:

sudo mkfs -t ext3 /dev/sdf

Warning: this might delete files you have saved. So you can run ls to make sure you don't lose important saved files and backup these files before execution.

0

If you are trying to mount image file in any folder present in /home in ubuntu then try these Commands:

Generalized :

>>mkdir <name of your directory>
>>sudo mount -o ro <name of image file with extension> <name of your directory>/

Specified: name of your directory = system , name of image file with extension = system.img

>>mkdir system                                
>>sudo mount -o ro system.img system/
0

I got the same error on boot and it was due to wrong filesystem entry on /etc/fstab.

The entry was

/dev/mapper/vgso-lvso /so xfs defaults 0 0 

and it should be ext4 mounted

/dev/mapper/vgso-lvso /so ext4 defaults 0 0 
1
  • This is the gotcha, op also states the wrong file system type. May 9, 2021 at 13:13
0

in my case changing sata cable powering both drives and restart seems to fix the problem. however I was unable to mount them on the same old point so changing them fixed for me. then I manually remove the old mount points from mnt directory :)

2
  • Welcome to the site, and thank you for your contribution. However, if you say you were "unable to mount them on the same old point" - what exactly do you mean by that? That you could no longer use the mount point you used previously to mount the drives, although you only exchanged the SATA cable?
    – AdminBee
    Oct 4, 2021 at 8:36
  • yes. before it was sda1 and somehow I was unable to mount on it. even after removing that mount from the os itself. then I used different mount name and it worked. I mean to say I change the 15 points sata power cable and sata3 data cables. Oct 7, 2021 at 5:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.