Putting a PC-based Linux system onto a USB drive

User discussion and information resource forum for Image products.
Post Reply
Brian49
Posts: 26
Joined: Thu Jun 07, 2012 12:58 pm

Putting a PC-based Linux system onto a USB drive

Post by Brian49 »

I'm looking for a way to put my PC-based Linux Mint Debian system, with all my personal settings and customisations, onto a USB drive. Can I use IFL to do that, please? Evidently it isn't just a matter of using the "restore" procedure to put a TBI of the main system onto the USB drive, because that necessarily includes the GRUB component, which means that attempting to boot the USB simply boots the system on the hard drive. Many thanks.
TeraByte Support(TP)
Posts: 305
Joined: Wed Aug 31, 2011 4:22 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by TeraByte Support(TP) »

Brian49 wrote:
> I'm looking for a way to put my PC-based Linux Mint Debian system, with all
> my personal settings and customisations, onto a USB drive. Can I use IFL to
> do that, please? Evidently it isn't just a matter of using the
> "restore" procedure to put a TBI of the main system onto the USB
> drive, because that necessarily includes the GRUB component, which means
> that attempting to boot the USB simply boots the system on the hard drive.
> Many thanks.

Not sure if you're restoring an image of an entire drive to the USB drive, or individual partitions. But in either case, the problem you're having (always booting the Linux install on the hard drive), could be because of duplicate UUIDs for the cloned partition(s). Whenever you image/restore a Linux partition, the restored copy will always have the same UUID as the source partition, and that is what grub and /etc/fstab typically use to identify the correct partition(s) when booting and mounting. The UUID is created when the partition is formatted, and imaging/restoring doesn't change it. It can be changed manually with 'tune2fs'

This web page has some information on this overall subject:
http://www.sudo-juice.com/how-to-change ... partition/

Note that an easier way to change the UUID of a parttiion than given on that page is this command (as root):
tune2fs -U random /dev/sdXY (where /dev/sdXY is the partition you want to change, such as e.g. /dev/sda2)
Obviously, you want to be VERY careful that you are using the correct partition designation when you change a UUID, and also be sure you always have a known good backup of the main hard drive that you're trying to clone.
Brian49
Posts: 26
Joined: Thu Jun 07, 2012 12:58 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by Brian49 »

Thank you very much for responding. Yes, I was working with partitions, not entire drives.

If I understand correctly, the idea is that after "restoring" the TBI to the USB, I then change the UUID of the partition on the hard drive, so that it differs from that of the partition on the USB. Have I got that right, please? Thanks again.
TeraByte Support(TP)
Posts: 305
Joined: Wed Aug 31, 2011 4:22 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by TeraByte Support(TP) »

Brian49 wrote:
> Thank you very much for responding. Yes, I was working with partitions, not
> entire drives.
>
> If I understand correctly, the idea is that after "restoring" the
> TBI to the USB, I then change the UUID of the partition on the hard drive,
> so that it differs from that of the partition on the USB. Have I got that
> right, please? Thanks again.

It could be either way, but my choice would be to leave the (known working) original hard drive and Linux installation alone, and only change things on the USB drive.

You will also need to look at the /etc/fstab file on the cloned USB root partition. If there are UUIDs in there (most likely there are), then they would have to be changed to the corresponding new ones. How many new UUIDs you have to deal with would depend on how many Linux partitions are involved. If you just have a root partition involved, then you only have 1 UUID to deal with.

Also, how are you dealing with Grub on the USB drive? Is the USB drive multi-boot, or does it just have the cloned Linux install? I'm assuming you want the USB drive to be self-contained and boot on it's own?
Brian49
Posts: 26
Joined: Thu Jun 07, 2012 12:58 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by Brian49 »

Since my previous reply I had got as far as changing the UUID of the partition on the USB, and editing /etc/fstab on the USB, both of which were straightforward enough. But updating GRUB on the USB has defeated me so far. I tried editing /boot/grub/grub.cfg on the USB to reflect the new UUID, but then it wouldn't boot at all. The USB will carry only the cloned Linux install, and ideally I would like it to boot on its own. Many thanks once again for your kind help.
TeraByte Support(TP)
Posts: 305
Joined: Wed Aug 31, 2011 4:22 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by TeraByte Support(TP) »

Brian49 wrote:
> Since my previous reply I had got as far as changing the UUID of the
> partition on the USB, and editing /etc/fstab on the USB, both of which were
> straightforward enough. But updating GRUB on the USB has defeated me so
> far. I tried editing /boot/grub/grub.cfg on the USB to reflect the new
> UUID, but then it wouldn't boot at all. The USB will carry only the cloned
> Linux install, and ideally I would like it to boot on its own. Many thanks
> once again for your kind help.

