Content on this page was generated by AI and has not been manually reviewed.
This page includes AI-assisted insights. Want to be sure? Fact-check the details yourself using one of these tools:

How to repartition disk in ubuntu server a comprehensive guide 2026

VPN

How to repartition disk in ubuntu server a comprehensive guide: a concise overview first helps you decide if repartitioning is right for you, followed by practical steps, safety tips, and common gotchas. Quick fact: repartitioning can erase data, so always back up before making changes. This guide covers everything from pre-checks to live-repartition methods, with real-world tips and troubleshooting.

  • Quick-start checklist
  • Step-by-step partitioning workflow
  • Advanced scenarios LVM, encryption, RAID
  • Common pitfalls and how to avoid them
  • Resources and backups

How to repartition disk in ubuntu server a comprehensive guide. This guide is designed to be a practical, no-nonsense resource for sysadmins and enthusiasts who need to adjust disk layouts on Ubuntu Server. Whether you’re resizing an existing partition, creating new ones for data, or converting to LVM, this post walks you through it with clear steps, multiple approaches, and safety notes.

Key takeaways:

  • Know your current disk layout before touching anything
  • Choose a partitioning tool that matches your setup gdisk, fdisk, parted, or the graphical tool if you’re on a GUI-less server
  • Back up important data, and plan a rollback in case something goes wrong
  • For servers with critical workloads, consider non-destructive methods like LVM or virtual disk expansion

In this guide, you’ll find:

  • Preconditions and safety tips
  • How to inspect disks and partitions
  • How to repartition with and without data loss
  • How to resize, create, delete, or modify partitions
  • Special cases: LVM, encryption, and RAID
  • Troubleshooting steps
  • Useful commands and real-world examples
  • Useful URLs and resources unlinked in text: Apple Website – apple.com, Artificial Intelligence Wikipedia – en.wikipedia.org/wiki/Artificial_intelligence, Ubuntu Official Documentation – help.ubuntu.com, Debian Manual – man.debian.org

Preconditions and safety tips

  • Always back up your data. A failed repartition can lead to data loss.
  • Confirm the boot mode BIOS/Legacy vs UEFI because it can influence partitioning schemes and bootloaders.
  • Identify whether the disk uses MBR or GPT. GPT is common on modern systems and supports more partitions.
  • If the server is remote, ensure you have out-of-band access or a recovery plan in case the network drops during the operation.
  • Plan for downtime if you’re resizing root or boot partitions.

How to inspect disks and partitions

  • List all disks and their sizes
    • Command: lsblk -f
    • What you’ll see: device names sda, sdb, partitions sda1, sda2, filesystem types, and mount points.
  • Check partition table type
    • Command: lsblk -o NAME,PTTYPE,SIZE,MOUNTPOINT
    • If PTTYPE shows gpt or dos, you’ll know the layout.
  • See detailed partition info
    • Command: sudo fdisk -l /dev/sda or sudo gdisk -l /dev/sda
  • Verify mounted filesystems and usage
    • Command: df -hT
  • Back up critical config and boot entries
    • For UEFI systems, ensure the EFI partition is intact before making changes.

Common partitioning scenarios

  • Resize a non-root partition data partition
  • Repartition a drive that’s entirely unused
  • Add a new partition for data, databases, or backups
  • Convert to LVM for flexible resizing
  • Encrypt a data partition for security

Non-destructive options safe-first

  • Use LVM to resize logical volumes without touching the underlying physical volumes too aggressively
  • Extend an existing data partition by resizing the filesystem first, then the partition
  • Create additional partitions for data without touching root or boot

Step-by-step: repartitioning with minimal risk
Warning: these steps assume a data partition is being resized or a new partition is created on an unused portion of the disk. Replace /dev/sdx and partition numbers with your target device and numbers.

  1. Back up data and plan
  • Snapshot or copy critical data
  • Document current partition table: sudo parted /dev/sdx print
  • Decide on target layout e.g., resize sdx3 from 100GB to 150GB, create sdx4 as data
  1. Unmount relevant partitions
  • If the partition is in use, unmount it: sudo umount /dev/sdx3
  • For root or boot, you’ll need live media or a rescue environment to perform changes
  1. Resize or delete a partition non-root data example
  • If resizing a data partition, use:
    • Command: sudo growpart /dev/sdx 3 from cloud-utils-growpart
    • Then resize the filesystem:
      • ext4: sudo resize2fs /dev/sdx3
      • xfs: sudo xfs_growfs /mount/point
  • If shrinking a partition:
    • Unmount, run filesystem check, then resize:
      • ext4: sudo e2fsck -f /dev/sdx3
      • sudo resize2fs /dev/sdx3 150G
    • Then shrink partition to match the new filesystem size with parted or fdisk:
      • sudo parted /dev/sdx
      • parted resizepart 3 150GB
      • parted quit
  1. Create a new partition
  • Use parted or fdisk to create a new partition in the free space:
    • Command: sudo parted /dev/sdx
    • parted mkpart primary ext4 150GB 200GB
    • parted set 4 lvm on # if you plan to use LVM later
    • parted quit
  • Create a filesystem on the new partition:
    • ext4: sudo mkfs.ext4 /dev/sdx4
    • xfs: sudo mkfs.xfs /dev/sdx4
  • Mount the new partition if needed and update /etc/fstab
  1. Update fstab and mount
  • Get UUID for the new partition: sudo blkid /dev/sdx4
  • Add to /etc/fstab with the appropriate mount point and options
  • Mount: sudo mount -a
  • Verify: df -h

