LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-20-2011, 08:44 AM   #1
PrayingMantis
LQ Newbie
 
Registered: Nov 2011
Distribution: WindRiver, RedHat
Posts: 17

Rep: Reputation: Disabled
Problem reducing size for CF Card image using USB


Hi,

I am having an existing CF card image of size 512M, which I wish to unpack to a 4GB USB Stick, upgrade the kernel and initrd on the image and pack it again. So basically here is what I'm doing:

_1. I dd out the existing 512M image to the usb stick, mounted on /dev/sdb
dd if=cf_image.img of=/dev/sdb bs=16384
I observe, the size of the USB is now shown as 512M.
_2. I upgrade the kernel and the initrd on the USB stick.
_3. When I pack the usb back, the size of the image file i get is 4GB and not 512M.
dd if=/dev/zero of=/dev/sdb/zero bs=16384
rm -f zero
dd if=/dev/sdb of=./new_cf.img bs=16384

What am I doing wrong?
Will a sync help?

BTW my img file has two partitions, one small linux partition containing grub to boot up, and a FAT16 partition containing the kernel and the initrd image.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-21-2011, 11:51 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Don't copy the image to the USB stick. Just mount it (or better a copy of it, if something goes wrong), make your changes and use dd to copy it back to the CF card.
 
2 members found this post helpful.
Old 11-22-2011, 11:44 AM   #3
PrayingMantis
LQ Newbie
 
Registered: Nov 2011
Distribution: WindRiver, RedHat
Posts: 17

Original Poster
Rep: Reputation: Disabled
Hi Tobi,

Thanks for the reply.

But I'm not able to mount the CF card image. The image consists of a small linux partition (containing grub for booting up) and a windows partition (have the kernel and the initrd). It asks for the file system type while mounting.

Mantis
 
Old 11-22-2011, 12:05 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
When it contains partitions you have to mount it with an offset. To get the right offset value just use
Code:
fdisk -l YOURIMAGEFILE
It will show something like this:
Code:
tobi@monster ~ :) % fdisk -l test.img

Disk test.img: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7b36c16a

   Device Boot      Start         End      Blocks   Id  System
test.img1            2048       43007       20480   83  Linux
test.img2           43008     1048575      502784   83  Linux
As you can see, the first partition begins with sector 2048 and the sector size is 512 bytes, so the correct offset is 2048*512 = 1048576. To mount the first partition of my image file to /mnt you would launch the mount command this way:
Code:
mount -o loop,offset=1048576 test.img /mnt
In this example the offset for the second partition would be 43008*512 = 22020096.
 
1 members found this post helpful.
Old 11-23-2011, 09:22 AM   #5
PrayingMantis
LQ Newbie
 
Registered: Nov 2011
Distribution: WindRiver, RedHat
Posts: 17

Original Poster
Rep: Reputation: Disabled
Hi Tobi,

It works.. !! I have mounted the image file and made changes.

Thank you very much..

Mantis
 
  


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
Reducing size in LVM SBN Linux - General 8 07-28-2009 06:30 AM
Reducing Debian Installation Size??? kushalkoolwal Debian 18 08-15-2005 01:58 PM
Reducing file size using mencoder SithX Linux - Software 3 04-15-2005 08:56 PM
Reducing kernel size Kholnuu Slackware 6 01-22-2005 02:57 AM
reducing the size of linux partitions cybergir Linux - Newbie 1 02-04-2003 03:58 PM

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

All times are GMT -5. The time now is 06:11 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