Linux: An Experience in Resizing a Root Partition

Scope:

These instructions are intended for Linux systems without Logical Volume Manager (LVM). For that other type of system, check this documentation.

Resizing normal volumes in Linux is straightforward if partitions have already been set as members of groups controlled by Logical Volume Manager (LVM). However, many Linux instances are configured using automatic partitioning, whereby most volumes are set by the installation wizards. LVM configurations are typically out of scope of those installs. Hence, a Linux Admins must spend much time practicing Linux file systems manipulations. This article is an example of those endeavors.

For the adventurous, follow this external instruction with a grain of salt http://www.ivarch.com/blogs/oss/2007/01/resize-a-live-root-fs-a-howto.shtml). I’m more conservative when it comes to modifying root partitions. My preferred route has always been performing such task while root is NOT mounted to avoid open-file errors. In cloud and virtual machine services, one could simply remove the virtual disk of the target guest machine and reattach it to another Linux OS. In physical environments, it would be as simple as moving a physical disk from one server to the next. Better yet, I would advise in cloning a reference disk prior to performing shrinking or expanding storage procedures. Otherwise, one must take very good bread-crumb notes to revert failed attempts, should there be any.

Avast, prior to re-partitioning any device, one must note its start and ending sectors. A partition must be contiguous to avoid data loss. There are two popular tools available on most Linux flavors: Parted and Fdisk. Parted is convenient as it allows in-line calling of its methods to return values of private variables. Fdisk works via pure CLI, so it’s not convenient for scripting. In this example, I use parted for discovery and fdisk for partitioning to demonstrate usage of both utilities.

# Rescan disk 'device' that has been expanded in VMWare, Hyper-V, or KVM
deviceLetter=a
echo 1 > /sys/class/block/sd$deviceLetter/device/rescan
# View partitions (aka 'devices' - logical partitions of a device)
root@kimlinux:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0    7:0    0  55.3M  1 loop /snap/core18/1885
loop1    7:1    0  96.6M  1 loop /snap/core/9804
loop2    7:2    0  62.1M  1 loop /snap/gtk-common-themes/1506
loop3    7:3    0 161.4M  1 loop /snap/gnome-3-28-1804/128
loop4    7:4    0  29.9M  1 loop /snap/snapd/8790
loop5    7:5    0    39M  1 loop /snap/remmina/4309
loop6    7:6    0  39.6M  1 loop /snap/remmina/4324
loop7    7:7    0     4M  1 loop /snap/notepad-plus-plus/238
loop8    7:8    0 226.7M  1 loop /snap/wine-platform-runtime/145
loop9    7:9    0   215M  1 loop /snap/wine-platform-5-stable/5
sda      8:0    0  14.9G  0 disk 
sdb      8:16   0   477G  0 disk 
├─sdb1   8:17   0   300M  0 part /boot/efi
└─sdb2   8:18   0 476.7G  0 part /

root@kimlinux:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  1.7M  3.2G   1% /run
/dev/sdb2       469G  9.8G  435G   3% /
tmpfs            16G  404M   16G   3% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/loop1       97M   97M     0 100% /snap/core/9804
/dev/loop3      162M  162M     0 100% /snap/gnome-3-28-1804/128
/dev/loop2       63M   63M     0 100% /snap/gtk-common-themes/1506
/dev/loop4       30M   30M     0 100% /snap/snapd/8790
/dev/loop0       56M   56M     0 100% /snap/core18/1885
/dev/loop5       39M   39M     0 100% /snap/remmina/4309
/dev/loop6       40M   40M     0 100% /snap/remmina/4324
/dev/loop7      4.2M  4.2M     0 100% /snap/notepad-plus-plus/238
/dev/loop8      227M  227M     0 100% /snap/wine-platform-runtime/145
/dev/loop9      215M  215M     0 100% /snap/wine-platform-5-stable/5
/dev/sdb1       300M  7.8M  292M   3% /boot/efi
tmpfs            16G  8.0K   16G   1% /tmp
tmpfs           3.2G   12K  3.2G   1% /run/user/1000

# reboot now
# Attach disk to another Linux machine
# Discovery

#Using Parted:
lubuntu@lubuntu:~$ sudo parted /dev/sdb 'unit s print'
Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sdb: 1000215216s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start    End          Size        File system  Name  Flags
 1      4096s    618495s      614400s     fat32              boot, esp
 2      618496s  1000206899s  999588404s  ext4
 