Advanced: using LVM for flexible resizing

  • Convert existing partition to a physical volume PV
    • Command: sudo pvcreate /dev/sdx3
  • Create an volume group VG
    • Command: sudo vgcreate vg_data /dev/sdx3
  • Create a logical volume LV
    • Command: sudo lvcreate -L 100G -n data_lv vg_data
  • Create filesystem on LV
    • ext4: sudo mkfs.ext4 /dev/vg_data/data_lv
  • Mount LV and update fstab
  • To resize later:
    • Grow LV: sudo lvresize -L +50G /dev/vg_data/data_lv
    • Resize filesystem: sudo resize2fs /dev/vg_data/data_lv

Advanced: encryption and data security

  • For encryption with LUKS:
    • Create a new partition: /dev/sdx4
    • Initialize: sudo cryptsetup luksFormat /dev/sdx4
    • Open: sudo cryptsetup open /dev/sdx4 cryptdata
    • Create filesystem on /dev/mapper/cryptdata
    • Mount and update /etc/crypttab and /etc/fstab
  • Important: ensure you have the passphrase and backup keys stored securely

Special cases: boot and root partitions

  • Resizing root partition is high-risk; use a live USB or rescue mode
  • Consider moving root to a more flexible setup LVM or adding a separate boot partition
  • Always have a recovery plan in case the bootloader needs reinstallation

RAID considerations

  • If you’re using software RAID mdadm, resizing may require stopping arrays and rebuilding
  • Always consult your RAID configuration before changing partitions
  • Maintain backup and test changes in a staging environment if possible

Filesystem-specific notes

  • ext4
    • Common and reliable; supports online resizing with resize2fs
  • xfs
    • Generally supports online growth xfs_growfs but requires unmount if shrinking
  • btrfs
    • Flexible, supports online resizing, but ensure kernel support and backup before major changes

Data verification and sanity checks

  • After resizing or creating partitions, verify filesystem integrity:
    • ext4: sudo e2fsck -f /dev/sdx3
    • xfs: sudo xfs_repair /dev/sdx3
  • Confirm mount points and usage:
    • df -hT
    • lsblk -f
  • Check boot functionality if root/boot was altered:
    • Reboot into a rescue environment to test boot

Common pitfalls and how to avoid them

  • Pitfall: Data loss due to resizing the wrong partition
    • Avoid by double-checking partition numbers and device names; back up first
  • Pitfall: Mismatch between partition type and filesystem
    • Ensure you format the partition with the correct filesystem type
  • Pitfall: Boot failure after partition changes
    • Keep a live USB ready; update bootloader if necessary; verify EFI/boot files
  • Pitfall: Online resizing limits
    • Some filesystems support online resizing only up to a certain limit; plan accordingly

Performance considerations

  • Align partitions to 1MiB boundaries for optimal performance
  • Use modern filesystems ext4, xfs, or btrfs based on use case and kernel support
  • For databases or workloads with heavy I/O, consider separating data onto separate disks or LVGs

Troubleshooting steps

  • If a partition isn’t visible, rescan disks:
    • Command: sudo partprobe /dev/sdx
  • If the system won’t boot after changes:
    • Boot from live USB, chroot, and reinstall grub
    • Check /boot/efi if on UEFI systems
  • If a filesystem won’t resize:
    • Ensure unmounted state or run from a live environment
    • Run filesystem check and correct any errors first

Best practices and tips

  • Always have recent backups and a tested recovery plan
  • Document every change you make
  • Work in a maintenance window for production servers
  • Consider non-destructive options first LVM, adding new partitions before resizing root
  • Use automation appropriately to replicate steps on multiple servers

