As the title of this thread may seem ambiguous, here are some explanations.
Nowadays, there is no doubt that the best way to distribute Puppy is no longer an ISO file to burn to CD/DVD, but an image file to dump directly to USB stick or SD card.
I made this choice for ToOpPy in June 2017. To this end, did18 developed Img2Key and I made a dumping wizard called 2Pd2f using gdiskdump, available to ToOpPy users.
So far I have created such images from a 4GB hardware USB stick while the system weighs only about 300MB. The target drive must therefore have at least the same capacity as the source. Dumping takes about 20 minutes. With a 300 MB image, within 1 to 3 minutes.
So I initiated this thread to learn how to:
- - (1) create ex nihilo a smaller capacity virtual disk with a primary "bootable" partition containing the system files and then save its image.
- (2) reduce an existing image file. This image can be as well an image created ex nihilo as the image of an existing USB stick, the interest being finally to reduce its size as much as possible.
- The second one produces an operational image file and the USB stick burnt from it boots normally.
As soon as the commands are known and do the job well, it's quite simple to make a wizard, or a graphical user interface like the Disk Image Creator of mistfire (or better yet, to complete it for that purpose).
It was just an idea but while searching the net I didn't find anything like that, although it could be very useful.
**********************************
(1) Creating a disk image ex nihilo
**********************************
Create a working directory:
Code: Select all
# mkdir $HOME/virtual_disk
Code: Select all
# dd if=/dev/zero of=$HOME/virtual_disk/VD.img bs=1M count=512
Code: Select all
512+0 records in 512+0 records out 536870912 bytes (537 MB) copied, 1,25517 s, 428 MB/s
Enable loopback if it wasn't already enabled:
Code: Select all
# modprobe loop
Code: Select all
# losetup -f
Code: Select all
/dev/loop3
Code: Select all
# losetup /dev/loop3 $HOME/virtual_disk/VD.img
Code: Select all
# gparted /dev/loop3
- 1 - Create a table partition
Code: Select all
====================== libparted : 3.1 ======================
2 - Create a primary partition
3 - Format it to whatever you want
4 - Give it a label (optional)
5 - Make it "bootable"
6 - Possibly check it
7 - Quit gparted
Code: Select all
# losetup -d /dev/loop3
Code: Select all
# parted $HOME/virtual_disk/VD.img
Code: Select all
GNU Parted 3.1 Utilisation de $HOME/virtual_disk/VD.img Bienvenue sur GNU Parted ! Tapez 'help' pour voir la liste des commandes. (parted) unit Unité ? [compact]? B (parted) print Modèle: (file) Disque $HOME/virtual_disk/VD.img : 536870912B Taille des secteurs (logiques/physiques): 512B/512B Table de partitions : msdos Disk Flags: Numéro Début Fin Taille Type Système de fichiers Fanions 1 1048576B 536870911B 535822336B primary ntfs démarrage (parted) q (type q to exit from parted).
Code: Select all
# mkdir /mnt/VD
Code: Select all
# mount -o loop,offset=1048576 $HOME/virtual_disk/VD.img /mnt/VD
(2) Shrinking (existing) disk image
**********************************
Create a device of the image:
Code: Select all
$ losetup /dev/loop3 myimage.img
Code: Select all
$ partprobe /dev/loop3
Load the device using GParted:
Code: Select all
$ gparted /dev/loop3
- 1 - Select the partition and click Resize/Move.
2 - Drag the right bar to the left as much as possible
3 - Press Apply
3 - Possibly check it
4 - Close GParted).
The part of the disk unallocated that will not be used by the partition can be shaved. GParted is a tool for disks, so it doesn't shrink images, only partitions.
Unload the loopback-device being not needed anymore:
Code: Select all
$ losetup -d /dev/loop3
Code: Select all
$ fdisk -l myimage.img
Code: Select all
Disk myimage.img: 6144 MB, 6144000000 bytes, 12000000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ea37d Device Boot Start End Blocks Id System myimage.img1 2048 9181183 4589568 b W95 FAT32
So, next the image-file is shrunk to a size that can just contain the partition. For this, use the dd command. The size of the file is needed. The last block was 9181183 and block-numbers start at 0. That means the "count" value is equal to 9181183+1. This is important, else the partition will not fit the image:
Code: Select all
$ dd if=myimage.img of=myimage_shrunk.img bs=512 count=9181184
**********************************
Adapted from shrinking-images-on-linux by FrozenCow
Cordialement.