# Using Fdisk:
lubuntu@lubuntu:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.34).                                          
Changes will remain in memory only, until you decide to write them.          
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C

Device      Start        End   Sectors   Size Type
/dev/sdb1    4096     618495    614400   300M EFI System
/dev/sdb2  618496 1000206899 999588404 476.7G Linux filesystem

# Input the target partition manually
partition=/dev/sdb2
newsizeMb=471040

# Discover the start and end blocks automatically
device=$(lsblk -no pkname $partition)
partitionName=$([[ $partition =~ ([a-zA-Z0-9]+)$ ]] && echo ${BASH_REMATCH[1]})
sysblockDevice=/sys/block/$device
sysblockPath=/sys/block/$device/$partitionName
start=$(cat $sysblockPath/start)
size=$(cat $sysblockPath/size)
end=$(expr $size + $start - 1)
sectorSize=$(cat $sysblockDevice/queue/hw_sector_size)
newSize=$((1024 * 1024 / $sectorSize * $newsizeMb)) # 1024^2/sectorSize * MB
newEnd=$(expr $newSize + $start - 1)
partitionNumber=$(cat $sysblockPath/partition)

# My old script that doesn't work anymore due to this.
# Error: The resize command has been removed in parted 3.0
#if [ "$newEnd" -gt "$end" ] then
#	sudo parted -s $partition unit s resize $partitionNumber $start $newEnd
#fi

Resizing Linux Partitions – The Tried And True Method

# Resizing file system on root partition
lubuntu@lubuntu:~$ sudo resize2fs /dev/sdb2 400G
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/sdb2 to 104857600 (4k) blocks.
The filesystem on /dev/sdb2 is now 104857600 (4k) blocks long.
# Note the output of the above command: 104857600 blocks x 4k per block = 419430400k <= this is the value needed for the next step

# Get the last sector of disk
ubuntu@lubuntu:~$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C
Device      Start        End   Sectors   Size Type
/dev/sdb1    4096     618495    614400   300M EFI System
/dev/sdb2  618496 1000206899 999588404 476.7G Linux filesystem

# Retry partitioning using size value calculated previously, NOT sector counts
lubuntu@lubuntu:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).                                                                                   
Changes will remain in memory only, until you decide to write them.                                                   
Be careful before using the write command.
Command (m for help): d
Partition number (1,2, default 2):  
Partition 2 has been deleted.
Command (m for help): n
Partition number (2-128, default 2): 
First sector (618496-1000215182, default 618496): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (618496-1000215182, default 1000215182): +419430400k
Created a new partition 2 of type 'Linux filesystem' and of size 400 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# Check partition
lubuntu@lubuntu:~$ sudo e2fsck -f /dev/sdb2
e2fsck 1.45.5 (07-Jan-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb2: 317354/26214400 files (0.6% non-contiguous), 4472439/104857600 blocks

Resizing a partition – Example of what NOT To Do!

lubuntu@lubuntu:$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.34).                                                                      
Changes will remain in memory only, until you decide to write them.                                      
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C

Device      Start        End   Sectors   Size Type
/dev/sdb1    4096     618495    614400   300M EFI System
/dev/sdb2  618496 1000206899 999588404 476.7G Linux filesystem

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

Partition 2 has been deleted.

Command (m for help): n
Partition number (2-128, default 2): 
First sector (618496-1000215182, default 618496): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (618496-1000215182, default 1000215182): 965308415

Created a new partition 2 of type 'Linux filesystem' and of size 460 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): n
Partition number (3-128, default 3): 
First sector (965308416-1000215182, default 965308416): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (965308416-1000215182, default 1000215182): 

Created a new partition 3 of type 'Linux filesystem' and of size 16.7 GiB.

Command (m for help): t
Partition number (1-3, default 3): 
Partition type (type L to list all types): 31

Changed type of partition 'Linux filesystem' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# Check disk health

lubuntu@lubuntu:/$ sudo e2fsck /dev/sdb
e2fsck 1.45.5 (07-Jan-2020)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sdb

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

Found a gpt partition table in /dev/sdb


# Format the newly created partition and assign it to an LVM volume
lubuntu@lubuntu:/$ testDisk2=/dev/sdb3
lubuntu@lubuntu:/$ sudo pvcreate $testDisk2
  Physical volume "/dev/sdb3" successfully created.
