Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Neil Bothwick
On 16 January 2016 12:27:15 GMT+00:00, meino.cra...@gmx.de wrote:
> Neil Bothwick  [16-01-16 13:23]:
> > On Sat, 16 Jan 2016 13:02:04 +0100, meino.cra...@gmx.de wrote:
> > 
> > > You dd the image on a sdcard, put that one in a reader, copy two
> files
> > > from /boot to /media/boot, put the sdcard into the OrangePI-PC,
> boot
> > > it, log in via ssh and call a script named "fs_resize", the miniPC
> > > reboots...and VOILA!
> > > 
> > > Now I want to create such an image from parts of another image
> > > (kernel, firmware) and a bootable Gentoo minimal setup.
> > > 
> > > For that I need to understand the trick which is used to create
> such
> > > images.
> > 
> > Raspbian images do a similar thing, with an option in raspi_config
> to
> > resize the root filesystem to fill the card. There's no real trick,
> just
> > create the system you want on the smallest SD card that will hold
> it,
> > include the resize script and dd that card to an image.
> > 
> > 
> > -- 
> > Neil Bothwick
> > 
> > Copper wire was invented by two Scotsmen fighting over a penny!
> 
> My problem is, that I dont know which will be the final size of
> that image. So I will take a sdcard, which is big enough in 
> any case.and end up with the problem, which caused my first
> posting of this thread;)
> And I am not owning a great variety of sdcards...especially when
> it comes to feature of being EMPTY sdcards...;)
> 
> Best regards,
> Meino

Set it up on your 32GB card then, when you know how much space it uses, rsync 
it to a suitable card, like I said previously. You'll need a smaller card 
anyway, to test that it works, and microSD cards are really cheap now. 
-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Meino . Cramer
Neil Bothwick  [16-01-16 13:23]:
> On Sat, 16 Jan 2016 13:02:04 +0100, meino.cra...@gmx.de wrote:
> 
> > You dd the image on a sdcard, put that one in a reader, copy two files
> > from /boot to /media/boot, put the sdcard into the OrangePI-PC, boot
> > it, log in via ssh and call a script named "fs_resize", the miniPC
> > reboots...and VOILA!
> > 
> > Now I want to create such an image from parts of another image
> > (kernel, firmware) and a bootable Gentoo minimal setup.
> > 
> > For that I need to understand the trick which is used to create such
> > images.
> 
> Raspbian images do a similar thing, with an option in raspi_config to
> resize the root filesystem to fill the card. There's no real trick, just
> create the system you want on the smallest SD card that will hold it,
> include the resize script and dd that card to an image.
> 
> 
> -- 
> Neil Bothwick
> 
> Copper wire was invented by two Scotsmen fighting over a penny!

My problem is, that I dont know which will be the final size of
that image. So I will take a sdcard, which is big enough in 
any case.and end up with the problem, which caused my first
posting of this thread;)
And I am not owning a great variety of sdcards...especially when
it comes to feature of being EMPTY sdcards...;)

Best regards,
Meino








Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Neil Bothwick
On Sat, 16 Jan 2016 13:02:04 +0100, meino.cra...@gmx.de wrote:

> You dd the image on a sdcard, put that one in a reader, copy two files
> from /boot to /media/boot, put the sdcard into the OrangePI-PC, boot
> it, log in via ssh and call a script named "fs_resize", the miniPC
> reboots...and VOILA!
> 
> Now I want to create such an image from parts of another image
> (kernel, firmware) and a bootable Gentoo minimal setup.
> 
> For that I need to understand the trick which is used to create such
> images.

Raspbian images do a similar thing, with an option in raspi_config to
resize the root filesystem to fill the card. There's no real trick, just
create the system you want on the smallest SD card that will hold it,
include the resize script and dd that card to an image.


-- 
Neil Bothwick

Copper wire was invented by two Scotsmen fighting over a penny!


pgpvAAhF9VNVh.pgp
Description: OpenPGP digital signature


Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Meino . Cramer
Neil Bothwick  [16-01-16 12:44]:
> On Sat, 16 Jan 2016 17:53:18 +0800, Bill Kenworthy wrote:
> 
> > It is possible to create a dd image of the whole SD card and mount it in
> > a loopback to repartition etc.
> > 
> > Mount it then shrink your existing file system (and probably the
> > partition too) to less than the required size, then recreate the dd
> > image to a size still less than the new sd card.
> > 
> > On the new card, dd it across until it errors off, then fix/expand the
> > partition and then the file system.  You dont care if the end is missing
> > as long as your data is within the size needed.
> 
> I get the impression that Meino is trying to keep it as simple as
> possible for the other user, so fixing after errors is not a good idea.
> Otherwise you could do what you suggest with the original card, shrink the
> filesystem and partition to fit a smaller card then create a dd image
> that will overflow but should work.
> 
> 
> -- 
> Neil Bothwick
> 
> RISC: Reduced Into Silly Code


