LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 03-20-2019, 06:29 AM   #1
sebbl
LQ Newbie
 
Registered: Mar 2019
Posts: 3

Rep: Reputation: Disabled
Create complete, partitioned card image for an (embedded) Linux


Hi,

first of all: hello together, I'm new to that forum, but not new to Linux & Embedded

My problem:

I want to create a complete image for a CF/sd card (kind of memory card doesn't matter) including all approriate partitions. In my case, I have 3 partitions, boot, an embedded linux and a third one for temporary stuff.
Now I want to create an image file with the size of my CF card, e.g. 1GB.
I don't want to use a CF card for that, so partitioning a CF card, copying the files and using dd afterwards to clone the whole CF-card is not an option.
We already tried that with a shell script, what actually works, but I want to ensure if there is a more common or safe way, and that our approach is not unsafe, error-prone etc.
Roughly, I do the following:
- Create an empty 1GB file with dd /dev/zero -> IMAGE_FILE
- Write the partition table to that image file using sfdisk
- create loop devices for my partitions, e.g.
/sbin/losetup /dev/loop0 IMAGE_FILE
/sbin/losetup /dev/loop1 IMAGE_FILE -o [offset for first partition ...]
etc.
- create file systems, e.g. /sbin/mkfs.ext3 /dev/loop1
- mount the loop devices
- copy files there
- install grub on /dev/loop0
- unmount, cleanup etc.

Is this a common and reilable way? Are there tools supporting this kind of work?

thanks a lot in advance!

sebastian
 
Old 03-20-2019, 07:14 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,020

Rep: Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102Reputation: 4102
The only part I'd be worried about is using losetup with offset - have a look at kpartx to do it automatically for you.
 
Old 03-20-2019, 11:02 AM   #3
sebbl
LQ Newbie
 
Registered: Mar 2019
Posts: 3

Original Poster
Rep: Reputation: Disabled
Ok, thanks. In fact, kpartx is more comfortable. But currently I face the problem, that it is not deterministic, which loop device it will use for my image file, so I do not know, which to use in the subsequent command. In detail, after the kpartx command, I want to do
/sbin/mkfs.ext3 /dev/mapper/loopXp1 etc.
How to define X before or determine afterwards? Of course I can parse kpartx output with awk ...

thanks and regards,
sebastian
 
Old 03-21-2019, 11:45 AM   #4
sebbl
LQ Newbie
 
Registered: Mar 2019
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi,

with the kpartx approach, I'm facing the problem, that grub installation does not seem to work any more when using losetup if works.
I call grub (0.97, embedded elinos Linux) with --batch in exactly the same way as before:

$GrubBin/grub --batch <<EOT &> grub.log
device (hd0) /dev/loop0
root (hd0,0)
setup (hd0)
quit
EOT

The grub call does not give an error, but the image, copied to a CF card, does not boot any more.

The difference now of course is in the loop device setup. With losetup, I had loop0 and then loop1-3 as partitions. Now I have the /dev/mapper structure from kpartx.

Does anyone have an idea?

Thanks and regards,
Sebastian
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to create an image of a partitioned disk williepabon Ubuntu 3 01-25-2013 08:48 PM
Partitioned LINUX, need dd command to obtain image concsk Linux - Newbie 1 05-07-2012 05:35 PM
Need to know the command which shows all non-partitioned & partitioned hard drive saidul Linux - Newbie 2 12-04-2007 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 11:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration