0

The scenario. I've got an outdated Ubuntu installation I'm preparing to mothball and I want to use the drive it's installed on to install a fresh copy of another distro. Meantime, I've got a fair amount of data and configuration info on the old Ubuntu I want to preserve. In addition, this is one of my main boxes through which I do e-mail and on which I run important cron jobs: my use of it is mostly command-line through ssh sessions. So I don't want to just unceremoniously take it offline.

The task. Transfer the OS to a bootable USB drive and run it from there until re-installation of a new distro on the current HD is complete and operational. In other words, I've got my old working Ubuntu installation running off that USB drive that I can fall back on while I work at getting the new distro set up and reconfigured as I need. The old Ubuntu on USB also acts as a back-up of important files and data that I'll transfer to the new OS once it's operational.

Questions. I've got a USB flash drive of the appropriate capacity. I plan to format it ext2, though f2fs with an ext2 boot partition is also under consideration. Any thoughts on which file system will be better to use on this temporary installation? Also, the USB drive is USB2 and I realize the OS could run a bit slow for that reason. Still, for a period of 2-7 days, while I'm getting the new OS set up and configured, I assume the OS lag will be tolerable: any thoughts on that? Finally, I intend to run a command like rsync -aHAXx / /usb/mnt/point in order to copy the data from the running Ubuntu to the flash drive: any alternate suggestions for copying the outdated Ubuntu OS to the USB flash drive?

  • Is the outdated Ubuntu installation booting in BIOS mode? And is it using one single partition (the root partition) plus an optional swap partition? In that case you can use the One Button Installer and make a tarball, and install from that tarball to the USB drive. And you will have a backup copy too (the tarball stored on another drive). help.ubuntu.com/community/OBI -- Otherwise it should work well with sudo rsync ... and after that fix the bootloader, grub.cfg and fstab, manual tweaks. -- See also help.ubuntu.com/community/Installation/… – sudodus Aug 17 '17 at 17:28
  • Yes, BIOS mode. Single partition with swap but I plan to forego swap since the machine has 6 GB RAM and this is a temporary measure. Planning to use syslinux/extlinux for this, which I prefer to GRUB. Thanks for links. Will look into tar – MJiller Aug 17 '17 at 18:05
  • I think it would be rather easy to do this with the One Button Installer - to let it do the job and avoid the manual tweaks. It is possible to make it skip swap (or to make a very small swap partition, if you create the partitions manually at the 'advanced OBI level'). – sudodus Aug 17 '17 at 21:03
  • I'm slightly confused. How are you going to run both from the USB and install at the same time – fosslinux Aug 18 '17 at 0:23
  • You need two USB drives. One with the One Button Installer, and one where you want to install the system. You can store the tarball in the USB drive with the One Button Installer (if there is enough free space). Otherwise you can store the tarball in another drive (but not in the drive that is the source for the copying process). – sudodus Aug 18 '17 at 12:40
1

I suggest you to:

  1. BACKUP ALL YOUR DATA.
  2. Partition your usb flash drive:
    • 1 fat32 partition containing your new bootable ubuntu system (use Unetbootin for instance).
    • 1 ext4 partition containing an image of your old ubuntu system.
  3. Boot your USB flash drive.
  4. Install the new system.
  5. Mount & Chroot the image for using your old system.
  • Hadn't considered chroot but that's an interesting option. For that matter I suppose qemu/virtualbox booting the old Ubuntu under the new OS are worth consdiering too. Thanks for the suggestion. – MJiller Aug 17 '17 at 18:07
  • You could do that too,but that's not the fastest way to use your old system. – userv Aug 17 '17 at 19:13
1