Once you have edited both /etc/fstab and /boot/grub/grub.cfg on the USB drive with the new UUID of the root partition on the USB drive, then you still need to install grub to the MBR of the USB drive. The KB article linked to below has a procedure for what you need to do. The article includes a link to a grub2 boot disk that you can boot from to follow the steps in the procedure.

http://www.terabyteunlimited.com/kb/article.php?id=408

Since that article is focused on systems booting Linux from BIBM, here's some notes and differences specific to the situation that you are dealing with:

1. In step 4, when you are searching for partition(s) containing a grub.cfg file, you will likely get more than one result, since you will have both the hard drive install, along with the root parttiion on the USB drive - both of which will contain a grub.cfg file. You will need to know which of those partitons is the root parttiion on the USB drive, so that you can boot from it in step 5. To do that you can use the grub 'cat' command to display the file contents of each grub.cfg. You need to identify which copy of grub.cfg contains the new UUID that you set on the USB root parttiion.

For example, if the search command in step 4 gave this result:
hd0,msdos2 hd1,msdos1, cd

That means it found a grub.cfg on both hd0,msdos2 (drive 0, partition 2), and on hd1,msdos1 (drive 1, partition 1).
To determine which of those 2 partitions is your USB root partition, run the 'cat' command like this:
cat (hd0,msdos2)/boot/grub/grub.cfg
cat (hd1,msdos1)/boot/grub/grub.cfg
...and see which of those files contains the new UUID. Then use that partition in step 5 to boot into Linux.

2. For step 5, assuming it was the 2nd partition listed above, the boot command would be:
configfile (hd1,msdos1)/boot/grub/grub.cfg
...which should boot the system into Linux from the USB drive.

3. For step 6, you need to install grub to the MBR of the USB drive (NOT to the root partition). First, make sure that you are actually booted from the USB drive, and that the root partition you are running from is actually the one on the USB drive. An easy way to do that would be to have a file there (create one there after restoring) that you can use to identify the root partition on the USB drive.

Once having verified that you are booted and running from the USB drive, run the 'df' command and determine the Linux designation for the USB drive. For example if 'df' lists your root partition (/) as /dev/sdb1, then you will want to use /dev/sdb in the grub-install command in step 6, like this:

grub-install /dev/sdb (/dev/sdb is just an example - your USB drive may be different)

Note that it's using /dev/sdb above (not /dev/sdb1) because you need to install to the MBR on the USB drive, not to the root partition.

Once again though, ensure you have a known good backup of your hard drive installation in case something goes wrong. The most important thing is that before running the 'grub-install' command above, make sure that the drive you're installing it to is actually the USB drive, as described above.
Brian49
Posts: 26
Joined: Thu Jun 07, 2012 12:58 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by Brian49 »

Thanks very much for that. I now have a fully functioning installation on the USB drive.

I have a follow-up question if I may, please. If I use IFL to take an image of the partition on the USB, should I then be able to "restore" the image to a different USB? Would the GRUB issue come back to haunt me? Thanks again.
TeraByte Support(TP)
Posts: 305
Joined: Wed Aug 31, 2011 4:22 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by TeraByte Support(TP) »

Brian49 wrote:
> Thanks very much for that. I now have a fully functioning installation on
> the USB drive.
>
> I have a follow-up question if I may, please. If I use IFL to take an image
> of the partition on the USB, should I then be able to "restore"
> the image to a different USB? Would the GRUB issue come back to haunt me?
> Thanks again.

Yes, that should work OK also. In this case, it should be easier to take the image of the entire USB drive by selecting the top item (Entire Drive) on the Backup From screen when creating the image. Then select Entire Drive again when restoring the image to the target USB drive. Doing that will eliminate having to deal with grub, which will be automatically included in the image. You also have the option of using the Copy feature of IFL (instead of Image/Restore) to copy directly from one drive to the other, and do it in one step. In this case also, you can select Entire Drive to eliminate dealing with grub.

You could also do it by imaging/restoring the individual partition as you did before, and then you'd need to select the "Restore First Track" option when restoring to the target drive. That option will put grub on the target drive. If copying, the corresponding option would be "Copy First Track". In either case, I'd suggest entering a 0 (zero) in the First Track Sectors text box when restoring or copying. That will ensure that all of Grub's sectors get to the new drive.
Brian49
Posts: 26
Joined: Thu Jun 07, 2012 12:58 pm

Re: Putting a PC-based Linux system onto a USB drive

Post by Brian49 »

A very helpful reply - many thanks. It's good to know that images are portable, because I've found that USB drives are liable to become unusable from both a software and a hardware point of view.
Post Reply