0

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)

user79
  • 43
  • 3
    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. – Nmath Oct 10 '21 at 00:01
  • 3
    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. – user535733 Oct 10 '21 at 00:33
  • 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. – j0h Oct 10 '21 at 02:50
  • @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? – user79 Oct 10 '21 at 02:53
  • 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) – user79 Oct 10 '21 at 02:56
  • @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?! – user79 Oct 10 '21 at 03:04
  • 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. – j0h Oct 10 '21 at 03:24
  • Yes and yes. (Ubuntu was pre-installed) – user79 Oct 10 '21 at 03:27
  • 1
    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) – user79 Oct 10 '21 at 03:35
  • 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 Oct 10 '21 at 03:47
  • 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 – j0h Oct 10 '21 at 03:53
  • 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) – user79 Oct 10 '21 at 04:11
  • 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... (?) – user79 Oct 10 '21 at 04:23
  • 1
    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). – sudodus Oct 10 '21 at 10:32
  • 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) – user79 Oct 10 '21 at 14:59

3 Answers3

1

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

PonJar
  • 1,868
  • 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...) – user79 Oct 10 '21 at 15:03
  • 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...) – user79 Oct 10 '21 at 15:12
  • 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. – PonJar Oct 10 '21 at 16:45
  • 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 – user79 Oct 11 '21 at 14:03
1

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)

user79
  • 43
0

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

Yvain
  • 544
  • 1
  • 4
  • 12
  • 1
    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. – PonJar Oct 10 '21 at 16:38
  • 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 :) – user79 Oct 10 '21 at 17:32
  • 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...?! – user79 Oct 10 '21 at 17:37
  • You could try a dd from the disk to usb – Yvain Oct 10 '21 at 22:44
  • 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...) – user79 Oct 10 '21 at 23:37
  • 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. – Yvain Oct 11 '21 at 00:49
  • 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 ) – user79 Oct 13 '21 at 11:33