Clone your disk using Jeltka

Please note, if you don’t understand what’s going on here, it’s very easy to screw the source partition up, and lose your data! Be warned!

Obviously, boot into Jeltka first. Then, check the filesystem of the partition in question, in preparation for resizing the filesystem to it’s minimum size (please note, you may need to adjust device names accordingly):

e2fsck /dev/sda1

Then resize the filesystem to it’s smallest possible size using the -M flag of resize2fs:

resize2fs -M /dev/sda1

Mount the filesystem, check it’s size using df, and unmount it again (so fdisk can write the partition table successfully, later on):

mount /dev/sda1 /mnt
df -h
umount /dev/sda1

Now, we also need to reduce the size of the partition itself. This is so dd doesn’t copy more data than necessary (which could save you a lot of time). In the interests of safety, it’s always a good idea to make the partition at least 1GB bigger than the filesystem (fdisk and resize2fs, etc. calculate sizes in slightly different ways, the extra partition size ensures the partition is big enough to contain the filesystem). We also need to be careful because the version of fdisk included with Busybox uses the old 63 sector, default starting point for partitions, and your disk is probably partitioned with a 2048 sector starting point (this became the default in standard fdisk with the advent of GPT partitioning some years ago).

fdisk /dev/sda

To accommodate previous, we now change display units to sectors by pressing “u”. Press “p” to print the existing layout, to confirm the partition does indeed start at sector 2048. Then delete the existing partition – “d” followed by “1” (assuming the partition we’re concerned with is the first partition on the disk). Now we create a new partition with the same starting point – “n”, “p”, “1”, “2048”, “+14G” (where 14G is the size in gigabytes, you want the partition to be). Now type “p” again, and double check everything is as it should be, before hitting “w” to save the partition table and exit. Don’t worry too much if you’ve messed up here, as long as you can create a partition with the same starting point as the original, and enough size to accommodate the filesystem contained on it, you won’t lose any data. However, if you do something rash like create a new filesystem on an incorrectly sized/started partition, you will in fact be overwriting your nice data. In short, don’t do it!

Now we’re ready to do the actual copying using dd. I’m assuming here that you have a USB key/drive attached, and you’re going to output the partition image to a file on the USB key, with a view to dd’ing it onto a replacement HD/SSD, which you’ll physically put in your Chromebook subsequently. I’m assuming the USB key already has a compatible filesystem on it (ext4, FAT or NTFS, IIRC). Again, be careful to use the correct device name. First we’ll mount the USB stick somewhere suitable:

mount /dev/sdb1 /mnt

We should also backup the existing partition table and boot sector thusly:

dd bs=512 count=1 if=/dev/sda of=/mnt/bootsector.img

Then we’ll dd the partition to a file on the USB stick:

dd bs=1M if=/dev/sda1 of=/mnt/partition.img

If we had another console available, we could check on dd’s progress like so – find dd’s process number, and send a signal to it, to display progress every 60 seconds:

ps -e |grep dd
watch -d -n 60 kill -SIGUSR1 1234

Where “1234” is dd’s PID (will undoubtedly be something else entirely).

Assuming you didn’t run out of space on your USB whatever, dd will have completely successfully (eventually), and you can now set about swapping your HD/SSD out for a nice, shiny, big one. :)

Back already? Okay, now we’re ready to copy the partition table/bootsector over, and create a new partition to take advantage of all that space! Make sure you’ve mounted the USB whatever again.

dd if=/mnt/bootsector.img of=/dev/sda

Then use fdisk to create a new partition, as we did previously, only this time don’t specify a size (it will default to the end of disk).

Then, copy the partition image to the new partition we just created, using dd:

dd bs=1M if=/mnt/partition.img of=/dev/sda1

When this has finished, check you can mount the filesystem! Assuming you can, we can now resize the filesystem to take advantage of all that juicy space you’ve just purchased:

e2fsck /dev/sda1
resize2fs /dev/sda2

Success?