But there can still be gotchas if we've been repeating our process of migrating old to new for many many years - one of these gotchas is when you are moving a disk that has its first sector startig at 63 instead of say 2048. What do we do then?
Having cloned my old disk, containing a single
ext4 partition
using clonezilla's disk-to-disk imaging we are ready to extend the partitions to use the rest of the new space. The process for this is very simple:- note partition start boundary via
fdisk
- delete partition
- recreate partition using same start sector number and new extended to end of disk
- run
resize2fs
# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
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: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3ef45f39
Device Boot Start End Sectors Size Id Type
/dev/sdb1 63 471859263 471859201 225G 83 Linux
Partition 1 does not start on physical sector boundary.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048): 63
Value out of range.
First sector (2048-1953525167, default 2048): ^C
Command (m for help): ^C
Do you really want to quit? y
Hmm, so this isn't very good. We MUST recreate at the previous starting boundary but fdisk
complains. To understand this we need to remember that in the past (probably up to the early 2000s) partitions would start at LBA address 63 with 512byte sector sizes. However, modern harddisks almost always come with 4k phsyical sector sizes and logical 512k sectors (see the output from above) and it is more effecient for data reads/writes to be aligned with the phsyical sectors.
Neverless, we can force fdisk
to continue with the -c dos
flag.
# fdisk -c=dos /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
DOS-compatible mode is deprecated.
The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted.
Command (m for help): p
Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Geometry: 225 heads, 37 sectors/track, 121601 cylinders
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3ef45f39
Device Boot Start End Sectors Size Id Type
/dev/sdb1 63 471859263 471859201 225G 83 Linux
Partition 1 does not start on physical sector boundary.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (37-1953525167, default 38): 63
Last sector, +sectors or +size{K,M,G,T,P} (63-1953525167, default 1953525167):
Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): p
Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Geometry: 225 heads, 37 sectors/track, 121601 cylinders
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3ef45f39
Device Boot Start End Sectors Size Id Type
/dev/sdb1 63 1953525167 1953525105 931.5G 83 Linux
Partition 1 does not start on physical sector boundary.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
At this point we have recreated a partition to fill up all usable space - time for a filesystem check before the resize operation.
# partprobe /dev/sdb1
# e2fsck -f /dev/sdb1
e2fsck 1.44.2 (14-May-2018)
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/sdb1: 39667/14745600 files (1.2% non-contiguous), 39865795/58982400 blocks
# resize2fs /dev/sdb1
resize2fs 1.44.2 (14-May-2018)
Resizing the filesystem on /dev/sdb1 to 244190638 (4k) blocks.
The filesystem on /dev/sdb1 is now 244190638 (4k) blocks long.
Finally the resize is complete and we can check and mount the filesystem to show the new size.
# e2fsck -f /dev/sdb1
e2fsck 1.44.2 (14-May-2018)
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/sdb1: 39667/61054976 files (1.2% non-contiguous), 42775537/244190638 blocks
# mount /dev/sdb1 1
# df -h 1
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 917G 149G 722G 18% /tmp/b/1
Perfect. This shows that we've completed the migration from our 225GB to 1TB disk.
No comments:
Post a Comment