Skip to content
Snippets Groups Projects
Verified Commit 9480da74 authored by anarcat's avatar anarcat
Browse files

rewrite partitionned disk procedure

I was kind of scared of destroying everything by using fdisk. Turns
out there's a really easy hack with sfdisk.

This hack was found on this page:

https://karelzak.blogspot.com/2015/05/resize-by-sfdisk.html

This was used to resize vineale, see team#40778.
parent d2c610df
No related branches found
No related tags found
No related merge requests found
......@@ -495,109 +495,96 @@ want to extend from 10G to 20G to fill up the free space on
resize:
```
# lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 10G 0 part /
sdb 8:16 0 2G 0 disk [SWAP]
sdc 8:32 0 40G 0 disk /srv
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 40G 0 disk
└─sda1 8:1 0 20G 0 part /
sdb 8:16 0 4G 0 disk [SWAP]
```
We use fdisk on the device:
```
# fdisk /dev/sda
We use `sfdisk` to resize the partition to take up all available
space, in this case, with the magic:
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
echo ", +" | sfdisk -N 1 --no-act /dev/sda
Note the `--no-act` here, which you'll need to remove to actually make
the change, the above is just a preview to make sure you will do the
right thing. Here's a working example:
Command (m for help): p # prints the partition table
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
```
# echo ", +" | sfdisk -N 1 --no-reread /dev/sda
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
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: 0x73ab5f76
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 20971519 20969472 10G 83 Linux # note the starting sector for later
Disk identifier: 0x00000000
```
Old situation:
Now we delete the partition. Note that the data will not be deleted, only the partition table will be altered:
```
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 41943039 41940992 20G 83 Linux
Command (m for help): p
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
/dev/sda1:
New situation:
Disklabel type: dos
Disk identifier: 0x73ab5f76
```
Disk identifier: 0x00000000
Now we create the new partition to take up the whole space:
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 83886079 83884032 40G 83 Linux
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
Syncing disks.
```
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-41943039, default 2048): 2048 # this is the starting sector from above.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): 41943039
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Partition #1 contains a ext4 signature.
Note that the partition table wasn't updated:
Do you want to remove the signature? [Y]es/[N]o: n # we want to keep the previous signature
```
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 40G 0 disk
└─sda1 8:1 0 20G 0 part /
sdb 8:16 0 4G 0 disk [SWAP]
```
Command (m for help): p
So we need to reboot:
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU HARDDISK
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: 0x73ab5f76
```
reboot
```
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 41943039 41940992 20G 83 Linux
Note: a previous version of this guide was using `fdisk` instead, but
that guide was destroying and recreating the partition, which seemed
too error-prone. The above procedure is more annoying (because of the
reboot below) but should be less dangerous.
Command (m for help): w
The partition table has been altered.
Syncine disks.
```
TODO: next time, test with `--force` instead of `--no-reread` to see
if we still need a reboot.
Now we check the partitions:
Now we check the partitions again:
```
# lsblk -a
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 20G 0 disk
└─sda1 8:1 0 20G 0 part /
sdb 8:16 0 2G 0 disk [SWAP]
sdc 8:32 0 40G 0 disk /srv
sda 8:0 0 40G 0 disk
└─sda1 8:1 0 40G 0 part /
sdb 8:16 0 4G 0 disk [SWAP]
```
If we check the free disk space on the device we will notice it has not changed yet:
If we check the free space on the device, we will notice it has not
changed yet:
```
# df -h /
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 9.8G 8.5G 874M 91% /
/dev/sda1 20G 16G 2.8G 86% /
```
We need to resize it:
......@@ -607,7 +594,7 @@ We need to resize it:
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sda1 is now 5242624 (4k) blocks long.
The filesystem on /dev/sda1 is now 10485504 (4k) blocks long.
```
The resize is now complete.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment