{"record":{"id":"c8c77c24bc4bb845","repo":"hyperledger/fabric","slug":"error-while-creating-the-dir-s-ensure-peer-has","errorCode":null,"errorMessage":"error while creating the dir: %s, ensure peer has write access to configured ledger.snapshots.rootDir directory","messagePattern":"error while creating the dir: (.+?), ensure peer has write access to configured ledger\\.snapshots\\.rootDir directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/kv_ledger_provider.go","lineNumber":261,"sourceCode":"\nfunc (p *Provider) initLedgerStatistics() {\n\tp.stats = newStats(p.initializer.MetricsProvider)\n}\n\nfunc (p *Provider) initSnapshotDir() error {\n\tsnapshotsRootDir := p.initializer.Config.SnapshotsConfig.RootDir\n\tif !filepath.IsAbs(snapshotsRootDir) {\n\t\treturn errors.Errorf(\"invalid path: %s. The path for the snapshot dir is expected to be an absolute path\", snapshotsRootDir)\n\t}\n\n\tinProgressSnapshotsPath := SnapshotsTempDirPath(snapshotsRootDir)\n\tcompletedSnapshotsPath := CompletedSnapshotsPath(snapshotsRootDir)\n\n\tif err := os.RemoveAll(inProgressSnapshotsPath); err != nil {\n\t\treturn errors.Wrapf(err, \"error while deleting the dir: %s\", inProgressSnapshotsPath)\n\t}\n\tif err := os.MkdirAll(inProgressSnapshotsPath, 0o755); err != nil {\n\t\treturn errors.Wrapf(err, \"error while creating the dir: %s, ensure peer has write access to configured ledger.snapshots.rootDir directory\", inProgressSnapshotsPath)\n\t}\n\tif err := os.MkdirAll(completedSnapshotsPath, 0o755); err != nil {\n\t\treturn errors.Wrapf(err, \"error while creating the dir: %s, ensure peer has write access to configured ledger.snapshots.rootDir directory\", completedSnapshotsPath)\n\t}\n\treturn fileutil.SyncDir(snapshotsRootDir)\n}\n\n// CreateFromGenesisBlock implements the corresponding method from interface ledger.PeerLedgerProvider\n// This function creates a new ledger and commits the genesis block. If a failure happens during this\n// process, the partially created ledger is deleted\nfunc (p *Provider) CreateFromGenesisBlock(genesisBlock *common.Block) (ledger.PeerLedger, error) {\n\tledgerID, err := protoutil.GetChannelIDFromBlock(genesisBlock)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif err = p.idStore.createLedgerID(\n\t\tledgerID,\n\t\t&msgs.LedgerMetadata{","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/kv_ledger_provider.go#L243-L279","documentation":"initSnapshotDir wraps the os.MkdirAll error when creating either the in-progress or completed snapshots directory under the configured root fails. Fabric ensures both directories exist (mode 0755) at provider startup; failure to create them halts peer startup with this message advising a write-access check on ledger.snapshots.rootDir.","triggerScenarios":"Peer startup (NewProvider -> initSnapshotDir) when os.MkdirAll fails for SnapshotsTempDirPath or CompletedSnapshotsPath: parent dir missing and uncreatable, no write permission, read-only mount, or path is actually a file.","commonSituations":"Snapshots rootDir pointing to a read-only volume, path exists as a regular file, peer running as non-root without rights to the configured directory, or typo'd path under a non-writable parent.","solutions":["Confirm the peer's OS user has write access to ledger.snapshots.rootDir (chown/chmod)","Ensure the rootDir path is a directory, not a file; remove/rename any conflicting file","Remount the volume read-write if mounted read-only","Create the directory manually with mode 0755 and restart the peer"],"exampleFix":"// before: error while creating the dir: /var/hyperledger/production/snapshots/completedSnapshots: mkdir: read-only file system\n// after:\n# mkdir -p -m 0755 /var/hyperledger/production/snapshots/{inProgressSnapshots,completedSnapshots}\n# chown -R fabric:fabric /var/hyperledger/production/snapshots\n# peer node start","handlingStrategy":"validation","validationCode":"rootDir := viper.GetString(\"ledger.snapshots.rootDir\")\nif info, err := os.Stat(rootDir); err != nil {\n    return fmt.Errorf(\"snapshots rootDir %q missing\", rootDir)\n} else if !info.IsDir() {\n    return fmt.Errorf(\"snapshots rootDir %q is not a directory\", rootDir)\n} else if !isWritable(rootDir) {\n    return fmt.Errorf(\"no write access to snapshots rootDir %q\", rootDir)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create inProgressSnapshots and completedSnapshots with mode 0755","Verify volume is writable by the peer's runtime user before deployment","Ensure ledger.snapshots.rootDir points to a directory, not a file"],"tags":["hyperledger-fabric","snapshot","filesystem","permissions","configuration"],"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"}