L
L
lavAzza22016-07-15 15:52:04
linux
lavAzza2, 2016-07-15 15:52:04

How to make a copy of the Raspbian OS to a smaller SD card?

The situation is as follows:
On the Raspberry pi 3, the Raspbian OS is installed on a 32GB SD card. Less than 6 GB used.
To improve the reliability of the system, I decided to make a raid-1 of 2 SD cards of 16 GB each - one in the slot, the other through a USB card reader. (By the way, the question is - will it work?)
Accordingly, the task of transferring the OS from a 32 GB card to a 16 GB card arose. How to do it?
I tried to make an image of Win 32 Disk Imager, it, of course, made a full image of the card, i.e. 32 GB.
If it's not difficult, please give a detailed answer, I'm new to Linux.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sergey, 2016-07-15
@dev_random

I won't tell you about RAID, but you can cut the size of the image, for example like this ( Linux PC is needed )
1. lsblk . find the 32 Gb card (/dev/sdX) in the sd output
2. sudo umount /dev/sdX{1,2} (instead of "sdx" -- the device name from the previous command)
3. mkdir mnt
4. sudo mount /dev /sdX2 mnt
5. sudo mount /dev/sdX1 mnt/boot
6. (cd mnt && tar czpf ../rootfs.tar.gz *)
7. sudo umount /dev/sdX{1,2}
now you can remove the sd card
8. Install the kpartx
utility 9. Create a 16Gb file. dd if=/dev/zero of=fake_blockdevice.img bs=1M count=16000
10. make a new block device out of it: sudo kpartx -v -a fake_blockdevice.img
11. lsblk . find the device name (/dev/sdY}
12. markup the partitions and format them. for example, as here, points 1-4 (in 3 and 4 only mkfs.* commands) https://archlinuxarm.org/platforms/armv8/ broadcom/...
13. sudo mount /dev/sdY2 mnt/
14. mkdir mnt/boot
15. sudo mount /dev/sdY1 mnt/boot
16. sudo tar xzpf rootfs.tar.gz -C mnt will unpack the archive created in step 6
17. sudo umount /dev/sdY{1,2}
17. sync
profit. the output is a 16Gb file that can be written to a memory card using dd or Win 32 Disk Imager

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question