The review I did of the Xtra-PC I did a few weeks ago is by far the most read (and commented on) piece on my blog. So I thought it is time for a follow on. This includes instructions on how to clone your XtraPC onto another USB stick or onto the internal hard disk in your PC (if that is still working) – so if you want to know how do do that (a commonly asked question on the original review), read on!
A little look into the insides of this product – what makes it tick.
I have the top of the range 128GB stick. For the purposes of this work I am using the Xtra-PC in a 6 core 4GHz AMD Bulldozer machine with 16GB of memory and USB3 ports. This means that the USB3 stick operates much faster than it would in a USB2 backwards compatible mode.
The majority of the stick is formatted as the /data partition – in my case 94G in size. If you go for the smaller models the size of this area will be the main difference. This is arranged as the first partition table and significantly is formatted as the Windows compatible vfat file-system instead of one of the several (more efficient) native Linux file-system choices. Having it as the first file-system and Windows compatible is significant in that the Xtra-PC behaves just like any other memory stick. You can copy files to and from the /data partition by inserting the stick in any other computer.
Next is the partition for the Xtra-PC Linux operating system. This is sized at 21G on the stick I have and, with the extra software I have already put on about 25% full.
Lastly there is a small (2G) Linux swap partition. This is present but only used as a matter of last resort as the Xtra-PC is configured to swap to a number of zram areas first. Swapping to zram involves moving the data to another part of memory and compressing it as it goes. As the CPU power available in a computer is far greater than the speed of any device to be swapped to this is worth doing. It gives a graceful degradation of performance as the ‘swap’ fills up rather than hitting a sudden brick wall. Enough of a hint to e.g. close down some of the tabs you have open..
The machine I am testing on has twin screens, a true HD HDMI monitor and a 1280×1024 VGA screen.
When Xtra-PC comes up both screens are mirrors of each other and set at a fairly low resolution. The way to fix this however is to use the Local Administration -> Multi-monitor-configuration menu item from the bottom left hand corner Xtra-PC logo. This lets you position each screen relative to the other (they start superimposed – hence the same image on both screens) and choose which resolution you want for each screen. This gives a nice big work area.
What I would like to do before any more tinkering is having a fast and reliable way to clone my Xtra-PC onto another memory stick. Although memory stick wear is not the bad problem it used to be there hardware does not have any way of warning that it is about to wear out like the more expensive SSD disks do.
Looking at the /etc/fstab we see that the filesystems are mounted according to blkid rather than raw device and partition name. This is very wise as for a removable device like this which actual device name it gets depends entirely on what else is plugged in! The downside of this is that if we were to make a complete binary copy of the USB sick the computer would get somewhat confused if both sticks were plugged in at once. So the “brute force” method of taking a backup would be more trouble than it is worth! Also the stick would have to be the same size or larger for a ‘raw’ copy to work.
Here are the steps needed to clone your Xtra-PC stick onto another USB stick for backup purposes or equally can be used to install to the internal disk in your PC if you are sure that is working. This will involve executing some commands as the root user so be extra careful you are operating on the right device and not destroying the contents of another data disk.
I am covering the case here of backing up your Xtra-PC to another USB memory stick. The procedure for internal hard disks is the same as Linux treats USB keys just the same as any hard disk. It does not really matter how big the other USB stick or internal hard disk is, as long as it is big enough for the data you want to put on it. At a pinch an 8G or 16G USB stick would do if you don’t not have much data to store.
The first step is to plug the stick you want to use into another USB port on the machine you are running the Xtra-PC on. You will get a pop-up window “Removable medium is inserted”. Proceed with opening the media in File Manager.
You will now get a File Manager window
where that something is whatever file-system label has been put on that USB stick. For standard USB sticks sold for use with Windows this will be 2 sets of hex digits separated by a hyphen, e.g D1471-34AF.
Now open a terminal (Ctrl-Alt-T) and type the command df.
You will see a report of the free space on all your visible file-systems. There should be a line there that matches the /media/administrator/something you are seeing in the file manager window.
Make a note of the first thing on that line which will look like /def/sd then a letter and a number. The /dev is the directory path where device files live. “sd” stands for SCSI disk – all SATA and USB disks work as if there are SCSI disks the letter is which disk (this can vary BE VERY CAREFUL) and the number which partition on that disk. For a typical USB key there is only 1 partition taking up all the space. This is something we need to change to accommodate Xtra-PC.
Assuming that the device you are seeing in the df output is /dev/sdq1 perform the following steps – obviously substituting sdq for the device you actually want to use:
sudo fdisk /dev/sdq
- You will be asked for your password as you are now doing something as the super-user. Note that the default ‘administrator’ account on Xtra-PC has this powerful ability, it would be impossible to ever install any new software or system updates without it. It is good practice to create another account under your own name without sudo ability.
p command will print the current partition table. You will see just one partition in the case of a USB stick or several if you are reusing an internal hard disk. Use the d command to delete all existing partitions. This will remove everything already on that disk so be very careful you have the expected device!
Now create a DOS file-system partition for use as /data. Fdisk works in units of 512 byte sectors but you are allowed to say +2G for example for space equivalent to 2 Gigabytes. Use the n command, The partition start must be 2048 sectors to give room for the bootstrap that lives before it.
Once this partition is created set the type to the letter b by using the t command.
Next create a partition for the Linux root. Again it is up to you how big or small you make this, just bear in mind that what is on your current install must fit. The default partition type is correct in this case.
Lastly make a SMALL Linux swap partition as partition 3 – also using the n command. As Xtra-PC mostly swaps to zram this will hopefully not be used. 1G is plenty! Use the t command to change the type of this to 82.
Lastly use the a command to mark partition 2 as the bootable one.
The p command will confirm that everything is looking OK
Disk /dev/sdq: 250.1 GB, 250059350016 bytes 255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0xb7b1c70c Device Boot Start End Blocks Id System /dev/sdq1 2048 2099199 1048576 b W95 FAT32 /dev/sdq2 * 2099200 484444159 241172480 83 Linux /dev/sdq3 484444160 488397167 1976504 82 Linux swap / Solaris
The w command will write out this partition table.
Next we have to tell the Linux kernel that the partitions for this disk have been changed. This is a simple command:
sudo kpartx /dev/sdq
Now we need to create the filesystems and swap areas. 3 commands:
sudo mkfs -t vfat /dev/sdq1 – to make the /data partition
sudo mkfs -t ext4 /dev/sdq2 – to make the / partition
sudo mkswap /dev/sdq3 – to prepare the swap space
Remember we said that Xtra-PC very wisely mounts file-systems by ID rather than physical device names? Now is the time to use the blkid command to make a note of the new identifiers that have been created by building new file-systems – sample output has been provided – use YOUR numbers not these.
sudo blkid /dev/sdq1
/dev/sdq1: UUID=”D147-4D74″ TYPE=”vfat”
sudo blkid /dev/sdq2
/dev/sdq2: UUID=”d6047cba-a3ed-4165-9884-033ebbc1add2″ TYPE=”ext4″
sudo blkid /dev/sdq3
/dev/sdq3: UUID=”67207b39-5498-499e-a5d2-142be50ed8fc” TYPE=”swap”
Now we mount the new, still empty, root filesystem.
sudo mount /dev/sdq2 /mnt
And copy everything in the root file-system to the new copy. Best to shut as much down as possible (no documents open etc) before doing this.
sudo rsync -xDApXHla / /mnt
This will take a while – possibly 15 minutes or more – go have a cuppa!
There are some amendments we now need to make to the copy. Changing the UUIDs for the 3 filesystems to the ones for the new home, and installing the bootstrap.
sudo chroot /mnt
This will give you a root shell in the context of your new copy. At this command prompt then do:
Then edit the /etc/fstab file within this chroot using an editor you feel comfortable with and replace the UUID values for the /data root and swap lines for the ones that belong to the file-systems you freshly created. This is vital, otherwise the new clone will not know where to go for any of its file systems. It is important that is is done before the bootstrap install as the UUID of the root partition is referenced there:
You will get a few grumbles out of these commands but they seem to work anyway…
All done now. Exit out of the chroot shell using the exit command then
sudo umount /mnt and the clone should be ready.
If you have anything on /data you can also copy that over onto the clone. This can just be done using the File Manager (the VFAT filesystem does not have the concept of different file owners).
This should give you a working clone. I tried this onto both a 32G USB stick and then from that onto the internal 250G disk of an old Core 2 Duo based machine. The resulting Xtra-PC boot time was about 45 seconds from cold (much the same as my more modern machine manages from the original USB3 stick). Quite a bit better than USB2 boot time. Also worth noting is that once the clone image was running I re-did the grub-install step and this time no error messages at all.
Note this method works because the Xtra-PC is not really doing very much in the background. There are no open databases or other things that the direct file-system copy would not suit. Taking reliable ‘hot’ backups of 24/7 running systems is actually quite a difficult problem and a great deal of effort is expended finding better and better solutions to it.If you want to use these techniques on a more complex setup I would suggest running it in ‘single user mode’ so any complex services are shut down. The -x option to rsync limits the copy to just one file-system. This neatly avoids trying to duplicate the contents of special file-systems like /proc. If your Linux is built over more than one file system you would have to clone & copy each of them in turn…