https://github.com/hqarroum/initrd-snapshot
:camera: Library and tools to create and parse initial ramdisk snapshots.
https://github.com/hqarroum/initrd-snapshot
archiver initrd
Last synced: 8 months ago
JSON representation
:camera: Library and tools to create and parse initial ramdisk snapshots.
- Host: GitHub
- URL: https://github.com/hqarroum/initrd-snapshot
- Owner: HQarroum
- License: mit
- Created: 2016-09-03T21:04:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-10T13:05:44.000Z (over 9 years ago)
- Last Synced: 2025-03-28T07:27:43.520Z (about 1 year ago)
- Topics: archiver, initrd
- Language: C++
- Homepage:
- Size: 234 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Library and tools to create and parse initial ramdisk snapshots.
## Description
Initial ramdisks (initrd) provide the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root file system and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root (from initrd) is then moved to a directory and can be subsequently unmounted.
`initrd` snapshots are mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and where additional modules are loaded from `initrd`.
This project contains different components, namely :
* A C++11 library initially developped to provide the [Microcosm Kernel](https://github.com/HQarroum/microcosm) with the ability to load its root filesystem, though it is not dependant on any of microcosm's software components.
* A set of POSIX tools built on top the library to create and browse initrd images.
## Library usage
### Creating an image in memory
In order to create an `initrd` image you can use the image builder that is bundled with the library before writing it to a file :
```c++
auto image = initrd::builder_t()
.addFile({ file: file_1, size: size_of_file_1 })
.addFile({ file: file_2, size: size_of_file_2 })
.addFiles(list_of_files)
.build()
```
### Writing the image to disk
Once the image has been constructed in memory, you can write the image raw data to disk by calling the `.data()` accessor on the `initrd::image_t` class :
```c++
std::ofstream file("initrd.img", std::ofstream::out);
file.write(image.data(), image.size());
```
### Reading an image from disk
The operation here involves loading an image from the disk, and passing it to `initrd::reader_t` :
```c++
try {
auto file = read_file("./initrd.img");
initrd::reader_t reader(file.data(), file.size());
std::cout << reader.image() << std::endl;
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
```