14

As I understand it, creating an image of a Linux system makes an exact copy of the OS and any user files/configurations/programs etc.

What I would love to do is create an image of my work PC and install it at home on my desktop. Can someone briefly explain the process of creating and installing images of Linux systems?

Home OS: Windows. Want: An image file that can be executed in a virtual machine (VMPlayer or VirtualBox) or booted directly on my home PC. I have tried clonesys but would appreciate a different method.

2
  • how is the system set up and what imaging tools do you have access to? if you are using lvm it's super easy and can run on a live system. Some of the other tools require offline imaging. Dec 9, 2010 at 13:34
  • You need to provide more detail here, in order to get useful answers. What was "the program" that you tried? What were the image files it produced (their name and size at least)? Are you looking to replace your current OS at home, dual-boot, or run the Linux image in a VM? In any case what is your current OS at home? Do you need to make the image while the OS is actually running or would stopping it for a time be acceptable? (note: edit the extra detail into your question rather than as a comment, or the info could end up hidden after more comments are added by others) Dec 9, 2010 at 14:08

6 Answers 6

3

something you could try.

Prepare a live cd (doesn't matter which one). Have an external storage device large enough (same size as the work HD) to hold the image.

Put the live cd into your work computer and boot it up. Mount your external storage (or even network if you are so inclined)

Use dd to clone the hard drive on your work computer and store it as an image on your storage

Shutdown your work computer

do the same exact method on your home laptop, but instead of cloning your hard drive, you'll be putting your image on your hard drive essentially you have to reverse the if= and of= commands

You might have some hardware compatibility issues right out of the box unless the hardware of your home and work comps are the same. But it is all solvable :)

Enjoy.