Tools and commands recap

  • Disk and partition inspection:
    • lsblk -f
    • fdisk -l /dev/sdx
    • lsblk -o NAME,PTTYPE,SIZE,MOUNTPOINT
  • Partition management:
    • fdisk / parted / gdisk depending on GPT/MBR
    • sudo growpart /dev/sdx N
    • sudo parted /dev/sdx
  • Filesystem operations:
    • sudo mkfs.ext4 /dev/sdxN
    • sudo resize2fs /dev/sdxN
    • sudo xfs_growfs /mount/point
    • sudo e2fsck -f /dev/sdxN
    • sudo xfs_repair /dev/sdxN
  • LVM:
    • sudo pvcreate /dev/sdxN
    • sudo vgcreate vgname /dev/sdxN
    • sudo lvcreate -L 100G -n lvname vgname
    • sudo resize2fs /dev/vgname/lvname
  • Encryption:
    • sudo cryptsetup luksFormat /dev/sdxN
    • sudo cryptsetup open /dev/sdxN cryptname
  • Mount and fstab:
    • sudo blkid /dev/sdxN
    • sudo nano /etc/fstab
    • sudo mount -a

Frequently Asked Questions

Table of Contents

How do I know if I should repartition my Ubuntu server?

Repartitioning is typically needed when you’re running out of space on a partition, adding new drives, or restructuring for performance. If you’re introducing a data-heavy service or need more flexible growth, consider LVM first to minimize downtime.

Is it safe to repartition a live server?

Non-destructive options exist, but any partition change carries risk. If possible, perform changes in a maintenance window or within a rescue environment. Always back up before starting.

What tools should I use to repartition on Ubuntu Server?

Common choices are fdisk or gdisk for MBR/GPT schemes, parted for scripting, and cloud-utils-growpart if working with cloud images. For resizing, use resize2fs ext4 or xfs_growfs XFS.

Can I repartition the boot or root partition without downtime?

Yes, but it’s high risk. Use a live USB or rescue environment to modify the root/boot partitions, and ensure you have a robust recovery plan and bootloader repair steps.

How do I resize a filesystem without losing data?

Unmount the partition if possible, run a filesystem check, resize the filesystem first, then shrink or expand the partition to match. For root partitions, use a live environment.

How can I migrate to LVM on an existing Ubuntu server?

Create a new PV from free space, extend or move data to a new LV, and gradually migrate services. LVM provides flexible resizing with minimal downtime.

What happens if I forget to back up?

You risk permanent data loss. If you realize you’re at risk, stop and back up immediately before attempting changes.

How do I verify that the repartitioning worked?

Check the partition table again with lsblk or parted, verify filesystem integrity with fsck, and confirm mount points with df -h.

How do I recover if the system won’t boot after changes?

Use a live USB, chroot into the installed system, reinstall grub if needed, and verify the boot partition and EFI entries. Restore data from backup if necessary.

Are there any performance tips after repartitioning?

Keep partitions aligned, use fast disks where possible, and separate workloads onto dedicated partitions or LVGs. For databases, consider dedicated storage or RAID configurations with redundancy.

Useful URLs and Resources

  • Apple Website – apple.com
  • Artificial Intelligence Wikipedia – en.wikipedia.org/wiki/Artificial_intelligence
  • Ubuntu Official Documentation – help.ubuntu.com
  • Debian Manual – man.debian.org
  • Linux Foundation – linuxfoundation.org
  • Reddit r/linuxadmin – reddit.com/r/linuxadmin
  • Stack Exchange Server Fault – serverfault.com

How to Repartition Disk in Ubuntu Server A Comprehensive Guide: Manage Partitions, Resize, and Optimize Storage Efficiently

How to repartition disk in ubuntu server a comprehensive guide — Quick fact: Repartitioning is about reshuffling your disk’s partitions to better fit your needs, but it can risk data if done incorrectly. This guide walks you through safe, practical steps to repartition disks on Ubuntu Server, with real-world tips and checks to minimize downtime and data loss.

Introduction: a quick summary of what you’ll learn

  • Repartitioning concepts explained in plain language
  • How to prepare, backup, and plan without freaking out your data
  • Step-by-step methods for both live and offline repartitioning
  • Common scenarios: adding space, resizing, converting between partition types, and replacing disks
  • Verification and post-change checks to ensure your server stays healthy
  • Handy commands, references, and best practices

Quick facts:

  • Most servers use LVM Logical Volume Manager to make resizing partitions easier
  • Always back up important data before messing with partitions
  • Live repartitioning is riskier but possible with careful steps and proper tools

Useful URLs and Resources text, not clickable:

  • Ubuntu Documentation – ubuntu.com
  • LVM System Administration – wiki.archlinux.org
  • GNU Parted Manual – gparted.org
  • Red Hat Storage Administrator Guide – access.redhat.com
  • Debian Partition Tools – debian.org
  • Stack Exchange Server Fault – serverfault.com
  • Wikipedia: Disk Partitioning – en.wikipedia.org/wiki/Disk_partitioning
  • Linux Kernel Documentation – kernel.org
  • Ubuntu Community Help Wiki – help.ubuntu.com
  • TechNet Storage Concepts – docs.microsoft.com