Hi,

Neil is completly right here (Neil, you are completly right here! :)

Background: There is a cheap (15$) version of the Raspberry PI, which 
is based on a 4core, 1.2GHz Allwinner H3 CPU -- the OrangePI-PC

There are available several firmware images available for this board,
and each images can do a certain thing better than another (for
example hardware accelerated graphic). 

You dd the image on a sdcard, put that one in a reader, copy two files
from /boot to /media/boot, put the sdcard into the OrangePI-PC, boot
it, log in via ssh and call a script named "fs_resize", the miniPC
reboots...and VOILA!

Now I want to create such an image from parts of another image
(kernel, firmware) and a bootable Gentoo minimal setup.

For that I need to understand the trick which is used to create such
images.

The script mentioned above is this one:


#!/bin/bash

# **
# Resize Linux ext4 partition to fill sdcard
# **

if [ "$(id -u)" != "0" ]; then
echo "Script must be run as root !"
exit 0
fi

_REL=`lsb_release -sc`

_rootpart=`mount | grep "on / " | awk '{print $1}'`
if [ "${_rootpart}" = "/dev/mmcblk0p2" ]; then
rootdrv="mmcblk0p2"
sdcard="/dev/mmcblk0"
elif [ "${_rootpart}" = "/dev/mmcblk1p2" ]; then
rootdrv="mmcblk1p2"
sdcard="/dev/mmcblk1"
else
echo "Root fs mount partition not found!"
exit 1
fi
echo ""

fdisk -l $sdcard | grep $sdcard
echo ""

_btrfs=`mount | grep -o btrfs`

sdcard_part=`fdisk -l $sdcard | grep $rootdrv | awk '{print $1}'`
sdcard_sect=`fdisk -l $sdcard | grep "Disk $sdcard" | awk '{print $7}'`
if [ "${sdcard_sect}" = "" ]; then
sdcard_sect=`fdisk -l $sdcard | grep total | awk '{print $8}'`
fi
sdcard_end=$(expr $sdcard_sect - 1024)

part_start=`fdisk -l $sdcard | grep $rootdrv | awk '{print $2}'`
part_end=`fdisk -l $sdcard | grep $rootdrv | awk '{print $3}'`

echo "  Max block: $sdcard_end"
echo "   Part end: $part_end"
echo " Part start: $part_start"
if [ ! "${_btrfs}" = "" ]; then
echo " btrfs part: yes"
_resize="btrfs filesystem resize max /"
else
_resize="resize2fs ${sdcard_part}"
fi
echo ""
if [ $part_end -ge $sdcard_end ]; then
echo "Partition allready maximum size !"
rm /usr/local/bin/fs_resize_warning > /dev/null 2>&1
exit 0
fi

echo -n "WARNING: Do you want to resize \"$sdcard_part\" (y/N)?  "
read -n 1 ANSWER
if [ ! "${ANSWER}" = "y" ] ; then
echo ""
echo "Canceled.."
exit 0
fi
echo ""

# RESIZE PARTITION

echo -e "p\nd\n2\nn\np\n2\n$part_start\n$sdcard_end\nw" | fdisk ${sdcard} > 
/dev/null 2>&1
#if [ $? -ne 0 ]; then
#   echo "ERROR resizing partition!"
#   exit 1
#fi

echo "PARTITION RESIZED."

mv /etc/rc.local /etc/rc.local.orig

cat > /etc/rc.local << _EOF_
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# ** Overclock to 1.728 GHz
#echo 1728000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

echo 0 > /proc/sys/kernel/hung_task_timeout_secs

dmesg -n 1

/usr/local/bin/resize_fs &&

_EOF_

echo "exit 0" >> /etc/rc.local
chmod +x /etc/rc.local > /dev/null 2>&1

cat > /usr/local/bin/resize_fs << _EOF_
#!/bin/bash
$_resize
if [ \$? -eq 0 ]; then
rm /usr/local/bin/fs_resize_warning
rm /usr/local/bin/resize_fs
sleep 2
rm /etc/rc.local
mv /etc/rc.local.orig /etc/rc.local
fi
_EOF_

chmod +x /usr/local/bin/resize_fs > /dev/null 2>&1


REBOOT=1
echo "*"
echo "Rootfs Extended. Please REBOOT to take effect"
echo "*"
echo ""



