TS-4100 eMMC Backup/restore ums: Difference between revisions

From embeddedTS Manuals
(Remove incorrect 7553v2 reference)
(Clean up section to match 7553v2 and not use last sector of disk)
Line 1: Line 1:
U-Boot on the TS-4100 supports the "ums" command to allow the eMMC device (or SD card, or USB device for that matter) to be accessible directly on a host PC via USB mass storage. This method is generally slower than direct access from Linux on the TS-4100 itself, but it allows for direct updating of the flash media.
U-Boot on the TS-4100 supports the "ums" command to allow the eMMC device (or SD card, or USB device) to be accessible directly on a host PC via USB mass storage. This method is generally slower than direct access from Linux when [[#Booted_from_SD|booted from SD]] on TS-4100itself, but it allows for direct updating of the flash media from a host device.


{{Note|When using this method, do not write the last sector of the disk. This will cause the U-Boot UMS command to return as it thinks the whole disk has now been written and the disk imaging process has completed. The instructions below take this in to account by setting up the partition table to never include the last sector of the disk and the tools used have been selected to ensure that the last sector is not written at any time during the partition table setup.}}
{{Note|It is recommended to use a host PC with a native linux install.  It has been observed that some VMs fail to correctly pass-through the USB device created in U-Boot for UMS.}}
{{Note|It is recommended to use a host PC with a native linux install.  It has been observed that some VMs fail to correctly pass-through the USB device created in U-Boot for UMS.}}


Line 10: Line 11:
</source>
</source>


The USB mass storage device provided by the TS-4100 will begin to enumerate.  The following commands can then be used to set up the eMMC and unpack the latest image on to it. Note that the instructions refer to /dev/sdX, please verify the correct device node that is created on the host and adjust the instructions as necessary.
Note that the instructions use a bash variable to define the device node; this allows the commands to be copy/pasted as-is to a terminal or in a script. Ensure that the correct device node is passed! The node "/dev/sdX" is used in the example below, update that line to use the correct whole-device node.
<source lang=bash>
<source lang=bash>
# Verify nothing else has the disk mounted with 'mount'
# Update this variable to match the specific device node as it appears on your PC!
# If partitions are mounted automatically, they can be unmounted with
export UMS_DEV="/dev/sdX"
umount /dev/sdX1


mkfs.ext3 /dev/sdX1
# Verify nothing else has the partition mounted
mkdir /mnt/emmc
sudo umount "${UMS_DEV}"1
mount /dev/sdX1 /mnt/emmc
 
# Remove, and re-set the partition table, ensuring there is a single partition that ends just before the last sector of disk
sudo dd if=/dev/zero bs=512 count=1 of="${UMS_DEV}"
sudo echo 'label: dos' | sfdisk "${UMS_DEV}"
sudo parted -s -a optimal "${UMS_DEV}" mkpart primary ext3 0% 99%
sudo mkfs.ext3 -F "${UMS_DEV}"1
 
# Mount, unpack filesystem tarball, and flush all cached data
sudo mkdir /mnt/emmc
sudo mount "${UMS_DEV}"1 /mnt/emmc
wget http://ftp.embeddedarm.com/ftp/ts-socket-macrocontrollers/ts-4100-linux/distributions/debian/ts4100-armhf-stretch-latest.tar.xz
wget http://ftp.embeddedarm.com/ftp/ts-socket-macrocontrollers/ts-4100-linux/distributions/debian/ts4100-armhf-stretch-latest.tar.xz
tar -xJf debian/ts4100-armhf-stretch-latest.tar.xz -C /mnt/emmc
sudo tar -xJf debian/ts4100-armhf-stretch-latest.tar.xz -C /mnt/emmc
umount /mnt/emmc
sudo umount /mnt/emmc
sync
sync
</source>
</source>
{{:U-Boot ext4 warning}}
{{:U-Boot ext4 warning}}


After the image is written, the files can all be verified on disk against the original files created in the tarball. Reinsert the disk to verify any block cache is gone, then run the following:
Once written, the files on disk can be verified to ensure they are the same as the source files in the archive. To do so, run the following commands (Note that this expects to have the bash variable still set up from above):
<source lang=bash>
<source lang=bash>
mount /dev/sdX1 /mnt/emmc
sudo mount "${UMS_DEV}"1 /mnt/emmc
cd /mnt/emmc/
cd /mnt/emmc/
sudo md5sum --quiet -c md5sums.txt
sudo md5sum --quiet -c md5sums.txt
umount /mnt/emmc
cd -
sudo umount /mnt/emmc
sync
sync
</source>
</source>


The 'md5sum' command will report any differences between files and their checksums. Any differences are an indication of failure to write data or a damaged disk.
The md5sum command will report what differences there are, if any, and return if it passed or failed.
 
 
UMS can also be used to create an image from an existing device. However, we recommend using the [[#Createing_A_Production_Image|image prep script]] to complete this process for its ease of use, removal of temporary or unique files, and generation of MD5 hashes for each file.


Manual process:
At this point, the device is unmounted and is sync'ed.  The TS-4100 can safely be powered offBe sure to disconnect the USB cable as well to ensure the system is fully powered off.
<source lang=bash>
dmesg | tail -n 30
# Look for the last /dev/sd* device connectedThis should also match the eMMC
# size of around 3.78GiB.
sudo mkdir /mnt/emmc/
sudo mount /dev/sdX1 /mnt/emmc/
cd /mnt/emmc/
tar -cjf /path/to/ts4100-backup-image.tar.bz2
cd ../
umount /mnt/emmc/
sync
</source>

Revision as of 18:15, 23 January 2020

U-Boot on the TS-4100 supports the "ums" command to allow the eMMC device (or SD card, or USB device) to be accessible directly on a host PC via USB mass storage. This method is generally slower than direct access from Linux when booted from SD on TS-4100itself, but it allows for direct updating of the flash media from a host device.

Note: When using this method, do not write the last sector of the disk. This will cause the U-Boot UMS command to return as it thinks the whole disk has now been written and the disk imaging process has completed. The instructions below take this in to account by setting up the partition table to never include the last sector of the disk and the tools used have been selected to ensure that the last sector is not written at any time during the partition table setup.
Note: It is recommended to use a host PC with a native linux install. It has been observed that some VMs fail to correctly pass-through the USB device created in U-Boot for UMS.


In order to use this method, enter the U-Boot shell while connected to the TS-4100 via the USB serial interface. Insert the proper USB cable between the host PC and the USB OTG port, and enter the U-Boot command:

ums 0 mmc 1

Note that the instructions use a bash variable to define the device node; this allows the commands to be copy/pasted as-is to a terminal or in a script. Ensure that the correct device node is passed! The node "/dev/sdX" is used in the example below, update that line to use the correct whole-device node.

# Update this variable to match the specific device node as it appears on your PC!
export UMS_DEV="/dev/sdX"

# Verify nothing else has the partition mounted
sudo umount "${UMS_DEV}"1

# Remove, and re-set the partition table, ensuring there is a single partition that ends just before the last sector of disk
sudo dd if=/dev/zero bs=512 count=1 of="${UMS_DEV}"
sudo echo 'label: dos' | sfdisk "${UMS_DEV}"
sudo parted -s -a optimal "${UMS_DEV}" mkpart primary ext3 0% 99%
sudo mkfs.ext3 -F "${UMS_DEV}"1

# Mount, unpack filesystem tarball, and flush all cached data
sudo mkdir /mnt/emmc
sudo mount "${UMS_DEV}"1 /mnt/emmc
wget http://ftp.embeddedarm.com/ftp/ts-socket-macrocontrollers/ts-4100-linux/distributions/debian/ts4100-armhf-stretch-latest.tar.xz
sudo tar -xJf debian/ts4100-armhf-stretch-latest.tar.xz -C /mnt/emmc
sudo umount /mnt/emmc
sync
Note: The ext4 filesystem can be used instead of ext3, but it may require additional options. U-Boot does not support the 64bit addressing added as the default behavior in recent revisions of mkfs.ext4. If using e2fsprogs 1.43 or newer, the options "-O ^64bit,^metadata_csum" must be used with ext4 for proper compatibility. Older versions of e2fsprogs do not need these options passed nor are they needed for ext3.

Once written, the files on disk can be verified to ensure they are the same as the source files in the archive. To do so, run the following commands (Note that this expects to have the bash variable still set up from above):

sudo mount "${UMS_DEV}"1 /mnt/emmc
cd /mnt/emmc/
sudo md5sum --quiet -c md5sums.txt
cd -
sudo umount /mnt/emmc
sync

The md5sum command will report what differences there are, if any, and return if it passed or failed.

At this point, the device is unmounted and is sync'ed. The TS-4100 can safely be powered off. Be sure to disconnect the USB cable as well to ensure the system is fully powered off.