Understanding partitioning basics

  • Partitions vs. volumes: A partition is a slice of a disk; a volume is what the OS sees and uses.
  • Primary, extended, and logical: Traditional MBR Master Boot Record has up to four primary partitions, with one extended containing logical partitions. GPT GUID Partition Table allows many partitions and is recommended for modern systems.
  • Filesystems: ext4, XFS, Btrfs, and others have different features. Ubuntu Server commonly uses ext4 or XFS.
  • LVM Logical Volume Manager: Abstracts partitions into physical volumes PVs, volume groups VGs, and logical volumes LVs, making resizing easier.

Why you might repartition

  • Add space to /home or /var without reinstalling
  • Create new partitions for databases, backups, or containers
  • Swap management improvements
  • Convert from non-LVM to LVM or vice versa more complex

Common risks

  • Data loss if you delete or resize wrong partitions
  • Boot issues if you modify the EFI/boot partition
  • System downtime during resizing, especially on active servers

Preparation: backups, planning, and tools

Before you touch disks:

  • Take a full backup of critical data
  • Document current partition layout with: lsblk, fdisk -l, df -h, pvs, vgs, lvs
  • Confirm whether the disk is using MBR or GPT: sudo parted -v will show GPT if present
  • Decide offline vs. online live repartitioning needs
  • Have a live USB or rescue mode ready in case you need to repair bootloaders

Recommended tools:

  • lsblk, blkid, df, du for quick checks
  • fdisk MBR or gdisk GPT for partition editing
  • parted for scripting and resizing with a safer flow
  • pvdisplay, vgdisplay, lvdisplay for LVM
  • resize2fs for ext4, xfs_growfs for XFS
  • crash cart approach: keep recovery media handy and test boot

Step-by-step: repartitioning with minimum downtime

Note: Tailor to your system; on production servers, perform changes during maintenance windows.

Step 1: Identify the target partitions

  • Run: lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT
  • Note the partition you want to resize or convert, and identify any LVM volumes if present.

Step 2: Backup and snapshot if possible

  • Create a full disk image or feature-enabled snapshot, if your storage supports it.
  • If using virtualization, take a VM snapshot.

Step 3: If resizing an existing partition on non-LVM

  • For ext4:
    • Unmount the partition if possible: umount /data
    • Check filesystem: e2fsck -f /dev/sdXn
    • Resize filesystem first: resize2fs /dev/sdXn NEW_SIZE
    • Resize partition: use parted or fdisk to resize the partition to match the new end sector
    • Remount and verify: mount /data; df -h
  • For XFS:
    • XFS supports online growing but not shrinking: xfs_growfs /mountpoint -D NEW_SIZE
    • To shrink, you must copy data off, recreate partition, then copy back

Step 4: If you need to shrink a filesystem to fit a smaller partition

  • For ext4:
    • Unmount, run e2fsck -f /dev/sdXn
    • Resize filesystem to the target smaller size: resize2fs /dev/sdXn NEW_SIZE
    • Then shrink the partition using parted or fdisk
  • Important: Shrinking can lead to data loss if miscalculated. Always have backups.

Step 5: If you’re using LVM

  • Benefits: Easier to resize logical volumes without touching the underlying PVs too much
  • Steps:
    • Extend PV: pvresize /dev/sdX
    • Create or extend a VG: vgcreate or vgextend as needed
    • Resize LV: lvresize -L +SIZE /dev/mapper/vg-name-lv-name
    • Grow filesystem: resize2fs /dev/mapper/vg-name-lv-name ext4 or xfs_growfs /mountpoint XFS
    • Verify with df -h and lsblk

Step 6: Replacing a disk

  • If you’re replacing a failed disk, plan for RAID or rely on LVM/VG replication
  • Steps:
    • Mark the old disk as failed in RAID array or remove from PV
    • Add new disk, partition, and pvresize
    • Extend VG and LV accordingly
    • Grow filesystem to utilize new space

Step 7: Boot and EFI considerations

  • If you touch the boot partition, you might need to reinstall GRUB
  • For UEFI systems, ensure the EFI System Partition ESP remains intact
  • After changes, run update-grub and ensure boot entries point to the right root partition

Step 8: Post-change checks

  • Reboot if necessary and monitor logs: journalctl -xe
  • Verify all mounts: df -h
  • Check service health: systemctl status
  • Run disk health checks: smartctl -a /dev/sdX if you have SMART available
  • Ensure backups succeeded after changes

Example scenarios: practical walkthroughs

Scenario A: Expanding a data partition on a non-LVM Ubuntu Server

  • Situation: /data is ext4 on /dev/sdb3, 100G used 60G
  • Action:
    • Unmount /data
    • Resize the partition to 200G using parted
    • Resize filesystem: resize2fs /dev/sdb3
    • Remount and verify: df -h
  • Result: +100G free space available to /data