4
  • 1
    OP said he wanted to create an image of a running system. A live CD means the system being cloned won't be running. Jul 7, 2011 at 16:39
  • @andrew, how about reading the actual question before just skimming the title. My answer is relevant.
    – g19fanatic
    Aug 5, 2011 at 16:57
  • 1
    No offense intended. I did read the whole question. The title plus the question together indicate that the OP wanted to create the image while the system was running. Hence also his reference to clonesys. Aug 5, 2011 at 17:12
  • 1
    The OP mentions nothing of needing to image a running system. Re-read his question, i take it as meaning he has a 'working' linux system and wants to clone it(running in the title can mean 'working'). His mention of clonesys is arbitrary and chalked up to unfamiliarity. You read it as him wanting a running clone (which isn't possible without running it in a VM to start with...). It doesn't read that way at all to me. What he is asking is doable with my method (and others mentioned).
    – g19fanatic
    Sep 13, 2011 at 1:55
2

http://www.linux-live.org/ gives you a really simple howto of the process:

Linux Live Kit is a set of shell scripts which allows you to create your own Live Linux from an already installed Linux distribution. The Live system you create will be bootable from CD-ROM or a disk device, for example USB Flash Drive, USB Pen Drive, Camera connected to USB port, and so on. People use Linux Live Kit to boot Linux from iPod as well.

0
1

You could use partimage to create an live image. But I think it's hard to get an working live image which you can easily transfer to one pc to the other.

When you can shutdown your work pc I would recommend a live cd with partimage and create an image to an usb stick and rewrite it on the home pc.

Or if you can't shutdown your pc, you could use dump (http://linux.about.com/od/commands/l/blcmdl8_dump.htm) to a file or over network (ssh).

1

The OP (who may still actually be alive) asked for someone to "briefly explain the process of creating and installing images of Linux systems." There are many such processes. To keep it "brief," we should perhaps try to narrow it down.

The title specifies that this is to be an image of a running Linux system. My understanding is that an image of a running system is problematic, because Linux does not have a Volume Shadow Copy feature like Windows has. Files may be in use, and may therefore not be copied correctly, or at all.

Systemback is one of the few surviving tools that at least try to take an image of a running system. I found it somewhat frustrating, but I think that may be because I was using it in a relatively constrictive virtual machine setting. It is pretty much self-explanatory, and there are tutorials available. But, briefly, it requires a two-stage process: use it to create a .sblive file, and then use that file to create an ISO or image file or to burn to a drive.

Other tools avoid the Volume Shadow Copy issue by creating an image when the system is not running. Clonezilla is probably the best-known example. You boot the computer with a Clonezilla bootable USB drive (or similar tool), and then work through Clonezilla's menu, answering questions for your specific situation. Here, too, there are tutorials.

I didn't particularly like Clonezilla's style. To me, it made things some things simpler and other things more complicated. For me, the preferred solution (in converting an Ubuntu virtual machine to a physical drive) was to boot another Linux ISO, use it to run a command that would create a .gz image file of the Ubuntu system (which was not running), and then use it to run another command that would restore that .gz file to a target drive. The commands I used were as follows:

sudo dd if=/dev/sda bs=16M conv=sync,noerror | pv | sudo pigz -c > /media/lubuntu/SSD/UbuntuImage.dd.gz

and then

sudo pigz -cdk /media/lubuntu/1TB/UbuntuImage.dd.gz | pv | sudo dd of=/dev/sdb bs=16M

Those require pv and pigz to be installed on the alternate Linux ISO. The whole process wasn't bad -- I would even say it was simpler than Systemback, once I figured it out -- but it did take some effort to assemble the pieces, and of course the commands were powerful: specifying the wrong drive could wipe out its contents entirely. In the interests of keeping this answer "brief," I won't overwhelm the casual reader with the full details, pointing instead to my detailed writeup elsewhere.

0

You can easily clone the OS using Clonezilla (the Live CD), but just know that the destination drive must be as big, or bigger than the original. These steps will show you how to clone the disk to another.

NOTE - backup your data

2
  • 1
    OP said he wanted to create an image of a running system. A live CD means the system being cloned won't be running. Jul 7, 2011 at 16:40
  • "These steps" is a broken link
    – DrBeco
    Apr 12 at 0:20
0

Here's how I've just done that:

Preparation

Windows 10 desktop

  • Install VirtualBox

The following steps are to provide a way to copy the disk image. I didn't have an external storage device with enough space to hold my laptop's disk image so I mounted my Windows machine vía SSH. There are other ways to do this, but this was easiest for me in the situation.

  • Enable WSL and reboot when prompted
  • Install Ubuntu from the Windows Store
  • Start Ubuntu from the Start Menu
  • Run sudo apt install openssh-server to install sshd
  • Run sudo nano /etc/ssh/sshd_config to edit the sshd configuration
  • Change PasswordAuthentication no to PasswordAuthentication yes, then press Ctrl+x, y, enter to save
  • Run sudo /etc/init.d/ssh restart

The Windows Firewall dialog should pop up now, click Accept to allow incoming connections.

Linux laptop

Run sudo apt install sshfs virtualbox to give you the sshfs and vboxmanage commands.

Now's a good time to test you can make an SSH connection to your Windows machine

Creating a boot image

If, in the next section, you create an image of your entire disk instead of just the Linux partition, then you probably won't need to do this.

I wanted to save space so only took my Linux root partition, but this isn't bootable by itself so I created a bootable ISO image:

Linux laptop

  • Install packages required by grub-mkrescue: sudo apt install grub-pc-bin xorriso
  • Make a directory to hold the bootable files: mkdir -p efibootiso/boot/grub
  • Copy the Grub EFI bootloader: cp /usr/lib/grub/x86_64-efi/* efibootiso/boot/grub/
  • Copy your laptop's Grub configuration: cp /boot/grub/grub.cfg efibootiso/boot/grub
  • Make the image: grub-mkrescue -o boot.iso efibootiso
  • Copy it to your Windows machine: scp boot.iso username@windowsten:/mnt/d/VMs/WorkLaptop/

Creating the disk image

Linux laptop

  • Reboot and select advanced options, then recovery mode from the bootloader
  • Select network from the recovery menu to enable networking
  • Then select the root console option and press enter
  • Run mount to check your root partition (mine is /dev/sda8 )
  • Make a temporary directory to mount your Windows machine, eg: mkdir /run/windowsten
  • Mount your Windows machine, eg: sshfs username@windowsten:/ /run/windowsten
  • Change directory to the location you want to save your disk image, eg: cd /run/windowsten/mnt/d/VMs/WorkLaptop

Here's the trick, if you run mount -o remount,ro / now then you'll get told it's in use, so instead use the magic sysrq keys: SysRq+s to force sync, then SysRq+u to force remount readonly. (SysRq on my laptop was Alt Gr + Print Screen)

  • Now make the VDI file with vboxmanage convertfromraw /dev/sda8 worklaptop.vdi

This will take a long time. I got about 10GB/hour with both machines using 802.11n wifi. Next time I'll use a wired connection.

When It eventually finishes, you'll have a disk image of your laptop's Linux partition.

Windows 10 desktop

  • Start VirtualBox
  • Click New
    • Click Expert Mode
    • Give your VM a name
    • Select the OS type and version (eg. Linux, Ubuntu (64 bit)
    • Give it enough RAM
    • Select "Use an existing virtual hard disk file" radio button
    • Click the yellow folder icon
    • Browse to and select the VDI file from the previous step
    • Click Create
  • Select your new VM
  • Click Settings
    • Click Storage
    • Select the optical Drive
    • Click the disc icon and select "Choose Virtual Optical Disc File"
    • Browse to and select the boot.iso image
  • Click System
    • Verify the optical drive is above hard disk in the boot order
    • Check Enable EFI
    • Click OK

Now you should be able to boot your VM.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .