4

Plenty of people struggle when they want to modify partitions on their running system. Frequently its because the partition they want to modify is mounted and when they run GParted the partition is marked with a lock symbol. The easiest solution of course is to use a live environment and make the changes from there. But what happens when for what ever reason they don't have access to live media? Perhaps they just don't have access to a usb device on which to place a suitable live environment such as the ubuntu instalation iso or the smaller GParted live iso. Can you modify partitions without a live USB/CD?

2 Answers 2

7

Fortunately there is a way to boot a live environment without a usb stick or CD drive.

The overview of this answer is that you boot an iso image stored on your hard drive by adding a custom entry to grub. However always make sure you have backups of any data you cannot afford to lose before trying to modify partitions. These are the steps:

Identify your partitions in grub command notation.

This is probably the least well known part of this procedure. I recommend using your home directory to store the iso image so you need to find where that is from the perspective of the grub command prompt.

You can do this from the grub menu while booting, just press c for a command mode prompt and then ls to list the partitions. You should see a list containing things like (hd0,msdos1) or (hd0,gpt1). These are partitions on your system and you are looking for the one containing your home directory. To do this type ls (hdX,Y)/ at the command mode prompt to list the contents of the top level of that partition. If you don't have a separate home partition you are looking for the partition containing home/ as below. If you do have a separate home partition you are looking for john/ or jane/ or what ever your username is.

enter image description here

If your system boots straight into Ubuntu you can make the grub menu visible by pressing the shift key (legacy system) or the Esc key (UEFI system) while booting.

Download the iso

Download the GParted iso from https://gparted.org/download.php . It's smaller than the Ubuntu iso but that works too. Choose where to permanently store it. In this example I chose my home directory and renamed the iso to gparted.iso rather than use the longer name that was downloaded and which specifies the gparted version. That means my iso is held at /home/user/gparted.iso

Modify grub

The next step is to modify your /etc/grub.d/40_custom file. Your file needs to look like this:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "GParted ISO" {
    set root=(hd0,msdos1)
    set isofile="/home/username/gparted.iso"
        loopback loop $isofile
        linux (loop)/live/vmlinuz boot=live union=overlay username=user components noswap ip=net.ifnames=0 toram=filesystem.squashfs findiso=$isofile
        initrd (loop)/live/initrd.img
}

The /etc/grub.d/40_custom file should already have the first 5 lines and may have other custom entries if you have added them in the past. You can keep any previous additions untouched.

Your version of the file will be slightly different. You need to change the the correct parameters for the root=(hdX,Y) line. You also need to get the correct path for your setup in the set isofile="/home/username/gparted.iso" line. If you have a seporate home partition it should be set isofile="/username/gparted.iso".

You can edit the file however you like but one way to do it is to open a terminal in your home folder and use the following:

a) cp /etc/grub.d/40_custom 40_custom.bak (this makes a backup of your 40_custom file in your home directory)

b) cp /etc/grub.d/40_custom 40_custom (this makes a working copy of your 40_custom file in your home directory which you edit in your editor of choice)

c) sudo cp 40_custom /etc/grub.d/40_custom (copies the modified file back)

d) sudo update-grub

When you reboot you should get a grub menu with a new entry for "GParted ISO" which will boot you into the GParted live enviroment where you can modify your partitions. I follow partitioning questions so if you hit any problems and cannot find an answer by searching Ask Ubuntu ask a new question and I'll help if I can.

2
0

Thank you for sharing this! Maybe it is not the easiest solution for unexperienced users, but can be very helpful in some (or many) cases :)

But if the image file is too big to be loaded to system memory by the toram option you probably can't (or shouldn't) modify the partition where the image file is stored.

If it is just a small image file and toram is used this probably won't be a problem. But it may well be one if the image file is larger than system memory, or if toram is not used. And I don't want to find out what happens when you move or resize the partition where the image file is stored, and the data, including the image file, has to be moved, and after it has been moved, the system tries to read data from the image file which now is located somewhere else on the disk...

Having a seperate small partition for the image file(s) may be the best and safest solution then (or just not modifying the partition where the image file is stored)

More useful information about booting ISO files from harddrive can be found here: https://help.ubuntu.com/community/Grub2/ISOBoot

0

You must log in to answer this question.

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