Scenario B: Shrinking a log partition to reclaim space for LVM

  • Situation: /var/log on ext4 /dev/sdc2, 50G, 10G used for logs
  • Action:
    • Unmount /var/log
    • Check and shrink filesystem to 8G
    • Shrink partition to 8G
    • Re-mount and ensure logs still write
  • Result: freed 2G for other partitions

Scenario C: Moving from non-LVM to LVM without data loss

  • Situation: Root is non-LVM, want LVM to grow
  • Action:
    • Create a new PV on an additional disk or free space
    • Create a new VG and LV
    • Copy data from the old root to the new LV rsync -aAX / /mnt/newroot
    • Update /etc/fstab and bootloader as needed
    • Reboot to ensure root comes from the new LV
  • Result: Flexible resizing in future

Scenario D: Repartitioning with RAID

  • If you’re using mdadm RAID, reshaping partitions usually means starting with backing up, then:
    • Add a new disk to the array, rebuild
    • Once synchronized, reduce or resize the array and partitions
  • Note: RAID reconfiguration can be risky; test in a non-production environment first

Best practices and optimization tips

  • Use GPT on modern systems to avoid MBR limitations
  • Prefer LVM if you anticipate changing disk space needs
  • Keep a bootable rescue disk handy in case you break the bootloader
  • Document every change with exact commands and outcomes
  • Schedule maintenance windows for production servers to minimize impact
  • Monitor SMART attributes after changes to catch early signs of drive problems
  • Don’t shrink partitions containing data unless absolutely necessary and you have verified backups

Tables: quick reference commands

  • Disk and partition overview
    • lsblk -o NAME,FSTYPE,SIZE,TYPE,MOUNTPOINT
    • blkid
    • df -h
  • Partition manipulation GPT
    • sudo parted /dev/sdX resizepart N END
    • sudo parted -l
  • Filesystem checks and resize
    • ext4: sudo e2fsck -f /dev/sdXN; sudo resize2fs /dev/sdXN NEW_SIZE
    • XFS: sudo xfs_growfs /mountpoint -D NEW_SIZE
  • LVM management
    • sudo pvresize /dev/sdX
    • sudo vgdisplay
    • sudo lvdisplay
    • sudo lvresize -L +SIZE /dev/mapper/vg-name-lv-name
    • sudo resize2fs /dev/mapper/vg-name-lv-name or sudo xfs_growfs /mountpoint
  • Boot and recovery
    • sudo update-grub
    • sudo grub-install

Real-world considerations and data points

  • In large environments, resizing operations are often planned around low-traffic hours to minimize impact.
  • LVM reduces downtime risk because you can resize logical volumes without rebooting in many cases.
  • GPT schemes avoid the 2TB limit and number of partitions constraints that MBR imposes, which is helpful for modern Ubuntu Server deployments.

Frequently Asked Questions

What is the safest way to repartition a disk in Ubuntu Server?

The safest way is to back up first, map out the current layout, and prefer operations on available free space or non-critical partitions. When possible, use LVM to resize without touching the root filesystem. Perform changes during a maintenance window and verify everything thoroughly afterward.

Can I repartition while the system is online?

Yes, but it carries higher risk. Prefer online resizing only for non-critical partitions or using LVM. For root or boot partitions, offline changes or live-boot methods are safer. Creating a nice discord server a step by step guide to setup, roles, moderation, and growth 2026

Do I need to back up before repartitioning?

Absolutely. Repartitioning can lead to data loss if something goes wrong. Back up important data and consider disk-level or VM snapshots.

How do I resize a partition without losing data?

Unmount the partition if possible, check the filesystem for errors, then resize the filesystem first, followed by resizing the partition. Always have a verified backup before starting.

What tools should I use for GPT disks?

GPT disks are best managed with GNU Parted, gdisk, or fdisk with GPT support. GPT is recommended for new servers.

How does LVM help with repartitioning?

LVM abstracts physical disks into volumes, letting you grow or shrink logical volumes without moving data around as much. It makes future changes safer and easier.

What’s the difference between resizing and shrinking?

Resizing expands or contracts the boundary of a partition or filesystem within safe limits. Shrinking a partition means reducing its size, which can be risky if data is near the boundary. How to setup a discord server the ultimate guide: Create, Configure, and Grow Your Community with Confidence 2026

Can I repartition a live system’s disk?

Yes, for certain partitions and with caution. Use online resize with LVM or carefully use tools like parted for non-root partitions. Always have a recovery plan.

How do I handle bootloader after repartitioning?

If you touch the boot partition, you may need to reinstall or repair GRUB. Boot from a live USB, chroot into the system, and run grub-install and update-grub.

What are signs that repartitioning went wrong?

Boot failures, missing files, corrupted filesystem, systemd errors, or services failing to start. If you see issues, boot into recovery, restore backups, and review logs.

How to repartition disk in ubuntu server a comprehensive guide to disk partitioning, resizing, LVM, and filesystem management

Yes, here’s a comprehensive guide to repartitioning a disk on Ubuntu Server. In this post you’ll find a practical, step-by-step plan for planning, backing up, resizing and creating partitions, and using LVM when appropriate. You’ll also get real-world tips, common pitfalls, and a quick reference of commands you’ll actually reach for. This guide is written with admins in mind who want reliable results with minimal downtime, plus a few backup-hardening ideas. Below is a short summary of what you’ll learn, followed by deeper sections, practical steps, and a robust FAQ.

  • How to assess your current disk layout and plan changes
  • Tools to use fdisk, gdisk, parted, pvcreate, vgcreate, lvextend, resize2fs, xfs_growfs, etc.
  • Non-destructive vs destructive repartitioning workflows
  • How to resize and extend logical volumes LVM online
  • How to create new partitions and filesystems for data directories
  • How to migrate data safely and verify integrity
  • Common pitfalls and recovery tips

Useful URLs and Resources text only
Ubuntu Documentation – ubuntu.com
GNU Parted – gParted.org
GNU fdisk Manual – man7.org/linux/man-pages/man8/fdisk.8.html
LVM HOWTO – linux.yandex.ru
XFS File System – wiki.archlinux.org/index.php/XFS
Ext4 File System – kernel.org
Rescue from a live USB – ubuntu.com/tutorials/booting-into-a-live-environment
rsync Manual – rsync.samba.org/rsync.html
Filesystem Quotas – man7.org/linux/man-pages/man5/quota.5.html How to Install SQL Server Database Engine 2012 Step by Step Guide 2026

Planning and prerequisites

  • Back up everything. Partitions represent the single fastest path to data loss if something goes wrong.
  • Identify the disks and partitions you’ll touch. Use lsblk, blkid, and df -h to map devices to mount points and filesystem types.
  • Decide on a strategy:
    • Non-destructive expansion: grow an existing partition or LV to use free space.
    • Destructive repartitioning: re-create partitions and migrate data.
    • Data separation: create new partitions for /data or other mount points to improve organization and backup scope.
  • Consider the underlying filesystem. ext4 is common on Ubuntu Server; XFS is favored for large data directories. If you’re using LVM, you can resize LV and filesystem more flexibly.
  • If you’re working on a boot disk root, plan for potential downtime. In many server setups, the root filesystem is inside LVM, which makes online resizing possible; otherwise you’ll need a live environment to resize.

Tools you’ll use

  • Disk layout and modification: fdisk, gdisk, parted, sgdisk
  • Partition resizing: parted recommended for GPT, fdisk MBR/legacy
  • LVM management: pvresize, vgextend, lvextend, lvresize, pvcreate, vgcreate, vgscan
  • Filesystem resize: resize2fs ext4, e2fsprogs, xfs_growfs XFS
  • Data migration and copy: rsync, tar, dump/restore specific setups
  • Live environment: Ubuntu Server live USB or other rescue media when resizing root without LVM

Non-destructive vs destructive repartitioning

  • Non-destructive:
    • Extend an existing partition into unallocated space partition must have space immediately after it, or use a tool that supports moving with care
    • Extend a logical volume LV in LVM and then grow the filesystem
    • Create a new partition and format it, then migrate data to it
  • Destructive:
    • Repartition a disk to change partition boundaries significantly and reformat the filesystem
    • Requires full data backup and restore

Step-by-step guide: non-destructive expansion when using LVM

This section covers a common scenario: you have a root volume inside LVM and you’ve added a new disk or have unallocated space. You want to extend the root LV non-disruptively.

  1. Check current layout
  • Run: lsblk -f
  • Verify which volume group and logical volume hold your root filesystem for example /dev/ubuntu-vg/root
  1. Prepare unallocated space if you added a disk or resized a partition
  • If you added a new disk /dev/sdb: create a new PV on it
    • pvcreate /dev/sdb1
    • vgextend ubuntu-vg /dev/sdb1
  • If you have free space in the same disk after a partition, resize the partition to capture it, then pvresize the PV:
    • pvresize /dev/ubuntu-vg/root or pvresize /dev/sda2 depending on your PV
  1. Extend the logical volume
  • lvextend -l +100%FREE /dev/ubuntu-vg/root
    • This uses all free extents in the volume group; adjust as needed.
  1. Resize the filesystem
  • If ext4:
    • resize2fs /dev/ubuntu-vg/root
  • If xfs:
    • xfs_growfs /mount/point or xfs_growfs /dev/ubuntu-vg/root -D size if mounted at a non-standard mount
  1. Verify
  • df -h
  • lsblk
  • Ensure the root filesystem shows the new size and there’s no data loss

