- 2 easy methods to extend/shrink resize primary partition in Linux
- Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
- Method 1: Change size of partition using parted CLI utility
- List available partitions
- Disable swap partition
- Delete swap and expand partition
- Re-create swap partition
- Method 2: Change size of partition using fdisk utility
- List available partitions
- Delete swap partition
- Part 1 — Resize root partition
- Create swap partition
- Part 2 — Resize root partition
- Related Posts
- Что такое extended partition? И как мне вернуть место?
- Partitioning
- Contents
- Partition table
- Master Boot Record
- Master Boot Record (bootstrap code)
- Master Boot Record (partition table)
- GUID Partition Table
- Choosing between GPT and MBR
- Partitionless disk
- Btrfs partitioning
- Partition scheme
- Single root partition
- Discrete partitions
- Example layouts
- UEFI/GPT layout example
- BIOS/MBR layout example
- BIOS/GPT layout example
- Tools
- Partitioning tools
- fdisk
- GPT fdisk
- GNU Parted
- Backup
- Recovery
- Partition alignment
- GPT kernel support
- Troubleshooting
2 easy methods to extend/shrink resize primary partition in Linux
Table of Contents
Related Searches: How to resize primary partition in Linux. How to extend non lvm root partition. How to change size of partition in Linux using parted and fdisk without destroying data. Steps to expand partition in RHEL/CentOS 7 and 8 Linux. Perform Disk Management in CentOS. How to use unallocated space to change size of partition in a disk in Linux. How to resize root partition not on LVM in Linux. Step by step guide to resize primary partition. How to expand partition with examples in Linux. centos disk management. rhel 7 extend non lvm root partition. centos 7 resize root partition. Steps to resize primary partition to extend non lvm root partition in linux. how to add unallocated disk space to a partition in Linux. centos shrink or extend non lvm root partition. add space to partition. fdisk extend partition. resize boot partition. extend non lvm root partition in linux. change size of partition.how to expand partition. centos resize primary partition. rhel change size of partition.
Earlier I had shared steps to create a file system and check file system type in Linux . Now in this article I will share the steps to resize primary partition, here we will extend non lvm root partition. With LVM it is far more easier and less riskier to change size of partition in an volume group in Linux .
- This article covers steps to resize primary partition (non-lvm) which can be dangerous and can leave your Linux system in an unusable broken state. It is important that you backup your content before you attempt to change size of partition.
- You can change size of partition (non-lvm) only on the last partition on the storage device with unallocated space. If the respective partition is not the last partition then the only way to expand partition is to backup your data , rebuild the disk and partitions, then restore the data. No tool such as gparted, parted or fdisk can help you change size of partition in such case.
- You must have some unallocated space or free space available in the concerned device to be able to expand partition. In some of the virtual environment you have an option to change the storage device size but on physical node if there is no enough unallocated space then resize primary partition (extend non lvm root partition) is not possible
- This article assumes you’re using either a GPT partition table, or an msdos partition table using primary partition types to extend non lvm root partition.
Lab Environment to resize primary partition (RHEL/CentOS 7/8) in Linux
I have performed resize primary partition operation on Virtual Machine running on Oracle VirtualBox installed on Linux server . My VM is running with CentOS 8 but I have also verified these steps on RHEL/CentOS 7 and RHEL 8 Linux.
Here my VM is installed on /dev/sda device where /dev/sda1 is boot partition, /dev/sda2 is root while /dev/sda3 is for swap.. Additionally I have left some unallocated free space in /dev/sda for the demonstration of this article to extend non lvm root partition.
Method 1: Change size of partition using parted CLI utility
You can either use gparted (GUI utility) or parted (CLI utility) to change size of partition in Linux. Here we plan to resize primary partition which in our case is /dev/sda.
List available partitions
To list the available partitions in /dev/sda we will execute below command
As I mentioned in the disclaimer section, you can change size of partition only on the last partition of the device but here root partition ( /dev/sda2 ) is not the last one instead swap ( /dev/sda3 ) is my last partition. So to expand root partition I must delete swap device to be able to to use unallocated space and extend non lvm root partition. After deleting swap, root partition will become the last partition on /dev/sda after which we can resize primary partition.
Disable swap partition
Currently I have around 1GB reserved for swap partition
I will turn off my swap (disable swap partition) and use this space to extend non lvm root partition in Linux
Verify the swap partition space, as you see not it is 0
Update /etc/fstab to make sure swap partition is not mounted at boot up stage.
Delete swap and expand partition
Now to resize primary partition /dev/sda2 and expand partition to a new value we must first delete swap partition using parted utility. As we need root partition to be the last partition of /dev/sda before we expand partition.
But our root partition is showing the same size as earlier i.e.
To complete the steps to resize non lvm root partition, execute resizefs to expand partition and refresh the changes
Re-verify the new size of root partition to make sure our steps to extend non lvm root partition was successful.
Re-create swap partition
Now we must create Swap partition which we deleted earlier in this article. We will again use parted utility to create swap partition
Now with parted we only created a partition with file system type as swap. Use mkswap to turn this partition into swap.
Next we must update /etc/fstab with the UUID of our new swap partition. To get the new UUID of swap partition
Update this UUID in /etc/fstab as shown below
Finally turn on the new swap partition
Verify the new swap partition
Now you can reboot your Linux server to make sure everything is OK and resize primary partition was successful.
Method 2: Change size of partition using fdisk utility
Similar to parted command, you can also use fdisk utility to resize primary partition and extend non lvm root partition.
List available partitions
Before we resize primary partition, let us list the available partitions
Now as you see my existing root partition /dev/sda2 size is
10G . Here we will expand partition with +1GB using unallocated disk space from /dev/sda .
Delete swap partition
Currently my swap partition is enabled and is the last partition of /dev/sda . So we must first delete swap partition here before we change size of partition as we need root to be the last partition in /dev/sda
So we will turn off the swap partition before we disable it
Now it is time to use fdisk utility to resize partition
Part 1 — Resize root partition
We will continue with the steps to extend non lvm root partition in the same fdisk session. Note down the start sector of the root partition before you expand partition.
Create swap partition
After we resize primary partition, in the same fdisk session we will also create a new swap partition which we had deleted initially with new start and end sector
Update the kernel regarding the recent changes we did to change size of partition
But our swap partition is still shown as 0
Now let us complete our steps to create swap partition using mkswap
Next update /etc/fstab with the UUID for your new swap partition. You can use blkid to get the UUID
Update the same in /etc/fstab as shown below
Now you can turn on the swap partition
Verify the same using free command
Part 2 — Resize root partition
If not done already in above steps, once you exit fdisk utility, update the kernel regarding the recent changes we did to change size of partition
We are not done with resize primary partition, as df command still shows old partition size for root partition
Execute resize2fs to expand partition on /dev/sda2 with the new changes
Now you can verify the new size of root partition
Lastly I hope the steps from the article to resize primary partition and extend non lvm root partition on RHEL/CentOS 7/8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
Источник
Что такое extended partition? И как мне вернуть место?
День добрый. Поставил дебиан, и не пойму что у меня с /home происходит.
/home всего 10 гигов, когда как должно быть 100. Никто не знает что происходит и как /home сделать 100 гигов вместо 10?
Extended раздел — это раздел для других разделов, так как из-за ограничений mbr может быть только 4 primary partitions.
Что показывает df -h
Extended Это виртуальный костыль для обхода ограничения в четыре раздела досовой разметки. Те на самом деле у тебя:
Вот что говорит.
У меня файловый менеджер сказал что у меня 10 гигов моих кончается. Это он проглючил получается?
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 97G 2.5G 90G 3% /home
Порядок, хомяк на 97 гигов.
Вы это в каком месте прочитали?
Ну так и монтируй sda5 в /home. 7 лет на лоре, а такие вопросы.
У меня файловый менеджер сказал что у меня 10 гигов моих кончается. Это он проглючил получается?
Судя по всему, что это не про хомяк, а про корень.
Очищайте логи, кэши и т.п.
откуда такой вывод?
fdisk говорит про 97 ГиБ, parted говорит про 106 ГБ (десятичных). Какие основания им не доверять?
Впрочем, может и не помочь.
На современных системах под корень стоит отводить 15-20 гигов.
Так что лучше хомяк сжать, а корень растянуть.
LiveCD/USB + GParted в помощь.
Точно помню что Files в Gnome сказал про /home. Точно это он проглючил.
Так что лучше хомяк сжать, а корень растянуть.
Нахрена их вообще разносить на отдельные разделы, если диск один? Б-ги погромирования дали вам Btrfs с субтомами и мощными квотами, а также проектные квоты в ext4 и XFS для ретроградов. Но нет, мы будем дальше пердолить таблицу msdos из восьмидесятых, а в случае чего перезагружаться и тягать разделы через кривой parted! 🙂
Можно например вынести отдельно /var и тогда 10Гб должно хватить
Да как угодно, лишь бы работало, а там уж ТС сам разберётся.
Но нет, мы будем дальше пердолить таблицу msdos из восьмидесятых, а в случае чего перезагружаться и тягать разделы через кривой parted! 🙂
так учатся планировать . Позже будет разбивка с запасом + свободные разделы (для теста , подмонтировать и тд)
Нахрена их вообще разносить на отдельные разделы, если диск один?
Узнаешь, когда будешь переустанавливать систему.
Тут вообще ни при чём.
А у тебя /dev/sda5 вообще в /home монтируется? Что в /etc/fstab написано?
Нафига психически здоровому человеку btrfs? LVM же специально для этого был сделан.
Зачем, когда есть lvm2? Даже перезагружаться не надо, только выключить графическую оболочку и отмонтировать хомяк на время уменьшения фс, дальнейшая миграция проводится наживую в свободное от остальных дел время.
Источник
Partitioning
Disk partitioning or disk slicing is the creation of one or more regions on secondary storage, so that each region can be managed separately.
An entire disk may be allocated to a single partition, or multiple ones for cases such as dual-booting, maintaining a swap partition, or to logically separate data such as audio and video files. The partitioning scheme is stored in a partition table such as Master Boot Record (MBR) or GUID Partition Table (GPT).
Partition tables are created and modified using one of many partitioning tools. The tools available for Arch Linux are listed in the #Partitioning tools section.
Partitions usually contain a file system directly which is accomplished by creating a file system on (a.k.a. formatting) the partition. Alternatively, partitions can contain LVM, block device encryption or RAID, which ultimately provide device files on which a file system can be placed (or the devices can be stacked further).
Any block device (e.g. disk, partition, LUKS device, LVM logical volume or RAID array) that directly contains a mountable file system is called a volume.
Contents
Partition table
There are two main types of partition table available. These are described below in the #Master Boot Record (MBR) and #GUID Partition Table (GPT) sections along with a discussion on how to choose between the two. A third, less common alternative is using a partitionless disk, which is also discussed.
Use a partitioning tool to view the partition table of a block device.
Master Boot Record
The Master Boot Record (MBR) is the first 512 bytes of a storage device. It contains an operating system bootloader and the storage device’s partition table. It plays an important role in the boot process under BIOS systems. See Wikipedia:Master boot record#Disk partitioning for the MBR structure.
Master Boot Record (bootstrap code)
The first 440 bytes of MBR are the bootstrap code area. On BIOS systems it usually contains the first stage of the boot loader. The bootstrap code can be backed up, restored from backup or erased using dd.
Master Boot Record (partition table)
In the MBR partition table (also known as DOS or MS-DOS partition table) there are 3 types of partitions:
Primary partitions can be bootable and are limited to four partitions per disk or RAID volume. If the MBR partition table requires more than four partitions, then one of the primary partitions needs to be replaced by an extended partition containing logical partitions within it.
Extended partitions can be thought of as containers for logical partitions. A hard disk can contain no more than one extended partition. The extended partition is also counted as a primary partition so if the disk has an extended partition, only three additional primary partitions are possible (i.e. three primary partitions and one extended partition). The number of logical partitions residing in an extended partition is unlimited. A system that dual boots with Windows will require for Windows to reside in a primary partition.
The customary numbering scheme is to create primary partitions sda1 through sda3 followed by an extended partition sda4. The logical partitions on sda4 are numbered sda5, sda6, etc.
GUID Partition Table
GUID Partition Table (GPT) is a partitioning scheme that is part of the Unified Extensible Firmware Interface specification; it uses globally unique identifiers (GUIDs), or UUIDs in the Linux world, to define partitions and partition types. It is designed to succeed the Master Boot Record partitioning scheme method.
At the start of a GUID Partition Table disk there is a protective Master Boot Record (PMBR) to protect against GPT-unaware software. This protective MBR just like an ordinary MBR has a bootstrap code area which can be used for BIOS/GPT booting with boot loaders that support it.
Choosing between GPT and MBR
GUID Partition Table (GPT) is an alternative, contemporary, partitioning style; it is intended to replace the old Master Boot Record (MBR) system. GPT has several advantages over MBR which has quirks dating back to MS-DOS times. With the recent developments to the formatting tools, it is equally easy to get good dependability and performance for GPT or MBR.
Some points to consider when choosing:
- To dual-boot with Windows (both 32-bit and 64-bit) using Legacy BIOS, the MBR scheme is required.
- To dual-boot Windows 64-bit using UEFI mode instead of BIOS, the GPT scheme is required.
- If you are installing on older hardware, especially on old laptops, consider choosing MBR because its BIOS might not support GPT (but see below how to fix it).
- If you are partitioning a disk that is larger than 2 TiB, you need to use GPT.
- It is recommended to always use GPT for UEFI boot, as some UEFI implementations do not support booting to the MBR while in UEFI mode.
- If none of the above apply, choose freely between GPT and MBR. Since GPT is more modern, it is recommended in this case.
Some advantages of GPT over MBR are:
- Provides a unique disk GUID and unique partition GUID (PARTUUID) for each partition — A good filesystem-independent way of referencing partitions and disks.
- Provides a filesystem-independent partition name (PARTLABEL).
- Arbitrary number of partitions — depends on space allocated for the partition table — No need for extended and logical partitions. By default the GPT table contains space for defining 128 partitions. However if you want to define more partitions, you can allocate more space to the partition table (currently only gdisk is known to support this feature).
- Uses 64-bit LBA for storing Sector numbers — maximum addressable disk size is 2 ZiB. MBR is limited to addressing 2 TiB of space per drive.[1]
- Stores a backup header and partition table at the end of the disk that aids in recovery in case the primary ones are damaged.
- CRC32 checksums to detect errors and corruption of the header and partition table.
The section on #Partitioning tools contains a table indicating which tools are available for creating and modifying GPT and MBR tables.
Partitionless disk
This article or section needs expansion.
Partitionless disk a.k.a. superfloppy refers to a storage device without a partition table, having one file system occupying the whole storage device. The boot sector present on a partitionless device is called a volume boot record (VBR).
Btrfs partitioning
Btrfs can occupy an entire data storage device and replace the MBR or GPT partitioning schemes. See the Btrfs#Partitionless Btrfs disk instructions for details.
Partition scheme
This article or section needs expansion.
There are no strict rules for partitioning a hard drive, although one may follow the general guidance given below. A disk partitioning scheme is determined by various issues such as desired flexibility, speed, security, as well as the limitations imposed by available disk space. It is essentially personal preference. If you would like to dual boot Arch Linux and a Windows operating system please see Dual boot with Windows.
Single root partition
This scheme is the simplest and should be enough for most use cases. A swapfile can be created and easily resized as needed. It usually makes sense to start by considering a single / partition and then separate out others based on specific use cases like RAID, encryption, a shared media partition, etc.
Discrete partitions
This article or section needs expansion.
Separating out a path as a partition allows for the choice of a different filesystem and mount options. In some cases like a media partition, they can also be shared between operating systems.
Below are some example layouts that can be used when partitioning, and the following subsections detail a few of the directories which can be placed on their own separate partition and then mounted at mount points under / . See file-hierarchy(7) for a full description of the contents of these directories.
The root directory is the top of the hierarchy, the point where the primary filesystem is mounted and from which all other filesystems stem. All files and directories appear under the root directory / , even if they are stored on different physical devices. The contents of the root filesystem must be adequate to boot, restore, recover, and/or repair the system. Therefore, certain directories under / are not candidates for separate partitions.
The / partition or root partition is necessary and it is the most important. The other partitions can be replaced by it.
/ traditionally contains the /usr directory, which can grow significantly depending upon how much software is installed. 15–20 GiB should be sufficient for most users with modern hard disks. If you plan to store a swap file here, you might need a larger partition size.
The /boot directory contains the kernel and ramdisk images as well as the boot loader configuration file and boot loader stages. It also stores data that is used before the kernel begins executing user-space programs. /boot is not required for normal system operation, but only during boot and kernel upgrades (when regenerating the initial ramdisk).
A suggested size for /boot is 200 MiB unless you are using EFI system partition as /boot , in which case at least 260 MiB is recommended.
The /home directory contains user-specific configuration files, caches, application data and media files.
Separating out /home allows / to be re-partitioned separately, but note that you can still reinstall Arch with /home untouched even if it is not separate—the other top-level directories just need to be removed, and then pacstrap can be run.
You should not share home directories between users on different distributions, because they use incompatible software versions and patches. Instead, consider sharing a media partition or at least using different home directories on the same /home partition. The size of this partition varies.
The /var directory stores variable data such as spool directories and files, administrative and logging data, pacman’s cache, etc. It is used, for example, for caching and logging, and hence frequently read or written. Keeping it in a separate partition avoids running out of disk space due to flunky logs, etc.
It exists to make it possible to mount /usr as read-only. Everything that historically went into /usr that is written to during system operation (as opposed to installation and software maintenance) must reside under /var .
/var will contain, among other data, the pacman cache. Retaining these packages is helpful in case a package upgrade causes instability, requiring a downgrade to an older, archived package. The pacman cache will grow as the system is expanded and updated, but it can be safely cleared if space becomes an issue. 8–12 GiB on a desktop system should be sufficient for /var , depending on how much software will be installed.
One can consider mounting a «data» partition to cover various files to be shared by all users. Using the /home partition for this purpose is fine as well. The size of this partition varies.
A swap is a file or partition that provides disk space used as virtual memory. Swap files and swap partitions are equally performant, but swap files are much easier to resize as needed. A swap partition can potentially be shared between operating systems, but not if hibernation is used.
Historically, the general rule for swap partition size was to allocate twice the amount of physical RAM. As computers have gained ever larger memory capacities, this rule is outdated. For example, on average desktop machines with up to 512 MiB RAM, the 2× rule is usually adequate; if a sufficient amount of RAM (more than 1024 MiB) is available, it may be possible to have a smaller swap partition.
To use hibernation (a.k.a suspend to disk) it is advised to create the swap partition at the size of RAM. Although the kernel will try to compress the suspend-to-disk image to fit the swap space there is no guarantee it will succeed if the used swap space is significantly smaller than RAM. See Power management/Suspend and hibernate#Hibernation for more information.
Example layouts
This article or section needs expansion.
The following examples use /dev/sda as the example disk with /dev/sda1 as the first partition. The block device naming scheme will differ if you are partitioning a NVMe disk (e.g. /dev/nvme0n1 with partitions starting from /dev/nvme0n1p1 ) or an SD card or eMMC disk (e.g. /dev/mmcblk0 with partitions starting from /dev/mmcblk0p1 ). See Device file#Block device names for more information.
UEFI/GPT layout example
Mount point on the installed system | Partition | Partition type GUID | Partition attributes | Suggested size |
---|---|---|---|---|
/boot or /efi 1 | /dev/sda1 | C12A7328-F81F-11D2-BA4B-00A0C93EC93B : EFI system partition | At least 260 MiB | |
[SWAP] | /dev/sda2 | 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F : Linux swap | More than 512 MiB | |
/ | /dev/sda3 | 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 : Linux x86-64 root (/) | Remainder of the device |
BIOS/MBR layout example
Mount point on the installed system | Partition | Partition type ID | Boot flag | Suggested size |
---|---|---|---|---|
[SWAP] | /dev/sda1 | 82 : Linux swap | No | More than 512 MiB |
/ | /dev/sda2 | 83 : Linux | Yes | Remainder of the device |
N/A | Unallocated space 2 | N/A | N/A | At least 16.5 KiB at the end of the disk |
BIOS/GPT layout example
Mount point on the installed system | Partition | Partition type GUID | Partition attributes | Suggested size |
---|---|---|---|---|
None | /dev/sda1 | 21686148-6449-6E6F-744E-656564454649 : BIOS boot partition 3 | 1 MiB | |
[SWAP] | /dev/sda2 | 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F : Linux swap | More than 512 MiB | |
/ | /dev/sda3 | 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 : Linux x86-64 root (/) | Remainder of the device |
- The ESP can be mounted to /efi if the used boot loader is capable of accessing the file system (and everything above it) on which the kernel and initramfs images are located. See EFI system partition#Typical mount points and the warning in Arch boot process#Boot loader for details.
- An unpartitioned space of at least 33 512-byte sectors (16.5 KiB) at the end of the disk to allow converting to GPT in the future. The space will be required for the backup GPT header. The recommendation to preserve an unpartitioned space applies to all MBR partitioned disks.
- A BIOS boot partition is only required when using GRUB for BIOS booting from a GPT disk. The partition has nothing to do with /boot , and it must not be formatted with a file system or mounted.
Tools
Partitioning tools
The following programs are used to create and/or manipulate device partition tables and partitions. See the linked articles for the exact commands to be used.
This table will help you to choose utility for your needs:
MBR | GPT | |
---|---|---|
Dialog | fdisk parted | fdisk gdisk parted |
Pseudo-graphics | cfdisk | cfdisk cgdisk |
Non-interactive | sfdisk parted | sfdisk sgdisk parted |
Graphical | GParted gnome-disk-utility partitionmanager | GParted gnome-disk-utility partitionmanager |
fdisk
fdisk and its related utilities are described in the fdisk article.
- fdisk ( util-linux )
- fdisk(8) – Dialog-driven program for creation and manipulation of partition tables.
- cfdisk(8) – Curses-based variant of fdisk.
- sfdisk(8) – Scriptable variant of fdisk.
GPT fdisk
gdisk and its related utilities are described in the gdisk article.
GNU Parted
These group of tools are described in the GNU Parted article.
Backup
- fdisk can create a backup of the partitions table. See fdisk#Backup and restore partition table.
- GPT fdisk can create a binary backup consisting of the protective MBR, the main GPT header, the backup GPT header, and one copy of the partition table. See GPT fdisk#Backup and restore partition table.
Recovery
- gpart — A utility that guesses the contents of a destroyed MBR partition table. Its usage is explained in the gpart(8) man page.
https://github.com/baruch/gpart || gpart
- GPT fdisk — A partitioning tool that can restore the primary GPT header (located at the start of the disk) from the secondary GPT header (located at the end of the disk) or vice versa.
https://www.rodsbooks.com/gdisk/ || gptfdisk
- TestDisk — A utility that supports recovering lost partitions on both MBR and GPT.
https://www.cgsecurity.org/index.html?testdisk.html || testdisk
Partition alignment
fdisk, gdisk and parted handle alignment automatically. See GNU Parted#Check alignment if you want to verify your alignment after partitioning.
For certain drives Advanced Format might be able to provide a better-performing alignment.
GPT kernel support
The CONFIG_EFI_PARTITION option in the kernel config enables GPT support in the kernel (despite the name, EFI PARTITION). This option must be built in the kernel and not compiled as a loadable module. This option is required even if GPT disks are used only for data storage and not for booting. This option is enabled by default in all Arch’s officially supported kernels. In case of a custom kernel, enable this option by doing CONFIG_EFI_PARTITION=y .
Troubleshooting
This article or section needs expansion.
Источник