Direct copy Ramdisk image to Ramdisk device - linux

Right, so I've got a Ramdisk image on a mounted device at, say, /mnt/sda1/Ramdisk.img . I want to copy the raw data directly to a ramdisk device at /dev/ram0, in such a way that there will be no need to use mke2fs: I could mount the image and device and find that both are identical.
Ideally this would use only linux commands.
My ideas so far: Mounting the image on a loopback and using basic IO to put the data from one device into the other. I could probably do this with C.
Also, somehow finding the physical address of the ramdisk device and using linux or C commands to put the file directly into the memory.
Thanks in advance.
P.S: I know that the kernel somehow flags memory which was used for ramdisks so the system does not reclaim it. Anyone know where these flags are?

Any kind of copy command is going to require a partition and filesystem at the destination. However, dd can work at the disk or partition level, by just specifying the disk (eg /dev/sda) or partition (eg (dev/sda1) level. So in theory, you could do
dd if=ramdisk_image_file of=/dev/ram0

Related

Mounting filesystem image from physical memory in C

I'm booting linux with my own init executable which is written in C.
As a part of my init process, I want to mount a custom filesystem image which was preloaded to the physical memory (let's say at address 0xFFFF0000).
The type of the filesystem image can be changed to whatever will work, as far as it has POSIX (like ext4).
How can I mount the image successfully entirely from physical memory using C code?
What I've tried:
Mounting from /dev/mem (as seen here: http://www.qnx.com/developers/docs/qnxcar2/index.jsp?topic=%2Fcom.qnx.doc.neutrino.technotes%2Ftopic%2Fmultiple_Mounting.html), it doesn't fail but I don't see the wanted files from the image in the target directory. Moreover, this method uses char device so ext4 doesn't work since it need a block device.
Building another image file in the rootfs and filling it with the raw data from 0xFFFF0000 and mounting it. It's dumb and won't save changes to the image itself upon restarting.
Note: I've enabled loop devices for my system if needed

What are the limitations of updating kernel and device tree while running elinux?

I am trying to prepare for an event where i need to update a kernel and device tree file remotely on an embedded Linux device. I know where these objects are saved in storage, but i am not sure if my current approach to update them is optimal or even stable.
Right now the i know that:
The kernel is stored in a FAT32 partition which i can mount and see the kernel file uImage.
The device tree is stored in a section of storage accessible via a block device /dev/mmcblk1boot0 and an offset and span.
So my questions are:
Assuming Linux is up and running, is updating the kernel and device tree as simple as overwriting the
uImage file (cp new-uImage uImage) and the data at the DTB offset
(dd if=new.dtb of=/dev/mmcblk1boot0 seek=<offset>)?
Does the Kernel look at these storage location after boot?
Are there more common ways to accomplish the same result?

adding a device to another device in a raid config

If I have a device mounted in RHEL, how do I add another device to it and make it a raid0 config?
I know how to mount two new devices in a raid0 config, but how do I do it with one device that is already in use and has data on it?
Depends on the details; is it an lvm volume? Then add the new device to the volume group and extend the logical volume. Is it a file system like ZFS? Then add the device to the pool. Otherwise, you need to backup the mounted drive, unmount and create a raid0 volume.
Save you some headaches and clone the drive with a disk imaging software like Clonezilla (http://clonezilla.org/).
Once you have your drived cloned as a disk image, set up RAID0 and recover your clone to the newly created RAID, telling Clonezilla to expand to the total size of the disk.
This way, even if something goes wrong, you can always undo the whole process and just recover your clone into the original single disk as if nothing happened.
Hope it helps,
Regards
I don't think it's possible. You can't have a mounted drive and convert it into a RAID array along with another drive. You will surely have to unmount it first. More realistically, you'll probably have to reformat the drive before adding it to a RAID array. Understand that the RAID is being managed at a lower level than the OS. The OS sees the RAID array as one partition. The OS has no ability to manage or add drives to an existing RAID array.

extract file from linux bootable disk

I have a bootable IDE hard drive which has Linux on it(with GRUB bootloader).
I need to extract files inside this hard drive, but the problem is the booting fails
because of some reason... super-block or boot sector must be corrupted. (the hard drive uses EXT3 partition)
So I am trying to mount my corrupted hard drive into another system and extract data from there. however, if I mount my corrupted hard drive, the fdisk -l tells me that "Disk /dev/sdb doesn't contain a valid partition table"
In the worst case, I want to recover even some partial data off from this disk. what would be the best way to do this?? Thank you in advance.
You can run any linux live CD/DVD and then you can be able to get required files
If you want to fix boot sector then refer this link

How to get real file offset in NAND by file name?

Using linux, I can use raw access to NAND or access to files through filesystem. So, when I need to know, where my file is really located in NAND, what should I do? I cannot found any utilities providing this feature. Moreover, I cannot detect any possibility of this, besides hacking kernel with tons of "printk" (it's not nice way, I guess).
Can anybody enlighten me on this? (I'm using YAFFS2 and JFFS2 filesystems)
You can make a copy of any partition with nanddump. Transfer that partition dump to a PC. The nandsim utility can be used to mount the partitions on a PC.
modprobe nandsim first_id_byte=0x2c second_id_byte=0xda \
third_id_byte=0x90 fourth_id_byte=0x95 parts=2,64,64
flash_erase /dev/mtd3 0 0
ubiformat /dev/mtd3 -f rootfs.ubi
This command emulates a Micron 256MB NAND flash with four partitions. If you just capture the single partition and not the whole device, don't set parts. You can also do nanddump on each partition and then concatenate them all. This code targeted mtd3 with a UbiFs partition. For JFFS2 or YAFFS2, you can try nandwrite or some other appropriate flashing utility on the PC.
How to get real file offset in NAND by file name?
The files may span several NAND sectors and they are almost never contiguous. There is not much of an advantage to keep file data together as there is no disk head that takes physical time to seek. Some flash has marginally better efficiency for sequential reads; yet other flash will give better performance for reads from another erase block.
I would turn on debug at either the MTD layer or in the filesystem. In a live system, the position of the file may migrate over time on the flash even if it is not written. This is active wear leveling.

Resources