I have a file with an xz extension, ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz. How do you get the .img out of it?

My goal is to flash the file on an SD card. I want to use www.etcher.io I finally got it to work, but etcher will only handle .iso and .img files.

  • Related, if not a duplicate: askubuntu.com/q/92328/249734 , but any number of "decompress and pipe through dd" references will cover well enough. – mckenzm Dec 4 '19 at 17:52

As far I can see on my Ubuntu 16.04 LTS system - the GNOME Disks utility allow to restore disk image in GUI way:

  1. Select target drive.
  2. Click on hamburger button, and then select Restore Disk Image

    GNOME Disks

  3. Then it will ask the path of image file:

    Select Disk Image to restore

    here you can select any of *.img, *.img.xz (sic!) and *.iso formats.

  4. Double check that destination is correct and then hit Start Restoring... button on opened window.

| improve this answer | |
  • 7
    Why the sic? Is this because .img.xz is really a compressed disk image and not a "disk image"? In reality it looks like you don't know that .xz is a thing and you are pointing out that .gz is written typographically wrong... – Giacomo Alzetta Dec 3 '19 at 13:13

xz is a compression format like zip or gz. To be able to decompress it from the command line you need to install xz-utils:

$ sudo apt-get install xz-utils

and then use this command to decompress your file:

$ unxz ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

If you are under windows you can use 7zip

| improve this answer | |
  • 1
    Are there currently supported Ubuntu releases on which xz-utils is not installed by default? – Eliah Kagan Dec 2 '19 at 15:54
  • 6
    you can use 7zip in linux as well. – rtaft Dec 2 '19 at 15:54
  • 1
    If you want to keep the compressed file use the option -k – rubo77 Dec 3 '19 at 6:54
  • @EliahKagan it seems to me that xz-utils is not pre-installed on Ubuntu server. – Benoît Dec 18 '19 at 8:02

Decompressing .xz files in general

ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz is the result of compressing a single file, ubuntu-19.10-preinstalled-server-arm64+raspi3.img, with xz. You can uncompress it with:

unxz ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

That will extract ubuntu-19.10-preinstalled-server-arm64+raspi3.img and, assuming it succeeds, delete ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz. If you want to keep that original .xz file, you can pass the -k/--keep option:

unxz -k ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

Note that this is different from what you would usually do for a .tar.xz file, since tar supports decompressing and extraction through a single command. In the case of a .xz file (unless the file is very misleadingly named), only decompression is needed.

Flashing the preinstalled Ubuntu Server image in particular

The particular file you've downloaded is a preinstalled image for Ubuntu Server 19.10. Assuming the file was correctly and successfully downloaded (see below), you can use the official instructions to flash this image to a storage device. The best way to do this differs depending on what operating system you're using to do it. But assuming it's Ubuntu, here's a summary:

  • Find the name of the device that you are writing it to. One way to do this is in Disks (your file browser). Make sure this is not the name of a device that contains any data you wish to keep!

  • Run this command, replacing device with the device name you found:

    xzcat ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz | sudo dd of=device bs=32M

    There, xzcat is doing the work of unxz. If you have a corrupted file, xzcat will fail, just as unxz would.

    If you ran unxz and got a .img file, then don't use that command above with xzcat. In that case, use this command instead:

    sudo dd if=ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz of=device bs=32M

It is not typically possible to write a flash drive with dd in a WSL system. So if you're running Ubuntu in Windows 10 with WSL, those instructions don't apply. But in that case you can just use a Windows method (see the official instructions).

Dealing with possibly incomplete or corrupted files

If decompression fails with an error message about how the file format is not recognized, then especially if running file on it is unable to identify the format as XZ compressed data (though sometimes otherwise), you likely have a corrupted or incomplete download. You can use ls -l to find the length of your file in bytes and compare that length to the expected length--for that particular file, the length should be 661217868. That addresses most cases of incomplete downloads and a few cases of corrupted downloads, but it is far from perfect.

Many files available for downloading, including ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz all the Ubuntu images, have checksums that can be used to more reliably gauge if the file was completely and correctly downloaded. For security purposes, it's a good idea to check the GPG signautre on the file providing the checksums (and to avoid MD5 checksums, which are weak against deliberate attacks). But for checking for inadvertent corruption, it's enough to look up the checksum and test your file.

The kind of checksum provided and recommended for checking Ubuntu images these days is a SHA256SUM. This file contains the SHA256SUMs for the 19.10 server images, including ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz. One of its lines is:

52ca28f21685eef965d476a716a7bc01237456d6a8770a56630299036eade0bf *ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

Running the sha256sum utility on your file should produce a checksum that matches exactly, like this:

$ sha256sum ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz
52ca28f21685eef965d476a716a7bc01237456d6a8770a56630299036eade0bf  ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

If it does not, then your download was corrupted or incomplete and that's probably the explanation for your difficulty decompressing or otherwise using the file.

| improve this answer | |
  • It says the file format is not recognized when I do this. – BJsgoodlife Dec 2 '19 at 15:57
  • @BJsgoodlife What's the exact command you're running and the exact error message you get? Also, what's the output of ls -l ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz and file ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz? (One way to provide this information could be to edit your question to include it.) – Eliah Kagan Dec 2 '19 at 16:09
  • @Eliiah Kagan unxz ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz unxz: ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz: File format not recognized. I will edit my question too. – BJsgoodlife Dec 2 '19 at 16:17
  • @BJsgoodlife Thanks. I've expanded my answer to cover what to do when you get this sort of error. Basically, you should check the SHA256SUM to ensure you have a complete and correct download. (I still recommend that you edit your question as planned.) I've also expanded my answer to link to the recommended method of flashing a preinstalled Ubuntu Server image to a storage device, since that's your actual goal here, and I've summarized one of the recommended methods for doing so. Note that this will still only work (and have the desired effect) if you downloaded a complete and uncorrupted file. – Eliah Kagan Dec 2 '19 at 16:40

You can use mkusb-dus to extract and clone directly from an img.xz file (compressed file with xz).

  • Install mkusb

    If you run standard Ubuntu live, you need an extra instruction to get the repository Universe. (Kubuntu, Lubuntu ... Xubuntu have the repository Universe activated automatically).

    sudo add-apt-repository universe  # only for standard Ubuntu
    sudo add-apt-repository ppa:mkusb/ppa  # and press Enter
    sudo apt-get update
    sudo apt-get install mkusb mkusb-nox usb-pack-efi
  • Run dus in the directory where you have the file, in general

    dus file.img.xz

    in your case

    dus ubuntu-19.10-preinstalled-server-arm64+raspi3.img.xz

It is important that the target drive (the memory card of a Raspberry Pi) is big enough for the image. It must be exactly the same size or bigger.

  • If there is an MSDOS partition table it will be straightforward to clone an image to a drive that is bigger than the image.
  • If there is a GUID partition table, GPT, and the drive is bigger than the image, a backup partition table must be written to the end of the drive. mkusb will do it automatically. With some other cloning tools you may have to fix it yourself afterwards, for example with gdisk.
| improve this answer | |
  • @sudodus- when I did this, I saw a gui not a Terminal. Where do you type the code? – BJsgoodlife Dec 2 '19 at 17:21
  • @BJsgoodlife, You can open a terminal window and type the code. (It is also possible to do it via a graphical user interface, but I think it is easier to do it directly from a terminal window.) – sudodus Dec 2 '19 at 19:06

Open the file with the Archive Manager and extract the img file from there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.