code: func prepareStage1Image(cfg PrepareConfig, cdir string) error {
  	s1 := common.Stage1ImagePath(cdir)
  	if err := os.MkdirAll(s1, common.DefaultRegularDirPerm); err != nil {
  		return errwrap.Wrap(errors.New("error creating stage1 directory"), err)
  	}
  
  	treeStoreID, _, err := cfg.TreeStore.Render(cfg.Stage1Image.String(), false)
  	if err != nil {
  		return errwrap.Wrap(errors.New("error rendering tree image"), err)
  	}
  
  	if err := writeManifest(*cfg.CommonConfig, cfg.Stage1Image, s1); err != nil {
  		return errwrap.Wrap(errors.New("error writing manifest"), err)
  	}
  
  	if !cfg.UseOverlay {
  		destRootfs := filepath.Join(s1, "rootfs")
  		cachedTreePath := cfg.TreeStore.GetRootFS(treeStoreID)
  		if err := fileutil.CopyTree(cachedTreePath, destRootfs, cfg.PrivateUsers); err != nil {
  			return errwrap.Wrap(errors.New("error rendering ACI"), err)
  		}
  	}
  
  	fn := path.Join(cdir, common.Stage1TreeStoreIDFilename)
  	if err := ioutil.WriteFile(fn, []byte(treeStoreID), common.DefaultRegularFilePerm); err != nil {
  		return errwrap.Wrap(errors.New("error writing stage1 treeStoreID"), err)
  	}
  	return nil
  }
docs: // prepareStage1Image renders and verifies tree cache of the given hash
  // when using overlay.
  // When useOverlay is false, it attempts to render and expand the stage1.