lubuntu@lubuntu:/$ sudo pvscan -v
  PV /dev/sda                       lvm2 [14.91 GiB]
  PV /dev/sdb3                      lvm2 [16.64 GiB]
  Total: 2 [<31.56 GiB] / in use: 0 [0   ] / in no VG: 2 [<31.56 GiB]
lubuntu@lubuntu:/$ sudo vgcreate volumegroup1 /dev/sda /dev/sdb3
  Volume group "volumegroup1" successfully created

# View the results of the re-partitioned disk
root@lubuntu:~# sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).                                                                      
Changes will remain in memory only, until you decide to write them.                                      
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C

Device         Start        End   Sectors  Size Type
/dev/sdb1       4096     618495    614400  300M EFI System
/dev/sdb2     618496  965308415 964689920  460G Linux filesystem
/dev/sdb3  965308416 1000215182  34906767 16.7G Linux LVM

Full list of disk formatting options:

  1 EFI System                     C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  2 MBR partition scheme           024DEE41-33E7-11D3-9D69-0008C781F39F
  3 Intel Fast Flash               D3BFE2DE-3DAF-11DF-BA40-E3A556D89593
  4 BIOS boot                      21686148-6449-6E6F-744E-656564454649
  5 Sony boot partition            F4019732-066E-4E12-8273-346C5641494F
  6 Lenovo boot partition          BFBFAFE7-A34F-448A-9A5B-6213EB736C22
  7 PowerPC PReP boot              9E1A2D38-C612-4316-AA26-8B49521E5A8B
  8 ONIE boot                      7412F7D5-A156-4B13-81DC-867174929325
  9 ONIE config                    D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149
 10 Microsoft reserved             E3C9E316-0B5C-4DB8-817D-F92DF00215AE
 11 Microsoft basic data           EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
 12 Microsoft LDM metadata         5808C8AA-7E8F-42E0-85D2-E1E90434CFB3
 13 Microsoft LDM data             AF9B60A0-1431-4F62-BC68-3311714A69AD
 14 Windows recovery environment   DE94BBA4-06D1-4D40-A16A-BFD50179D6AC
 15 IBM General Parallel Fs        37AFFC90-EF7D-4E96-91C3-2D7AE055B174
 16 Microsoft Storage Spaces       E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D
 17 HP-UX data                     75894C1E-3AEB-11D3-B7C1-7B03A0000000
 18 HP-UX service                  E2A1E728-32E3-11D6-A682-7B03A0000000
 19 Linux swap                     0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
 20 Linux filesystem               0FC63DAF-8483-4772-8E79-3D69D8477DE4
 21 Linux server data              3B8F8425-20E0-4F3B-907F-1A25A76F98E8
 22 Linux root (x86)               44479540-F297-41B2-9AF7-D131D5F0458A
 23 Linux root (ARM)               69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
 24 Linux root (x86-64)            4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
 25 Linux root (ARM-64)            B921B045-1DF0-41C3-AF44-4C6F280D3FAE
 26 Linux root  (IA-64)             993D8D3D-F80E-4225-855A-9DAF8ED7EA97
 27 Linux reserved                 8DA63339-0007-60C0-C436-083AC8230908
 28 Linux home                     933AC7E1-2EB4-4F13-B844-0E14E2AEF915
 29 Linux RAID                     A19D880F-05FC-4D3B-A006-743F0F84911E
 30 Linux extended boot            BC13C2FF-59E6-4262-A352-B275FD6F7172
 31 Linux LVM                      E6D6D379-F507-44C2-A23C-238F2A3DF928
 32 FreeBSD data                   516E7CB4-6ECF-11D6-8FF8-00022D09712B
 33 FreeBSD boot                   83BD6B9D-7F41-11DC-BE0B-001560B84F0F
 34 FreeBSD swap                   516E7CB5-6ECF-11D6-8FF8-00022D09712B
 35 FreeBSD UFS                    516E7CB6-6ECF-11D6-8FF8-00022D09712B
 36 FreeBSD ZFS                    516E7CBA-6ECF-11D6-8FF8-00022D09712B
 37 FreeBSD Vinum                  516E7CB8-6ECF-11D6-8FF8-00022D09712B
 38 Apple HFS/HFS+                 48465300-0000-11AA-AA11-00306543ECAC
 39 Apple UFS                      55465300-0000-11AA-AA11-00306543ECAC
 40 Apple RAID                     52414944-0000-11AA-AA11-00306543ECAC
 41 Apple RAID offline             52414944-5F4F-11AA-AA11-00306543ECAC
 42 Apple boot                     426F6F74-0000-11AA-AA11-00306543ECAC
 43 Apple label                    4C616265-6C00-11AA-AA11-00306543ECAC
 44 Apple TV recovery              5265636F-7665-11AA-AA11-00306543ECAC
 45 Apple Core storage             53746F72-6167-11AA-AA11-00306543ECAC
 46 Solaris boot                   6A82CB45-1DD2-11B2-99A6-080020736631
 46 Solaris boot                   6A82CB45-1DD2-11B2-99A6-080020736631
 46 Solaris boot                   6A82CB45-1DD2-11B2-99A6-080020736631
 47 Solaris root                   6A85CF4D-1DD2-11B2-99A6-080020736631
 48 Solaris /usr & Apple ZFS       6A898CC3-1DD2-11B2-99A6-080020736631
 49 Solaris swap                   6A87C46F-1DD2-11B2-99A6-080020736631
 50 Solaris backup                 6A8B642B-1DD2-11B2-99A6-080020736631
 51 Solaris /var                   6A8EF2E9-1DD2-11B2-99A6-080020736631
 52 Solaris /home                  6A90BA39-1DD2-11B2-99A6-080020736631
 53 Solaris alternate sector       6A9283A5-1DD2-11B2-99A6-080020736631
 54 Solaris reserved 1             6A945A3B-1DD2-11B2-99A6-080020736631
 55 Solaris reserved 2             6A9630D1-1DD2-11B2-99A6-080020736631
 56 Solaris reserved 3             6A980767-1DD2-11B2-99A6-080020736631
 57 Solaris reserved 4             6A96237F-1DD2-11B2-99A6-080020736631
 58 Solaris reserved 5             6A8D2AC7-1DD2-11B2-99A6-080020736631
 59 NetBSD swap                    49F48D32-B10E-11DC-B99B-0019D1879648
 60 NetBSD FFS                     49F48D5A-B10E-11DC-B99B-0019D1879648
 61 NetBSD LFS                     49F48D82-B10E-11DC-B99B-0019D1879648
 62 NetBSD concatenated            2DB519C4-B10E-11DC-B99B-0019D1879648
 63 NetBSD encrypted               2DB519EC-B10E-11DC-B99B-0019D1879648
 64 NetBSD RAID                    49F48DAA-B10E-11DC-B99B-0019D1879648
 65 ChromeOS kernel                FE3A2A5D-4F32-41A7-B725-ACCC3285A309
 66 ChromeOS root fs               3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC
 67 ChromeOS reserved              2E0A753D-9E48-43B0-8337-B15192CB1B5E
 68 MidnightBSD data               85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7
 69 MidnightBSD boot               85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7
 70 MidnightBSD swap               85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7
 71 MidnightBSD UFS                0394EF8B-237E-11E1-B4B3-E89A8F7FC3A7
 72 MidnightBSD ZFS                85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7
 73 MidnightBSD Vinum              85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7
 74 Ceph Journal                   45B0969E-9B03-4F30-B4C6-B4B80CEFF106
 75 Ceph Encrypted Journal         45B0969E-9B03-4F30-B4C6-5EC00CEFF106
 76 Ceph OSD                       4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D
 77 Ceph crypt OSD                 4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D
 78 Ceph disk in creation          89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE
 79 Ceph crypt disk in creation    89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE
 80 VMware VMFS                    AA31E02A-400F-11DB-9590-000C2911D1B8
 81 VMware Diagnostic              9D275380-40AD-11DB-BF97-000C2911D1B8
 82 VMware Virtual SAN             381CFCCC-7288-11E0-92EE-000C2911D0B2
 83 VMware Virsto                  77719A0C-A4A0-11E3-A47E-000C29745A24
 84 VMware Reserved                9198EFFC-31C0-11DB-8F78-000C2911D1B8
 85 OpenBSD data                   824CC7A0-36A8-11E3-890A-952519AD3F61
 86 QNX6 file system               CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1
 87 Plan 9 partition               C91818F9-8025-47AF-89D2-F030D7000C2C
 88 HiFive Unleashed FSBL          5B193300-FC78-40CD-8002-E86C45580B47