Best regards,
Meino





Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Neil Bothwick
On Sat, 16 Jan 2016 17:53:18 +0800, Bill Kenworthy wrote:

> It is possible to create a dd image of the whole SD card and mount it in
> a loopback to repartition etc.
> 
> Mount it then shrink your existing file system (and probably the
> partition too) to less than the required size, then recreate the dd
> image to a size still less than the new sd card.
> 
> On the new card, dd it across until it errors off, then fix/expand the
> partition and then the file system.  You dont care if the end is missing
> as long as your data is within the size needed.

I get the impression that Meino is trying to keep it as simple as
possible for the other user, so fixing after errors is not a good idea.
Otherwise you could do what you suggest with the original card, shrink the
filesystem and partition to fit a smaller card then create a dd image
that will overflow but should work.


-- 
Neil Bothwick

RISC: Reduced Into Silly Code


pgpnj2F8SLj1Y.pgp
Description: OpenPGP digital signature


Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Meino . Cramer
Bill Kenworthy  [16-01-16 11:04]:
> On 16/01/16 17:27, Neil Bothwick wrote:
> > On Sat, 16 Jan 2016 04:50:49 +0100, meino.cra...@gmx.de wrote:
> > 
> >> to post a firmware image of my embedded linux computer
> >> to a friend I want to size it down.
> >>
> >> System wise I did that already (only the really necessary
> >> stuff of Gentoo plus some configuration and addons related
> >> to the embedded system)...the problem comes with the size of
> >> the microSDcard I use: 32 GB
> >>
> >> The microSDcard (source) has two partitions (boot + the rest).
> >> The boot partition is the first partition and it is of a fixed
> >> and tiny size. The second partition contains the "rest": Gentoo.
> >> Currently the used space of this partition is also small.
> >>
> >> The image needs to be of a format, which makes
> >> it possble to 'dd' it onto a microSDcard (target) and afterwards use
> >> g/parted to resize/expand the second partition to the end
> >> of the microSDcard to get all storage space available.
> > 
> > Quick and kludgy. Partition an SD card of the correct size, rsync your
> > data to it, then dd that card.
> > 
> > Any other method you use will require you to have a smaller SD card to
> > test the resultant image, so you may as well use that as the source and
> > know it works.
> > 
> > 
> 
> It is possible to create a dd image of the whole SD card and mount it in
> a loopback to repartition etc.
> 
> Mount it then shrink your existing file system (and probably the
> partition too) to less than the required size, then recreate the dd
> image to a size still less than the new sd card.
> 
> On the new card, dd it across until it errors off, then fix/expand the
> partition and then the file system.  You dont care if the end is missing
> as long as your data is within the size needed.
> 
> BillK
> 
> 
> 
Hi Neil, hi Bill,

THANKS FOR THE EXPLANATIONS! :)

Will try that!

Best regards,
Meino





Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Bill Kenworthy
On 16/01/16 17:27, Neil Bothwick wrote:
> On Sat, 16 Jan 2016 04:50:49 +0100, meino.cra...@gmx.de wrote:
> 
>> to post a firmware image of my embedded linux computer
>> to a friend I want to size it down.
>>
>> System wise I did that already (only the really necessary
>> stuff of Gentoo plus some configuration and addons related
>> to the embedded system)...the problem comes with the size of
>> the microSDcard I use: 32 GB
>>
>> The microSDcard (source) has two partitions (boot + the rest).
>> The boot partition is the first partition and it is of a fixed
>> and tiny size. The second partition contains the "rest": Gentoo.
>> Currently the used space of this partition is also small.
>>
>> The image needs to be of a format, which makes
>> it possble to 'dd' it onto a microSDcard (target) and afterwards use
>> g/parted to resize/expand the second partition to the end
>> of the microSDcard to get all storage space available.
> 
> Quick and kludgy. Partition an SD card of the correct size, rsync your
> data to it, then dd that card.
> 
> Any other method you use will require you to have a smaller SD card to
> test the resultant image, so you may as well use that as the source and
> know it works.
> 
> 

It is possible to create a dd image of the whole SD card and mount it in
a loopback to repartition etc.

Mount it then shrink your existing file system (and probably the
partition too) to less than the required size, then recreate the dd
image to a size still less than the new sd card.

On the new card, dd it across until it errors off, then fix/expand the
partition and then the file system.  You dont care if the end is missing
as long as your data is within the size needed.

BillK





Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-16 Thread Neil Bothwick
On Sat, 16 Jan 2016 04:50:49 +0100, meino.cra...@gmx.de wrote:

