Extend the root partition (ext4, not LVM) of a disk in Debian

The root partition is the repository for all other file systems. Through it, the system gains access to many (if not all) of its resources. This section (file system) contains such important system directories (which can be placed in separate sections if desired and be separate file systems) as “/ usr”, “/ bin”, “/ etc”, “/ var”, “ / opt “, etc., collectively they all contain kernel files, standard system utilities, stored system configuration files, system event log files, etc.

There is a virtual machine, the disk partition is as follows:

$ lsblk
$ df -H
$ sudo cfdisk /dev/sda

Turn off the virtual machine, increase the size of the vdi disk using VBoxManage (included in VirtualBox):

"C:Program FilesOracleVirtualBoxVBoxManage.exe" modifyhd "C:UsersuserVirtualBox VMsdebian8debian8.vdi" --resize 12288

Turn on the virtual machine, see what happened

$ lsblk
$ df -H
$ sudo cfdisk /dev/sda

Turn off swap (swap file)

$ sudo swapoff -a

We start deleting partitions (data will not be lost)

We look at the markup

$ sudo fdisk /dev/sda

Command (m for help): p
Disk /dev/sda: 12 GiB, 12821987328 bytes, 25042944 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd00b3928

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 15988735 15986688  7.6G 83 Linux
/dev/sda2       15990782 16775167   784386  383M  5 Extended
/dev/sda5       15990784 16775167   784384  383M 82 Linux swap / Solaris

In this example, first delete / dev / sda2

Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

See the result

Command (m for help): p
Disk /dev/sda: 12 GiB, 12821987328 bytes, 25042944 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd00b3928

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1  *     2048 15988735 15986688  7.6G 83 Linux

Delete the / dev / sda1 partition (no data will be lost)

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Thus, we have removed the partitions on the disk. This method is used because with automatic disk partitioning in Debian (without LVM), the root partition is at the beginning of the disk, and the added space is at the end of the disk. And between them is the area allocated for swap.

Create a new section (primary)

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-25042943, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-25042943, default 25042943): +11G

Created a new partition 1 of type 'Linux' and of size 11 GiB.

Thus, we created a new 11 Gb partition, left 1 Gb for swap

Create (extended) partition under swap

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2):
First sector (23070720-25042943, default 23070720):
Last sector, +sectors or +size{K,M,G,T,P} (23070720-25042943, default 25042943):

Created a new partition 2 of type 'Extended' and of size 963 MiB.

Let’s try to change the file system type

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82
You cannot change a partition into an extended one or vice versa. Delete it first.

Type of partition 2 is unchanged: Extended.

The utility swears

Save changes

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

The utility reports that the changes will be applied after reboot

Reboot the virtual machine

$ sudo reboot

See the result

$ lsblk
$ df -H
$ sudo cfdisk /dev/sda

Run the cfdisk utility

$ sudo cfdisk /dev/sda

Select / dev / sda1:

Bootable

Selecting the unallocated area:

New - > Partition size: 962M -> Type: 82

Extend the root partition (ext4, not LVM) of a disk in Debian 8

Save changes

Write: yes - > Quit

Extend the root partition (ext4, not LVM) of a disk in Debian 9

We transmit information about changing the markup to the operating system by installing the parted utility

$ sudo apt install parted -y
$ sudo partprobe

Create a partition for swap

$ sudo mkswap /dev/sda5
Setting up swapspace version 1, size = 985084 KiB
no label, UUID=be9028ea-7dd0-445b-99ae-69835d586ed5

Turn on swap

$ sudo swapon /dev/sda5

See new UUIDs

$ sudo blkid
/dev/sda1: UUID="c86485d2-6505-426e-9298-48eb1462be89" TYPE="ext4" PARTUUID="d00b3928-01"
/dev/sda5: UUID="be9028ea-7dd0-445b-99ae-69835d586ed5" TYPE="swap" PARTUUID="d00b3928-05"

We register them in / etc / fstab

$ sudo nano /etc/fstab

We mount

$ sudo mount -a

Reboot the virtual machine

$ sudo reboot

Checking

$ lsblk
$ df -h

Extend the root partition (ext4, not LVM) of a disk in Debian 10

Extending the / dev / sda1 partition

$ sudo resize2fs /dev/sda1

Checking

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        11G  1.2G  9.1G  12% /
udev             10M     0   10M   0% /dev
tmpfs           403M  5.5M  397M   2% /run
tmpfs          1006M     0 1006M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs          1006M     0 1006M   0% /sys/fs/cgroup

Thus, we expanded the root partition of a running Debian operating system without resorting to the LiveCD.

Related Posts