First, turn off raspberry, unplug the power plug, and then remove the SD card.
The next step will be on Linux PC (or Linux live system).
Please do not use raspberry PI in subsequent steps! I tried several times, but failed all the time.
Start your Linux machine, start the console window, and then use
sudo gparted
Start GParted, then insert it into the SD card reader (and, of course, the SD card) and refresh the GParted device list (Ctrl R).
Select your SD card from the drop-down menu in the upper right corner. Note the device path for later use (for example, / dev / SDD). In the next steps, we will reduce the master data partition. This will save us a lot of time for the next step. therefore
Right click the ext4 partition available in the list
Select resize / move
In the resize / move window, drag and drop the zone to the desired size, or just manually enter the new size. In my case, it's 4096mib
Hit resize / move and apply all actions buttons
GParted will now resize the partition.
For other steps, note the specific data of the partition:
Right click the partition SDD1 in the list and click info
Note the size, first sector, last sector and total sector
Repeat the steps for partition sdd2
For example:
/dev/sdd1
/dev/sdd2
Now you have resized the partition and some important values for subsequent steps.
Step 2: save data
In this step, we will create a complete backup SD card.
Wait a minute, you said we wanted to create a smaller card!?
That's right, but before we can shrink the backup, we need a backup that can shrink.
So open a new console window and type:
su root
(if not already created, enter the root password, enter "sudo passwd" and set a root password)
(Su it's OK without 'root')
If you want to create a backup on an external device, you must first install it. If you use a Linux live system and want to backup on an internal (Windows) hard disk, you must also install it.
First create an installation point:
mkdir -p /mnt/backup
Use GParted to get the name of the backup target device:
Refresh with Ctrl R
Determine the hard drive menu from the device drop-down list. You used a known size in step 1. Select it and note the device path of the desired partition (for example, / dev / sda1).
To install your backup hard drive:
mount /dev/sda1 /mnt/backup
Your backup space is now accessible in / MNT / backup.
Let's start and backup
dd if=/dev/sdd of=/mnt/backup/rpi.img bs=1M
This command copies the entire SD card to our backup hard drive and creates an image file as large as the SD card.
Please be patient, this process may take a long time! Have coffee or some beer, maybe two
Step 3: create a custom picture
Finally, we can start creating custom images.
To do this, we create an image disk with the same properties as the backup image but different sizes.
Remember strange numbers, such as the Department you should pay attention to? Now we need them!
Just make sure you use the fdisk tool to get the specific data of the backup image you created:
fdisk -l -u=cylinders /mnt/backup/rpi.img
The output shall be as follows:
Units = sectors of 1 * 512 bytes = 512 bytes
And so on
For the next step, we need (they should be the same for each SD card, but to ensure discovery!):
heads = 255
sectors/track = 63
Unit = 512 bytes
Now we must do some mathematical operations. Don't panic. It's easy.
Heads * sectors / track * units = bytes per column
255 * 63 * 512 = 8225280 = "note that this value is important!
The structure of the image is as follows:
4 MB unallocated space for master boot record (MBR)
63mb FAT32 boot partition
4096mb (for data partitioning)
Add up this space and you'll get 4163mb
With this information, we can calculate the required number of cylinders.
It's just (image size in bytes) / (bytes per cylinder) =) cylinder
The image size is 4163 MB. To convert it to bytes, we multiply the term by 1024 twice.
4163 * 1024 * 1024 = 4365221888 bytes
(image size in bytes) / (bytes per cylinder) = cylinder
4365221888 / 8225280 = 530, 71 = 531 cylinder
Now create a blank image by:
dd if=/dev/zero of=/mnt/backup/5gb.img bs=8225280 count=531
The result is a new blank image w size of 4163mb
Step 4: create a zone
There are no partitions or anything else in the created image. So let's create some partitions yes!
fdisk -u -C531 -S63 -H255 /mnt/backup/5gb.img
Now the tool fdisk creates a new boot table and asks you to take further steps. Now, you need to get the sector data from GParted.
e extended
Using default value 1
Selected partition 1
Youve just created the first boot partition. Now the data partition
e extended
Using default value 2
Just ignore the default sector size and use the sector size obtained from GParted!
Now enter "W" and press enter to finish!
The partition table has been altered
WARNING If you have created or modified any DOS 6.x
partitions please see the fdisk manual page for additional information.
Syncing disks
Step 5: copy data
Now let's talk about where you can transfer data to a blank image.
Just from the boot partition to the new boot partition, use the following command:
dd if=/mnt/backup/rpi.img of=/mnt/backup/5gb.img bs=512 count=129024 skip=8192 seek=8192
explain:
We skip the first 4MB (MBR!) on the image, start with 8192 blocks from the first partition, copy the next 129024 sector, and stop at the last sector (137215) of the partition.
We perform the same operation again, but for the second partition:
dd if=/mnt/backup/rpi.img of=/mnt/backup/5gb.img bs=512 count=8388608 skip=137216 seek=137216
Count = total sectors
Skip and find first sector
Done! Now you will get a new 4.4 gib image that you can use for all SD cards.
Copy it to the SD card, just like all other PI and boot images
In this description, I used a 64gib SD card. I have tested new custom images on 16 gib, 8 gib and 32 gib cards. Everything is fine. On the first boot, run "sudo raspi config" and resize the file system.
Feel free to use this instruction to make changes or sell. I don't care: D
Inspired by this how to: German directive
Contact person: Stanley Zhang
Tel : +86 13751812734
Email : Stanley@roadsunshine.com
Address : Room 712, A2 Jiefeng E-Commerce BlvdNo.50 Juyuan St, Shicha Rd, Baiyun Dist,
Guangzhou, China