> to post a firmware image of my embedded linux computer
> to a friend I want to size it down.
> 
> System wise I did that already (only the really necessary
> stuff of Gentoo plus some configuration and addons related
> to the embedded system)...the problem comes with the size of
> the microSDcard I use: 32 GB
> 
> The microSDcard (source) has two partitions (boot + the rest).
> The boot partition is the first partition and it is of a fixed
> and tiny size. The second partition contains the "rest": Gentoo.
> Currently the used space of this partition is also small.
> 
> The image needs to be of a format, which makes
> it possble to 'dd' it onto a microSDcard (target) and afterwards use
> g/parted to resize/expand the second partition to the end
> of the microSDcard to get all storage space available.

Quick and kludgy. Partition an SD card of the correct size, rsync your
data to it, then dd that card.

Any other method you use will require you to have a smaller SD card to
test the resultant image, so you may as well use that as the source and
know it works.


-- 
Neil Bothwick

Things which must be shipped together as a set, aren't.


pgpaTLSsB82FQ.pgp
Description: OpenPGP digital signature


Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-15 Thread Meino . Cramer
J. Roeleveld  [16-01-16 07:24]:
> On 16 January 2016 04:50:49 CET, meino.cra...@gmx.de wrote:
> >Hi,
> >
> >to post a firmware image of my embedded linux computer
> >to a friend I want to size it down.
> >
> >System wise I did that already (only the really necessary
> >stuff of Gentoo plus some configuration and addons related
> >to the embedded system)...the problem comes with the size of
> >the microSDcard I use: 32 GB
> >
> >The microSDcard (source) has two partitions (boot + the rest).
> >The boot partition is the first partition and it is of a fixed
> >and tiny size. The second partition contains the "rest": Gentoo.
> >Currently the used space of this partition is also small.
> >
> >The image needs to be of a format, which makes
> >it possble to 'dd' it onto a microSDcard (target) and afterwards use
> >g/parted to resize/expand the second partition to the end
> >of the microSDcard to get all storage space available.
> >
> >If I dd the source into an image I get all those zeroes also and
> >the image only will fit onto a microSDcard (target) of at least
> >the same size.
> >
> >If I dd each partition separately I get two files and the partition
> >table is not copied...may be technically possible but not user
> >friendly.
> >
> >How can I manage to get an image from my microSDcard (source), which
> >only consists of the used space in a way that it can be put onto 
> >another microSDcard (target) in the waay described above?
> >
> >How can I acchieve that magic ?  ;) :)
> >
> >Thank you very much in advance for any help!
> >Best regards,
> >Meino
> 
> I would create a script that partitions and formats the sdcard.
> Then untar the contents of the partitions
> Then set up the bootloader.
> 
> This should lead to a small size which is also user friendly.
> 
> --
> Joost 
> -- 
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
> 

Hi Joost,

thanks for your help.

Due to technical circumstances I am urged to use the "dd-way" to 
create the contents.

How can I accomplish, what I have described?

Thank you very much in advance for any help ! :)

Best regards,
Meino





Re: [gentoo-user] Creating an firmware image from a too large microSDcard...?

2016-01-15 Thread J. Roeleveld
On 16 January 2016 04:50:49 CET, meino.cra...@gmx.de wrote:
>Hi,
>
>to post a firmware image of my embedded linux computer
>to a friend I want to size it down.
>
>System wise I did that already (only the really necessary
>stuff of Gentoo plus some configuration and addons related
>to the embedded system)...the problem comes with the size of
>the microSDcard I use: 32 GB
>
>The microSDcard (source) has two partitions (boot + the rest).
>The boot partition is the first partition and it is of a fixed
>and tiny size. The second partition contains the "rest": Gentoo.
>Currently the used space of this partition is also small.
>
>The image needs to be of a format, which makes
>it possble to 'dd' it onto a microSDcard (target) and afterwards use
>g/parted to resize/expand the second partition to the end
>of the microSDcard to get all storage space available.
>
>If I dd the source into an image I get all those zeroes also and
>the image only will fit onto a microSDcard (target) of at least
>the same size.
>
>If I dd each partition separately I get two files and the partition
>table is not copied...may be technically possible but not user
>friendly.
>
>How can I manage to get an image from my microSDcard (source), which
>only consists of the used space in a way that it can be put onto 
>another microSDcard (target) in the waay described above?
>
>How can I acchieve that magic ?  ;) :)
>
>Thank you very much in advance for any help!
>Best regards,
>Meino

I would create a script that partitions and formats the sdcard.
Then untar the contents of the partitions
Then set up the bootloader.

This should lead to a small size which is also user friendly.

--
Joost 
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.