{"record":{"id":"41590e0852b44f65","repo":"hyperledger/fabric","slug":"error-creating-block-storage-root-dir-s-s","errorCode":null,"errorMessage":"Error creating block storage root dir [%s]: %s","messagePattern":"Error creating block storage root dir \\[(.+?)\\]: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/ledger/blkstorage/blockfile_mgr.go","lineNumber":100,"sourceCode":"\t\t\t-- Loads from db if exist, if not instantiate a new blockfilesInfo\n\t\t\t-- If blockfilesInfo was loaded from db, compares to FS\n\t\t\t-- If blockfilesInfo and file system are not in sync, syncs blockfilesInfo from FS\n\t  *) Starts a new file writer\n\t\t\t-- truncates file per blockfilesInfo to remove any excess past last block\n\t  *) Determines the index information used to find tx and blocks in\n\t  the file blkstorage\n\t\t\t-- Instantiates a new blockIdxInfo\n\t\t\t-- Loads the index from the db if exists\n\t\t\t-- syncIndex comparing the last block indexed to what is in the FS\n\t\t\t-- If index and file system are not in sync, syncs index from the FS\n\t  *)  Updates blockchain info used by the APIs\n*/\nfunc newBlockfileMgr(id string, conf *Conf, indexConfig *IndexConfig, indexStore *leveldbhelper.DBHandle) (*blockfileMgr, error) {\n\tlogger.Debugf(\"newBlockfileMgr() initializing file-based block storage for ledger: %s \", id)\n\trootDir := conf.getLedgerBlockDir(id)\n\t_, err := fileutil.CreateDirIfMissing(rootDir)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Error creating block storage root dir [%s]: %s\", rootDir, err))\n\t}\n\tmgr := &blockfileMgr{rootDir: rootDir, conf: conf, db: indexStore, cache: newCache(defaultBlockCacheSizeBytes)}\n\n\tblockfilesInfo, err := mgr.loadBlkfilesInfo()\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Could not get block file info for current block file from db: %s\", err))\n\t}\n\tif blockfilesInfo == nil {\n\t\tlogger.Info(`Getting block information from block storage`)\n\t\tif blockfilesInfo, err = constructBlockfilesInfo(rootDir); err != nil {\n\t\t\tpanic(fmt.Sprintf(\"Could not build blockfilesInfo info from block files: %s\", err))\n\t\t}\n\t\tlogger.Debugf(\"Info constructed by scanning the blocks dir = %s\", spew.Sdump(blockfilesInfo))\n\t} else {\n\t\tlogger.Debug(`Syncing block information from block storage (if needed)`)\n\t\tsyncBlockfilesInfoFromFS(rootDir, blockfilesInfo)\n\t}\n\terr = mgr.saveBlkfilesInfo(blockfilesInfo, true)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockfile_mgr.go#L82-L118","documentation":"newBlockfileMgr panics when fileutil.CreateDirIfMissing cannot create (or confirm) the ledger's block storage root directory. Without the dir the block store cannot initialize, so startup is aborted via panic.","triggerScenarios":"CreateDirIfMissing returns an error: parent path does not exist and cannot be created, permission denied, path exists as a file, or filesystem is read-only/full.","commonSituations":"Wrong peer configuration for fileLedger storage path; read-only container rootfs or volume; ledger path exists as a regular file left by a bad restore; running peer as a user without write access to /var/hyperledger.","solutions":["Create/repair the storage path and grant write access to the peer user (mkdir -p; chown)","Fix peer config (core.yaml fileLedger blockStorage path) or mount a writable volume at that path","If a file occupies the ledger path, remove it or move data to a fresh dir"],"exampleFix":"// before: peer config points to read-only path\n// fileLedger:\n//   storageDirectory: /ro-mount/ledgersData\n// after:\n// fileLedger:\n//   storageDirectory: /var/hyperledger/production/ledgersData","handlingStrategy":"validation","validationCode":"rootDir := conf.getLedgerBlockDir(id)\nif err := os.MkdirAll(rootDir, 0o755); err != nil {\n    return nil, fmt.Errorf(\"cannot create block storage dir %s: %w\", rootDir, err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"block storage init failed: %v\", r)\n    }\n}()","preventionTips":["Verify the configured fileLedger storage path is writable before peer start (touch test)","Never mount the ledger volume read-only","Ensure the path is a directory, not a file, and parent dirs exist","Provision disk space before startup"],"tags":["filesystem","permissions","configuration","panic"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}