Note: If the root filesystem is not on an LV for example, a simple partition mounted at /, you may need to resize the LV anyway if the root partition is enlarged via the disk partition itself. In that case, you might need to boot from a live USB to resize the root partition and filesystem safely.

Step-by-step guide: resizing a non-LVM partition ext4

  1. Back up and boot plan
  • Create a backup plan; consider using rsync to mirror important data to /data or another disk.
  1. Ensure you have unmounted space or can shrink the partition
  • If you can shrink a partition to create unallocated space, you’ll first shrink the filesystem:
    • If the partition is not in use or you can do this safely, unmount to shrink.
    • For root, you’ll generally need a live environment to shrink the filesystem.
  1. Shrink the filesystem
  • If the partition is ext4 and unmounted:
    • e2fsck -f /dev/sda1
    • resize2fs /dev/sda1 100G choose a new size
  1. Resize the partition
  • Use parted or fdisk to shrink the partition to the new size:
    • parted /dev/sda
    • parted resizepart 1 100G
    • parted quit
  1. Verify and mount
  • Run: lsblk -f, df -h
  • Re-mount if needed and verify data integrity
  1. Optional: Create a new partition for data
  • Create a new primary partition in the now unallocated space
  • Format it e.g., mkfs.ext4 /dev/sda2
  • Mount it to /data and copy data if needed

Important note: Root and other critical system partitions are tricky to resize while mounted. In most cases, you’ll use a live CD/USB or a rescue environment to safely resize the root partition.

Step-by-step guide: adding a new disk and using it for data or as extra space

  1. Connect and identify the new disk
  • Run: lsblk or sudo fdisk -l
  • Identify as /dev/sdb for example
  1. Create a partition and filesystem
  • Partition: sudo fdisk /dev/sdb or gdisk/parted for GPT
  • Create a new partition, typically /dev/sdb1
  • File system: sudo mkfs.ext4 /dev/sdb1
  1. Mount and persist
  • Create a mount point: sudo mkdir /data
  • Mount: sudo mount /dev/sdb1 /data
  • Add to /etc/fstab to persist across reboots
  1. Optional: migrate data
  • rsync -aAXv –exclude={“/data/”} /olddata/ /data
  • Ensure permissions and ownership are correct
  1. Expand later
  • If you later add more disks, you can extend the volume group if using LVM or create more partitions and mount points.

Common pitfalls and troubleshooting

  • Data loss risk: Always back up before resizing. A failed resize can corrupt the filesystem.
  • Root partition resizing: Avoid resizing root while running from the same root FS; use a live USB or rescue mode.
  • Mismatched UUIDs and fstab: If a partition’s UUID changes, update /etc/fstab accordingly.
  • Alignment issues: When creating partitions, align to 1MiB boundaries for best performance.
  • LVM metadata misalignment: If lvextend or pvresize fails, re-check PV size and VG state with vgdisplay and pvdisplay.
  • Boot issues after changes: Ensure boot loader entries remain valid if you touch the boot disk.

Best practices and performance tips

  • Use LVM for flexible growth: It’s easier to extend storage later without heavy downtime.
  • Align partitions: Create partitions at 1MiB boundaries to improve performance on modern drives.
  • Keep / and /var separate if you expect growth in logs and caches; this makes backups and maintenance easier.
  • Regular backups: Maintain a robust backup plan, especially before major repartitioning or resizing.
  • Documentation: Keep a record of what you changed and the exact commands you ran to help future maintenance.

Real-world scenarios and case studies

Scenario A: You have a 120GB root disk with 30GB free and want to add 50GB for /var

  • Add a new partition on the same disk or add a new disk
  • If using LVM, pvcreate on new partition, vgextend, lvextend root or create a new LV for /var
  • Resize the filesystem accordingly ext4: resize2fs; if /var is on its own LV, resize after lvextend

Scenario B: You added a 200GB disk and want to use it for /data How to generate a full database diagram in sql server 2026

  • Create /data and format with ext4
  • Mount and back up existing data to /data
  • Update /etc/fstab for automatic mounting on boot
  • Consider moving large datasets to the new disk and symlink or bind-mount if needed

Scenario C: Shrinking a non-LVM partition to free space for other uses

  • Shrink the filesystem first if possible, then shrink the partition
  • The new free space can be used to create another partition or extend an LV if using LVM

Quick reference commands

  • List disks and partitions: lsblk -f
  • Show disk usage: df -h
  • Create a new PV on a disk: pvcreate /dev/sdb1
  • Extend an LV: lvextend -l +100%FREE /dev/ubuntu-vg/root
  • Resize an ext4 filesystem: resize2fs /dev/ubuntu-vg/root
  • Grow an XFS filesystem: xfs_growfs /
  • Resize a PV to reflect new size: pvresize /dev/sdb1
  • Add a disk to an existing VG: vgextend ubuntu-vg /dev/sdb1
  • Copy data safely: rsync -aAXv /source/ /destination/
  • Mount with persistence: echo ‘/dev/sdb1 /data ext4 defaults,bind 0 0’ >> /etc/fstab example; adjust

