4

I have Linux Debian on the partition sda4 of my 1TB hard disk:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0   260M  0 part /boot/efi
├─sda2   8:2    0    16M  0 part 
├─sda3   8:3    0 530.7G  0 part 
├─sda4   8:4    0 135.5G  0 part /
├─sda5   8:5    0   977M  0 part [SWAP]
├─sda6   8:6    0   973M  0 part 
└─sda7   8:7    0  14.3G  0 part 
sr0     11:0    1  1024M  0 rom

Between sda3 and sda4 there is some space (exactly, 267 GB of unallocated space) that I took from windows (sda3) to extend the Linux partition. So, this space is on the left of sda4 and I want to give this it to the Linux partition, sda4.

Using GParted this is complicated to do, unless someone could explain it easily. I'd want to use fdsik, if possible, so to modify the partition size from the partition itself.

Many thanks in advance to all.

5
  • which file system? Jul 20, 2021 at 9:39
  • Whatever you do, I'd recommend to make a backup of the entire disk first. This has been gone wrong so many times and then users ask how to recover data.
    – eblock
    Jul 20, 2021 at 9:44
  • @MarcusMüller I don't understand your question Jul 20, 2021 at 9:56
  • @AvlesEdivad what is the file system on your / ? Jul 20, 2021 at 10:22
  • @MarcusMüller It's an Ext4 with Linux Debian GNU/Linux 10 (buster) Jul 20, 2021 at 11:37

2 Answers 2

4

You generally can't extend the filesystem on the partitions to the left, so the general procedure is to move the data to the left (which means copying it over chunk-wise). That's a rather annoying thing, as you have to do it offline: at some point you'll start overwriting the data at the beginning of your old partition.

things like gparted can do that for you, so if you have a live disk, that's certainly easy.

Now, the situation gets a lot easier if your free space is larger than your old partition. You can just copy over the whole contents of the old partition, then delete the old partition, extend the new partition to the right, and be done with it.

So, boot a live medium, use gparted to resize to left, and wait, be done.


exception:

If you have ZFS or BTRFS as file system on your root partition, this might be a lot easier, since you could simply add the new partition to the storage pools of these. Same for LVM. Generally, it's a bit last-decade to have an installation where you're neither using LVM or one BTRFS for storage: you almost always regret it later, and it's never a problem.

5
  • Thanks a lot, I'll try this method later on. So even with fdisk this can't be done? Jul 20, 2021 at 11:40
  • I hope this is GPT! Then fdisk is not very useful. But if you change the partition table manually, you need to do the data moving described above manually, using dd. I do not recommend – you can only make mistakes. Jul 20, 2021 at 12:16
  • Ok. I have another question: when changing the position of my Linux, does the boot is affected? I mean, do I have to change the address to the Linux position on the hard disk or is it done automatically? Jul 20, 2021 at 13:10
  • If your system uses a native UEFI-style boot (as would be suggested by the presence of /boot/efi), then it should not be affected unless you are running an obsolete version of Debian with a very early version of UEFI bootloader and its configuration, or have a custom boot configuration instead of one created by update-grub. Currently supported versions of Debian configure UEFI bootloader to find the filesystems using their UUIDs, independent of physical location.
    – telcoM
    Jul 20, 2021 at 13:19
  • It worked indeed. Thanks Jul 20, 2021 at 15:19
1

Boot from a "live" Linux DVD/USB and run gparted

A full backup is recommended prior to the partition adjustment.

This may take a considerable time to run.

You must log in to answer this question.

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