Score:0

How to create an image of system partition without booting from live DVD or USB? (Emergeny mode?)

tr flag

I'd like to create an image of my 20.04 system partition as a backup in case that anything goes wrong so that I can restore it later.

Additionally I want to make the system partition smaller (maybe after having it backed up...) so I can create a seperate partition for some photos and other data (which shouldn't be auto-mounted, but can be mounted when needed)

My problem is that the laptop doesn't have an optical drive and currently I don't have anything here that I could boot from (except a live DVD, which obviously doesn't help much without an optical drive)

So I thought it should somehow be possible to do this when I manually unmount / first, maybe after booting to emergeny mode? Or isn't it possible to unmount / even in emergeny mode?

Might using dd also work when / is mounted read-only?

Any ideas how I can get these simple tasks done without having to reboot from USB media?

Any help is appreciated.

edit:

I've given up on the modifying partitions part now as there really doesn't seem to be a good solution for shrinking a system partition that is mounted - But still I cannot believe there is no way to create a "live" image from a running system, as this is often needed for servers or other computers that you don't have physical access to...?! (And it was already possible in some other OS years ago)

Nmath avatar
ng flag
You do not need a DVD player. You can boot from a live USB. You cannot unmount the root file system while that installation is running.
user535733 avatar
cn flag
Do you have available partitions or unpartitioned space? If so, you can install Ubuntu *there*, boot into that system, then resize your current system partition(s). Not simple, easy to get confused, and adjusting paritions can always be risky. It would be simpler, safer, and less confusing to borrow a friend's empty USB drive for an afternoon.
j0h avatar
au flag
j0h
what you do not want to do is re-partition a disk that is currently running your operating system, countless issues will ensue. booting via a seprate boot media of any type is you safest option, that could be a boot disk, or another harddrive with linux already installed.
tr flag
@user535733 Maybe I could deactivate and delete the swap partition temporarily, but probably it is too small for a complete installation. - And I don't know how to install Ubuntu without some bootable medium? Can Ubuntu install itself from a running session to some other partition or media?
tr flag
The not very easy but easy to get confused part wouldn't be the problem, and I would create the image first anyway if anything should go wrong. - Would have to wait til next week and buy some crappy USB flash drive somewhere (that probably also won't last very long otherwise - which is also the reason why I currently don't have a working USB drive @Nmath)
tr flag
@j0h Ok, let's say the re-partitioning should wait until I get some bootable media - Does anyone know how I can at least create an image without bootable media?!
j0h avatar
au flag
j0h
is your system operational right now? is linux currently installed? dont make back ups on the same disk, its a waste of space, and affords you no protection should that disk fail.
tr flag
Yes and yes. (Ubuntu was pre-installed)
tr flag
I was rather thinking of a network share or backup via ftp or something like this. Writing an image to the same partition that you actually want to backup is not a very good idea anyway.... (would probably result in data loss I guess)
j0h avatar
au flag
j0h
ok, and you would like to create an additional way to boot you system. and or back up all your files. if you have the option, back up your personal files on your network drive. network boot is a thing, we are skipping that for now. all of your personal files should be in /home/$USER. making separate partitions, doesnt give you extra resilience to having a single failed hard drive. should your harddrive fail, having another bootable partiton wont help you. One of the reasons we are suggesting a boot usb stick, is that the total space required is much lower.
j0h avatar
au flag
j0h
There are many ways to create a bootable usb stick in linux. there is the "Startup disk creator" a graphical program, frequently included with many versions of ubuntu. you can download an image of whatever your favorite version of linux is. I like Mate, Im linking it here. https://cdimage.ubuntu.com/ubuntu-mate/releases/20.04/release/ubuntu-mate-20.04.3-desktop-amd64.iso once its downloaded, you can create a boot disk with the startup-disk-creator utility. You can use the command line if you want, $sudo dd if=/home/$USER/Downloads/ubuntu-mate-20.04.3-desktop-amd64.iso of=/dev/some/other/disk
tr flag
Thanks, but in case the internal drive fails (or anything else) I want to have an external backup not only of the files in /home but of the whole system because it took enough time to configure and install everything, and it would be useful in many situations to be able to go back to the current system where everything works as it should when I need to. I'm aware that a seperate partition only helps against e.g. filesystem corruption, but it also makes it a bit easier to backup the files stored on this partition regularly (just one place that needs to be backed up and no files I don't need)
tr flag
Having a second partition to boot from would primarily help me with creating the image when I currently don't have an USB drive, but could help in some other situations too when I think about it. But I don't intended this as a protection against a failed drive or something like that. Is there a way to install Ubuntu to some other partition or media from a running session, without booting from a bootable installation disc or USB drive first? I think the Startup disk creator needs an USB drive too... (?)
sudodus avatar
jp flag
If you can't buy a USB pendrive now, please try to borrow one from a friend, relative or colleague. The things you want to do are much more complicated without a USB pendrive. (It is also possible to boot via a USB adapter into a memory card (for example an SD card).
tr flag
Maybe I could move the files from an SD card somewhere else and boot from it, haven't tried this yet - but might be a good hint (if the computer can boot from it)
Score:1
in flag

If you don’t have the means to boot from an optical drive or usb you can boot most live iso files by placing them on your local hard drive and adding custom menu entry to grub.

I’ve described how to do this with GParted in the link below and expect you could do the same with something like clonezilla to image your system

How to modify partitions without a live USB/CD

I have GParted set up to run like this on most of my systems and it works just like booting from a usb

tr flag
That's pretty cool, so you always have your bootable USB drive with you when you need it :) (As long as the drive works correctly, of course...)
tr flag
That is also pretty close to what I was thinking of, thank you. - Probably one should make sure that the image file has its own partition, so you can modify all other partitions without problems. (If it is a small image file it probably will be loaded to system memory, but I wouldn't want to modify the partition on which the image file is placed anyway...)
PonJar avatar
in flag
That’s a sensible suggestion although I have never had a problem with this approach. The GParted and Clonezilla iso’s are quite small. I have placed them in my EFI partition before now but you don’t always have enough space for that.
tr flag
I assume it won't be a problem as long as the image file is small enough and system memory is big enough, and the **toram** option is used. Otherwise (e.g. when you use a full Ubuntu image and don't have enough RAM installed) probably the partition where the image file is stored will remain mounted, and if not unmounted manually (which could then go wrong...) probably cannot be modified anyway. Notes on using **toram** and more useful information about booting ISO files from harddrive: https://help.ubuntu.com/community/Grub2/ISOBoot#Installing_Ubuntu_from_a_Menuentry_Boot
Score:1
tr flag

I've marked PonJar's answer as accepted as it is the best solution I got (and found), and there isn't a good way to shrink a system partition while the system is running anyway.

But in case one wants to boot some other ISO image from hard drive, the GRUB entry probably needs to be modified.

Here is a detailed and more general guide on how to do this: https://help.ubuntu.com/community/Grub2/ISOBoot

It is even possible to use this method for installing Ubuntu without a USB drive or DVD (as long as GRUB is present and working)

Score:0
us flag

IMPOSSIBLE, you cannot resize a partition while it's mounted. Just boot from a live usb and use gparted.

PonJar avatar
in flag
I agree with you that a live usb is the easiest way to do this. However if you want to increase the size of a mounted partition and you have unallocated space after it on the drive then you can do it. See here https://askubuntu.com/questions/24027/how-can-i-resize-an-ext-root-partition-at-runtime I’ve tested this and it works.
tr flag
There doesn't seem to be a good solution for shrinking a mounted partition indeed... (I'm not saying that Windows is able to ;) - But at least you can use the internal drive to boot an image from as PonJar suggested :)
tr flag
I've given up on the modifying partitions part, but still I cannot believe there is no way to create a "live" image from a running system, as this is often needed for servers or other computers that you don't have physical access to...?!
Yvain avatar
us flag
You could try a dd from the disk to usb
tr flag
Maybe it works if I can sync (and if possible remount read-only) the partition before? - I could also check the image file with e2fsck to see if it appears usable, or mount the image file read-only in order to verify the files in it against the source filesystem. Of course rebooting to a live DVD, USB drive or ISO file is the best solution in most cases. But if using dd at least doesn't mess things up (if used correctly) it might be worth a try.... Maybe someone has tried this before? (Still doing some research on this...)
Yvain avatar
us flag
You can't break anything unless you mistake the options if / of (input file / output file) Take the whole drive (not a partition) as if and of to the usb it'll be good.
tr flag
I thought I couldn't mount the resulting image file when I dd the whole drive, but it is still possible - so you're right that also having the partition table and boot loader etc. included is a good idea :) (How to access partitions inside a full-disk image: https://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device )
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.