I followed through with my original plan and I have to say it has worked out quite well. For those in a situation like mine, where the installed O.S. has a relatively small footprint (i.e., it is smaller than cheaply-available USB drives) and the hard drive where the O.S. is currently installed is the target drive for migrating the system to a new O.S., this method of migration should prove quite effective. It gives you a working copy of your current O.S., which can be booted to at any time, as well as a copy, accessible as a data partion once the migration is complete, of all files and folders located under the old O.S. It just involves getting a USB drive of the requisite size (I actually got by with a 32GB drive), formatting it ext2, making it bootable with syslinux, copying all data from the old O.S. (that's actually still running) to the USB drive, and finally rebooting the system using the USB drive. More detailed steps below (instructions for a legacy BIOS, non-uefi system).

What is needed: a USB drive of appropriate size, a system that has syslinux installed, and the rsync utility running from the soon-to-be-replaced O.S.

  1. Acquire a USB drive of the requisite size, insert it into your system, create a partition, format it ext2, then set the boot flag for the partition (I used gparted for the last 3 steps).

  2. Make the drive bootable using syslinux: from a system with syslinux installed, run dd bs=440 count=1 if=/usr/lib/syslinux/bios/mbr.bin of=/dev/sdx ("x" being replaced by the drive letter of your inserted USB drive).

  3. Mount the drive and copy needed files for syslinux, from the system syslinux was installed from, using the command cp /usr/lib/syslinux/bios/*.c32 /syslinux-boot/syslinux/ (those files ultimately belong in the directory /boot/syslinux, but since that directory could get overwritten in step 4., we are temporarily renaming, at this stage, /boot to /syslinux-boot)

  4. Copy all files from the running old O.S. to the USB drive using the command rsync -aHAXx / /mount/point-of/USB-drive (/ is the root directory of your old O.S., from which you are running rsync, while /mount/point-of/USB-drive will be whatever point at which you mounted your USB drive). This process can take a very long time: on my system, with USB2.0 ports, it took over 12 hours; so be patient.

  5. Once copying is complete, move the syslinux directory located in the /syslinux-boot directory on the USB drive into the /boot directory on the USB drive.

  6. Edit or create a syslinux.cfg file within the /boot/syslinux directory on the USB drive. This can be a bit tricky as you will need to know the exact name and location of the kernel and initramfs you want to use when booting the USB drive. You will also need to stipulate the location of the root file system on the USB drive as it will be seen by your computer's BIOS. My syslinux.cfg file was appropriated straight from the Arch wiki, with just a bit of minor editing to tailor it to my system. It looks something like this:

PROMPT 1
TIMEOUT 50
DEFAULT Old-OS

LABEL Old-OS

    LINUX ../vmlinuz-3.2.0-75
    APPEND root=/dev/sdc1 rw
    INITRD ../initramfs-linux.img

(/dev/sdc1 is the location of the USB drive on my system)

  1. Reboot the computer, select in BIOS the newly-copied USB drive as the boot media, and it should boot pretty much as it always has. You can now take the current hard drive out of service and install your new O.S. to it, copying over such data as will be needed from the old installation once the new O.S. is installed and booting.

Afterthoughts:

  1. How long can an O.S. originally installed to a hard drive be run from a USB drive? I have no idea. I think it should be a relatively short period (perhaps a few days?) since, if running from flash media, special configurations are required in order to minimize read/write cycles. My plan is to run the old system from USB for no longer than about a week or two.

  2. Making the drive bootable could probably could be done with GRUB. I favor syslinux over GRUB, so I didn't really investigate that avenue.

  3. Not sure whether the vfat file system could be used in a scheme like this. I thought of using f2fs, which I find interesting for USB projects. Last I checked though, f2fs partitions cannot be booted from; such a variation on the present solution would thus probably require putting 2 partitions on the USB drive--a small ext2 /boot partition for kernel, initramfs and boot files, then the main data partition formatted f2fs. Plus additional editing of syslinux.cfg

  4. If there is any possibility the bootable USB drive running your old O.S. will be used in some other computer, it will be better to use the drive's UUID in your syslinux.cfg file instead of the device path, as I've used.The command blkid will provide the needed information for doing that.

Credits: the Arch wiki (mainly https://wiki.archlinux.org/index.php/syslinux)

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.