Although the instructions above are effective to the extent of showing us what NOT to do. As expected, the subject Linux machine would not boot after the procedure due to block errors. Fortunately, the following shall be an illustration of how to fix such a problem – I hope this info would save some Admin who’s having a bad day.

# checkdisk found errors
lubuntu@lubuntu:~$ sudo e2fsck -f /dev/sdb2
e2fsck 1.45.5 (07-Jan-2020)
The filesystem size (according to the superblock) is 124948550 blocks
The physical size of the device is 120586240 blocks
Either the superblock or the partition table is likely to be corrupt!

# Look for backups of superblock
lubuntu@lubuntu:~$ sudo mke2fs -n /dev/sdb2
mke2fs 1.45.5 (07-Jan-2020)                                                                                           
/dev/sdb2 contains a ext4 file system                                                                                 
        last mounted on / on Mon Aug 24 04:57:14 2020                                                                 
Proceed anyway? (y,N) y                                                                                               
Creating filesystem with 120586240 4k blocks and 30146560 inodes                                                      
Filesystem UUID: 46176ecb-6490-43e8-9ae5-c79f4b2e2f04                                                                 
Superblock backups stored on blocks:                                                                                  
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,                                       
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,                                           
        102400000

# Attempted to restore superblock from one of the locations        
sudo e2fsck -b 78675968 /dev/sdb2
Error writing block 120586454 (Invalid argument) while getting next inode from scan.  Ignore error<y>? yes
Error writing block 120586453 (Invalid argument) while getting next inode from scan.  Ignore error<y>? yes
Error writing block 120586449 (Invalid argument) while getting next inode from scan.  Ignore error<y>? yes
Error writing block 120586452 (Invalid argument) while getting next inode from scan.  Ignore error<y>? yes
Error reading block 120586456 (Invalid argument) while getting next inode from scan.  Ignore error<y>? yes
/dev/sdb2: e2fsck canceled.
/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****