Frequently Asked Questions

How can I repartition without losing data on Ubuntu Server?

You should back up, plan carefully, and prefer non-destructive methods like resizing an LV and filesystem with the system online, or using a live environment for root partition changes. Always verify the filesystem integrity after any resize with fsck and ensure you have tested boot/debug in a safe environment before relying on it in production.

Can I resize the root partition while the system is running?

If root is on an LVM logical volume, you can often resize online with less downtime. If not, you’ll typically need to boot from a live USB or rescue environment to resize the root partition safely.

What are the differences between fdisk, parted, and gdisk?

  • fdisk is best for MBR disks and basic partitioning; it’s quick but less feature-rich for modern GPT disks.
  • parted supports both MBR and GPT and handles larger disks and advanced layouts with more flexible resizing.
  • gdisk is the GPT-aware equivalent of fdisk and handles GPT disks with more robust features.

How do I resize an ext4 filesystem?

Use resize2fs to resize the ext4 filesystem after resizing the underlying partition and ensuring filesystem integrity with e2fsck first if needed.

How do I resize an XFS filesystem?

XFS supports online growth with the xfs_growfs command. If the XFS filesystem is on a mounted LV, you can run xfs_growfs on the mounted filesystem; if on a non-root partition, mount it and grow accordingly. How to reindex a table in sql server step by step guide 2026

How do I add a new disk to an existing LVM setup?

Create a PV on the new disk pvcreate /dev/sdb1, extend the VG vgextend volume_group_name /dev/sdb1, then lvextend to grow the LV, and finally resize the filesystem.

Should I always use LVM for Ubuntu Server disks?

LVM provides flexibility and is widely used on servers for easier growth and snapshots. If you don’t need the extra complexity, you can use standard partitions, but you’ll lose some flexibility later.

What if the boot loader stops working after repartitioning?

You can recover via a live USB, chroot into your installed system, verify /boot and boot loader configurations, reinstall GRUB if necessary, and update the boot entries.

How do I safely migrate data to a new partition or disk without downtime?

Use rsync to mirror data to the new location, verify integrity, update fstab and mount points, and perform a minimal downtime cutover by stopping affected services, if possible.

How can I verify that my repartitioning was successful?

Check disk space with df -h, verify partition sizes with lsblk -f, confirm the filesystem type, and ensure data accessibility. Run a file-level check e.g., grep, ls, cat tests to validate proper data access. How to Add a Discord Bot Step by Step Guide 2026

What backup strategy should I follow before repartitioning?

Back up critical data to an external disk or cloud storage, create a filesystem-level snapshot if available like LVM snapshots, and test restoring a sample dataset to ensure the backup works.

Can I repartition a live server over the network?

Resizing root or boot partitions from a live environment is safer, but some online LV extensions are possible. If you must work remotely, ensure you have console access and a tested rollback plan, along with a dependable backup strategy.

How do I migrate an entire system to a larger disk with minimal downtime?

Clone the disk or use rsync to replicate the system to a larger disk, adjust fstab and bootloader entries, and perform a careful switch during a maintenance window. Always test boot on the new disk in a controlled environment first.

What are best practices for partition alignment?

Align partitions to 1 MiB boundaries 2048 sectors on 512e disks to optimize performance and reduce write amplification, especially on SSDs and modern HDDs.

Is it safe to delete a partition to reclaim space?

Only after you’ve confirmed you’ve backed up the data and have a recovery plan. Deleting a partition risks data loss if you select the wrong device. How to get a link for your discord server easily with quick invites, permanent links, and best practices 2026

How do I recover data if a partitioning operation goes wrong?

If you have a backup, recover from backup. If not, you may attempt data recovery tools, but success is not guaranteed. Always keep a known-good backup before partition changes.


If you need more hands-on help with a specific setup for example, exact commands for your current partition map or a command-by-command walkthrough for your scenario, tell me your disk layout output of lsblk -f, df -h, and uname -r, and I’ll tailor the steps to your environment.

Sources:

Japan vpn extension edge

如何在macbook上轻松安装和使用vpn?新手指南:macOS上VPN安装步骤、隐私保护与速度优化

Proxy microsoft edge: how to configure proxies in Microsoft Edge with VPNs, IP masking, and geo-unblocking Creating a database in microsoft sql server 2012 a step by step guide to database creation, SSMS, and best practices 2026

蓝灯vpn github:免费翻墙利器还是隐私风险?深度解析与使用指南

免费机场vpn 使用指南:全面评测、设置要点与风险分析(2025 更新)

Recommended Articles

×