What do I do if a NameNode cannot be started after it is formatted?

Updated at:
Copy as MD

If you format a NameNode in an E-MapReduce (EMR) cluster as the root user and then try to start it, the NameNode fails to start because the hdfs user does not have permissions on files owned by root.

Error message

ERROR namenode.NameNode: Failed to start namenode.

Cause

Running hadoop namenode -format as the root user creates NameNode metadata files owned by root. When the NameNode service starts, it runs as the hdfs user, which cannot read those files — causing the startup failure.

Solution

  1. Stop all Hadoop Distributed File System (HDFS) components, including NameNode and DataNode.

  2. Switch to the hdfs user and reformat the NameNode:

    Warning

    hadoop namenode -format deletes all HDFS metadata. Run it only when HDFS contains no data you need to keep. In this scenario, the NameNode was already formatted as root with no data in HDFS, so it is safe to reformat.

    su hdfs
    [hdfs]$ hadoop namenode -format

    If permission errors occur on specific directories during formatting, grant the hdfs user the required permissions on those directories and retry.

  3. Start the NameNode:

    [hdfs]$ /usr/lib/hadoop-current/sbin/hadoop-daemon.sh start namenode
  4. Verify that HDFS is operating correctly:

    [hdfs]$ hadoop fs -ls
    [hdfs]$ hadoop fs -put
    [hdfs]$ hadoop fs -get
  5. Run an MR job to confirm that YARN is working as expected.