# Reverted changes to disk
lubuntu@lubuntu:~$ sudo fdisk /dev/sdb2
Welcome to fdisk (util-linux 2.34).                                                                                                                                                          
Changes will remain in memory only, until you decide to write them.                                                                                                                          
Be careful before using the write command.
The old ext4 signature will be removed by a write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xb911f923.
Command (m for help): p
Disk /dev/sdb2: 460 GiB, 493921239552 bytes, 964689921 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: 0xb911f923
Command (m for help): quit
lubuntu@lubuntu:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.34).                                                                                                                                                          
Changes will remain in memory only, until you decide to write them.                                                                                                                          
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C
Device      Start       End   Sectors  Size Type
/dev/sdb1    4096    618495    614400  300M EFI System
/dev/sdb2  618496 965308416 964689921  460G Linux filesystem
Command (m for help): d
Partition number (1,2, default 2): 
Partition 2 has been deleted.
Command (m for help): n
Partition number (2-128, default 2): 
First sector (618496-1000215182, default 618496): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (618496-1000215182, default 1000215182): 1000206899
Created a new partition 2 of type 'Linux filesystem' and of size 476.7 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): p
Disk /dev/sdb: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 850 
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: gpt
Disk identifier: 1D8CE9C6-B07F-3D46-8FA3-3ABC71E0985C

Device      Start        End   Sectors   Size Type
/dev/sdb1    4096     618495    614400   300M EFI System
/dev/sdb2  618496 1000206899 999588404 476.7G Linux filesystem

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# Retry fixing disk
lubuntu@lubuntu:~$ sudo e2fsck -f /dev/sdb2
e2fsck 1.45.5 (07-Jan-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences:  +(4096000--4097084) +(7962624--7963708) +(11239424--11240508) +(20480000--20481084) +(23887872--23888956) +(71663616--71664700) +(78675968--78677052) +(102400000--102401084)
Fix<y>? yes
Free blocks count wrong for group #0 (23453, counted=10578).
Fix<y>? yes
Free blocks count wrong for group #1 (31683, counted=19341).
### omitted for brevity ###
Directories count wrong for group #3792 (0, counted=621).
Fix<y>? yes
Free inodes count wrong (31244277, counted=30926934).
Fix<y>? yes
Padding at end of inode bitmap is not set. Fix<y>? yes
/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb2: 317354/31244288 files (0.4% non-contiguous), 4788118/124948550 blocks

Leave a Reply

Your email address will not be published. Required fields are marked *