Coder Social home page Coder Social logo

mini_image's Introduction

A simple script that uses rsync to make a minimal image of the current os.

Usage: ./mini_image.sh <device - optional> ./mini_image.sh backup.img sda

The image can be made on the current device if %used is below ~48% Freesapce is check to see if there is enough room

Using the system during image creation should be keep between none and minimal

Although it is writen for pi folks, other then dependency retrival, it should work on any Linux system

mini_image's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mini_image's Issues

Unable to expand root partition automatically using raspi-config

After creating a mini image and writing it to another sd card, I was unable to expand the root partition using the raspi-config tool. I was able to do this by manually running the partition tools, but it would be preferable to do this automatically.

Other things that have happened that may have caused a problem: I upgraded to Raspbian Jessie.

Thank you for this tool. It was simple to use and worked well.

no way to skip mounted smb drives

I'm making backup of my SD card to local drive. It actually tries to bake a backup of the mounted drive as well.

Example script:

#!/bin/bash

server='//10.0.0.10/share'
mount='/home/przemek/Desktop/mnt'
host=$HOSTNAME
path="$mount/$host"
host_server="$server/$host"
host_path="$mount/$host"
host_backup="$mount/$host/backup"

# sudo mount //10.0.0.10/share /home/przemek/Desktop/mnt/ -o $( cat passwd )
# sudo mount //10.0.0.10/share /home/przemek/Desktop/mnt/ -o $( sudo cat passwd )

script=$(realpath $0)
root=$(dirname ${script})

date=$(date +%Y-%m-%d_%H-%M-%S)
os=$(lsb_release -is | awk '{print tolower($0)}')
release=$(lsb_release -rs | awk '{print tolower($0)}')
filename="$host-$os-$release-$date.img"

mount_init_dir() { 
	if [ ! -d "$mount" ]; then
		mkdir $mount
	fi
				
	if [ -d "$mount" ]; then
		return 0
	else
		return 1
	fi
}

mount_init_mount() {
	if ! grep -qs "$mount" /proc/mounts; then
		mount $server $mount -o $( sudo cat $root/passwd )
	fi

	if grep -qs "$mount" /proc/mounts; then
		return 0
	else
		return 1
	fi
}

mount_init_host() {
	if [ ! -d "$path" ]; then
		mkdir "$path"
	fi
		
	if [ -d "$path" ]; then
		return 0
	else
		return 1
	fi
}

mount_init_exit() {
	if grep -qs "$mount" /proc/mounts; then
		umount $mount
	fi
	
	if ! grep -qs "$mount" /proc/mounts; then
		return 0
	else
		return 1
	fi
}

mount_finish() {
#	echo 'Print Q to exit...'
#	echo ''
#	
#	while true; do
#		read -t 1 -n 1 key
#
#		if [[ $key = q ]]; then
#			break
#		fi
#	done
	
	while true; do
		echo 'checking if mount removed'
		
		if mount_init_exit; then
			break
		else
			sleep 1
		fi
	done
	
	echo ''
	echo 'Done!'
	echo ''
}

maunt_backup() {
	$root/mini_image.sh $host_backup/$filename
	
	echo 'Backup done...'
}

mount_init() {
	while true; do
		echo "checking if mount dir exist..."
		
		if mount_init_dir; then
			break
		else
			sleep 1
		fi
	done

	while true; do
		echo "checking if mount created"
		
		if mount_init_mount; then
			break
		else
			sleep 1
		fi
	done

	while true; do
		echo "checking if host file created"
		
		if mount_init_host; then
			echo "Mount point created: $mount"
			break
		else
			sleep 1
		fi
	done
}

mount_init
maunt_backup
mount_init_exit

exit 0

Restore image is not working

Hi
i try your solution on the mini image , i have a sd card 32Go the and the size used is 9Go

boot_block=$(df --block-size=1M | grep '/dev/mmcblk0p1' | awk '{print $2}')
root_block=$(df --block-size=1M | grep '/dev/root' | awk '{print $3}')
file_block=$(($boot_block+$root_block+420))
echo Nombre total de blocks plus 420 : $file_block >> $file_log_end
file_size=$(($file_block*1024))
echo Taille totale image : $file_size >> $file_log_end
dd if=/dev/mmcblk0 bs=1M count=$file_block conv=noerror iflag=fullblock > $backup_all/backup_pi_sda.img

blocks mmcblk0p1 : 255
blocks root : 8778
Nombre total de blocks plus 420 : 9453
Taille totale image : 9679872

I save 9 Go and restore the image on the SD card (32Go)
But when i boot it's impossible to validate the user and password
Do you have a idea ?
Regards

Restore image is not working

Hi, I have a 128GB sd card. Raspberry pi 4b. Running Buster-Lite. Headless. When I use

sudo ./mini_image.sh backup.img mmcblk0
Your documentation doesn't specify, I assume that "device" argument is the device I want to read

I get an infinite loop, tons of rsync log msgs, ever growing, including it's own backup.img file recursively (/root/backup.img, then /root/sdcard/backup.img, etc...)
I had to CTRL-C out of it, which left some things open (might be a great idea to add a CTRL-C signal handler to the script).

If I use sudo ./mini_image.sh backup.img it generates an image

If I try to restore with Belena Etcher, or using sudo dd if=backup.img of=/dev/disk3
I get an unrecognized disk (in MacOSX),
And it doesn't boot on the rpi - my HDMI doesn't even turn on. Constant green light.

however, when I diskutil list, I see:

/dev/disk3 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *125.0 GB   disk3
   1:                 DOS_FAT_16                         265.3 MB   disk3s1
   2:                      Linux                         2.1 GB     disk3s2

but it simply doesn't mount in MacOSX like normal rasbian .img files... ( I would expect to see the FAT /boot directory mounted under /Volumes, to edit config.txt and cmdline.txt and such... but MacOSX says unrecognized disk would you like to format)

On my rpi, before backing up with mini_image.sh, I get:

$ sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="F661-303B" TYPE="vfat" PARTUUID="88bd9a7d-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="8d008fde-f12a-47f7-8519-197ea707d3d4" TYPE="ext4" PARTUUID="88bd9a7d-02"
/dev/sda1: LABEL="Samsung USB" UUID="D896-5CB1" TYPE="vfat" PARTUUID="c3072e18-01"
/dev/mmcblk0: PTUUID="88bd9a7d" PTTYPE="dos" 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.