robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Partitioning

Mon Feb 27, 2017 2:40 am

Hi - was wondering if anyone could help with this I am stuck..?? Our codebase got imaged and the image works fine. The issue is that the image was taken of the whole 16gb SD card and the codebase is only 4GB. This has left me with a 16GB image which is too large to distribute online. I am trying to figure out the correct course of action to create a new image of only the code base needed. I am on a mac and so far I have tried gparted which I can't get installed on the mac. I am assuming there is a named partition that I need to find and and then use as part of the dd command?

User avatar
DougieLawson
Posts: 29760
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Partitioning

Mon Feb 27, 2017 7:52 am

Get another SDCard and a USB reader. Build a copy of plain Raspbian on the new SDCard, boot that. Put your card with the partitioning problems in the USB reader, plug the USB reader into your RPi.

sudo apt-get install gparted
You can then use sudo gparted to resize/move the partitions on your card (get it down to 3.9GB). Then take a new image of that smaller card.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Re: Partitioning

Mon Feb 27, 2017 6:44 pm

Hi, thanks a ton. The first part worked I was able to view and shrink partition 2 to end at 7.9GB however then when I run dd it's still creating a 16GB image from the card.

2 ends now at 7.9GB....

Number Start End Size Type File system Flags
1 4194kB 70.3MB 66.1MB primary fat16 lba
2 70.3MB 15.5GB 15.4GB primary ext4

I am trying to figure out the dd string to create the image from just the data not all of the empty space...
http://www.linuxnix.com/what-you-should ... d-command/

User avatar
DougieLawson
Posts: 29760
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Partitioning

Mon Feb 27, 2017 8:28 pm

Take a dd copy of /dev/sda1 and /dev/sda2 seperately. Build an 8GB card with a partition table that has enough space for those two dd copies and dd them back.

dd of /dev/sda is as dumb as a dumb thing on a dumb day and without a block count parameter will always copy the full card even the, now, empty bits.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Re: Partitioning

Tue Mar 07, 2017 2:23 pm

Thanks a ton for the help!

robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Re: Partitioning

Wed Aug 09, 2017 12:53 am

Hi I was wondering if you could answer this. I am trying to use dd to copy only the first partition which I believe is named boot. I keep getting no such directory when trying

dd if=/dev/disk2/boot of=biblisda1.img

or

dd if=/dev/disk2/sda1 of=biblisda1.img
diskutil.png
diskutil.png (147.08 KiB) Viewed 808 times
cmd line diskutil.png
cmd line diskutil.png (53.17 KiB) Viewed 808 times
Much appreciated I know I am close to understanding this!

User avatar
rpdom
Posts: 11525
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Partitioning

Wed Aug 09, 2017 5:21 am

I don't know a lot about apples, but on that last image of the text screen the boot partition looks like it is /dev/disk3s1 and the main Linux area is /dev/disk3s2. If you are doing any "raw" operations on them, like dd, you will probably find it runs quicker if you use the raw disk interface (which doesn't require as much processing of the data), /dev/rdisk3s1 and /dev/rdisk3s2.

robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Re: Partitioning

Sat Aug 12, 2017 3:05 am

Hey thanks a ton that worked for the copy. I finally got the data

It doesn't boot. So close. I used a freshly formatted sd card and ran the command:

Jalalis-MacBook-Air:~ jalalihartman$ sudo dd of=/dev/disk3s1 if=biblisda1.img
129024+0 records in
129024+0 records out
66060288 bytes transferred in 35.211285 secs (1876111 bytes/sec)

do I have to dd the 2nd partition if it appears to be empty? what am I missing....trying to get this under 5mb and running on the pi so I can give out free on sourceforge.

do i just make the of=/dev/disk3?

also would love if anyone just has a link of what to study up on to do this. so many rabbit holes out there that are wrong info

thanks!!

User avatar
rpdom
Posts: 11525
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Partitioning

Sat Aug 12, 2017 6:10 am

The first partition only contains the boot files. Everything else is in the second partition, which you won't be able to look at on a Mac OS.

robautoproject
Posts: 16
Joined: Sat Feb 22, 2014 6:56 pm
Contact: Website

Re: Partitioning

Sat Aug 12, 2017 7:29 pm

Ok, so second partition would be?

Jalalis-MacBook-Air:~ jalalihartman$ sudo dd if=/dev/rdisk3s2 of=biblisda2.img

So I am assuming I need to specify dd to only copy the first x gb? or do I somehow shrink all the dead space in partition 2?

Thanks!!!

User avatar
rpdom
Posts: 11525
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Partitioning

Sat Aug 12, 2017 7:37 pm

You can't just copy the first xGB, file systems don't work that way. You need to shrink the file system first and then copy the data.

The easiest way to copy the SD card contents to another card (smaller of larger) is to use the SD card copier (piclone) on running Pi with the new SD card in a USB adaptor.

User avatar
mattrix
Posts: 120
Joined: Mon Mar 02, 2015 6:20 am
Location: Christchurch, New Zealand
Contact: Website

Re: Partitioning

Thu Aug 24, 2017 3:20 am

I use a bash script I wrote to shrink images as much as possible (multiple passes).
You pass it the /dev/sdX and an image ouput.
Once it's schrinked as much as possible, it outputs the img.

Here's the script:
https://pastebin.com/PcutjdRx
(use at your own risk)

run like

Code: Select all

sudo ./shrink.sh sdX shrunk.img
www.matthuisman.nz

Return to “Other”

Who is online

Users browsing this forum: No registered users and 3 guests