Catapultatore Automatico Nucleare per il Nostro Opportuno Linux Ordinario
A bash tool to automatically shrink, flash and expand a disk image on an external device.
Before launching the script make sure to have on your system
parted growpart awk tune2fs resize2fs fallocate
On most Debian based systems all needed dependencies can be installed with
sudo apt install cloud-guest-utils parted
Available options (also listed when the script is launched with -h
or --help
):
--no-bake
: passed image will not be shrinked nor modified in any way. Otherwise it will be resized to be as small as possible.
--post-install <executable script file>
: a script to be executed on the new disk, using it as root partition. Warning: Some systemd tools such as hostnamectl, localectl and timedatectl can not be used, as they require an active dbus connection and this option uses internally chroot
(see it on the ArchWiki).
--hostname <PC hostname>
: the new hostname on the passed disk
--shutdown
: shutdown the machine immediately after finishing the script execution
--swap <swap size>
: add a swap to the primary OS on the new disk. Needs a partition size that can be accepted by the fallocate
command.
Possible suffixes: K
, M
, G
, T
, P
, E
, Z
, Y
.
Only two suffixes of practical use at this point in time: M
for Megabytes and G
for Gigabytes.
From its man page:
The length and offset arguments may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB, and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB, and YB.
A typical usage example
sudo ./cannolo.sh xubuntu.img --hostname PC-42 --swap 1G /dev/sdb
This is the procedure I followed
- I created a disk on VirtualBox with default size (10 GB), default type (
vdi
) but with fixed size (in this case the default option is dynamically allocated, but choosing that option will result in Xubuntu formatting the disk with LVM, probably because it is easier to resize it in future). - Install Xubuntu according to instructions:
i. Start Xubuntu > F4 > "OEM installation" > Install
ii. Name asked in the first screen:WEEE Open
iii. Automatic partitioning
iv. Password: read the archives - Execute pesca on it
- Comment or delete the line starting with
/swapfile
in/etc/fstab
, since by default Xubuntu creates aswapfile
.
ONLY FOR 32 BIT: Regenerate grub config files with(and if neeeded update the packages, but in this case it is already done by the pesca).sudo grub-mkconfig -o /boot/grub/grub.cfg
- Remove the file
/swapfile
(a reboot may be needed). - Remove the system logs (just run
sudo journalctl --rotate && sudo journalctl --vacuum-time=1s
) and all the files download during the process (basically thepesca
)
Then, to create the .img
just run
VBoxManage clonemedium --format RAW <file.vdi> <file.img>
The file env.sh
contains some useful aliases:
img2vdi <file.img> <file.vdi>
creates avdi
file from the passed.img
vdi2img <file.vdi> <file.img>
does the exact opposite process
These aliases can be enabled simply by running
source env.sh
This script has been tested on simple BIOS partition schemes, containing only one primary partition with the operative system (both for x86 and x86_64 architectures).