Skip to content

Instantly share code, notes, and snippets.

@0xJchen
Created July 15, 2023 22:32
Show Gist options
  • Save 0xJchen/a828c8ae591af107f7451b57f37f3612 to your computer and use it in GitHub Desktop.
Save 0xJchen/a828c8ae591af107f7451b57f37f3612 to your computer and use it in GitHub Desktop.
resize fs
The output from `lsblk` shows that you have two large disks (`nvme0n1` and `nvme1n1`) that are 3.5T in size but do not have any partitions or filesystems. If you want to increase the size of your `/` filesystem, you can't do it directly because it's currently on a smaller disk (`nvme2n1`) which is completely used.
A better approach would be to create a new partition on one of the larger disks, create a filesystem on it, and then move your data from the smaller disk to the new filesystem on the larger disk. Here is an outline of the steps you would need to take.
**Disclaimer: This process can result in data loss if not done carefully. Always backup important data before attempting these steps.**
1. **Create a new partition on one of the larger disks**
Before you create a new partition, you need to check if there is free space available. If there is no free space, you may need to shrink or delete an existing partition.
Here is an example of creating a new partition using `fdisk`. This example uses `/dev/nvme0n1`, but replace that with whichever device you want to partition:
```
sudo fdisk /dev/nvme0n1
```
In the fdisk utility:
- Press `n` to create a new partition
- Select the defaults to use all available space
- Press `w` to write the changes
2. **Create a new filesystem on the new partition**
Assuming the new partition is `/dev/nvme0n1p1`, you would use `mkfs` to create a new filesystem:
```
sudo mkfs.ext4 /dev/nvme0n1p1
```
Replace `ext4` with your filesystem of choice, if different.
3. **Mount the new filesystem**
Before you can use the new filesystem, you need to mount it. First, create a mount point, such as `/mnt/newroot`:
```
sudo mkdir /mnt/newroot
```
Then, mount the new filesystem:
```
sudo mount /dev/nvme0n1p1 /mnt/newroot
```
4. **Copy the data from the old filesystem to the new one**
One way to copy the data is to use `rsync`:
```
sudo rsync -aAXv / /mnt/newroot --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}
```
This command copies all files from the root filesystem to the new filesystem, excluding certain directories that should not or need not be copied.
5. **Update /etc/fstab**
Before you reboot, you need to update `/etc/fstab` to mount the new filesystem at boot. First, find the UUID of the new filesystem:
```
sudo blkid
```
Look for the line with `/dev/nvme0n1p1` and note the UUID. Then, open `/etc/fstab` in a text editor:
```
sudo nano /etc/fstab
```
Add a line for the new filesystem:
```
UUID=your-uuid / ext4 errors=remount-ro 0 1
```
Replace `your-uuid` with the actual UUID.
6. **Reboot**
Finally, you can reboot into your new filesystem:
```
sudo reboot
```
After the reboot, your `/` filesystem should be on the new, larger disk. Verify this with `df -hT`.
Again, this is a high-risk operation that can result in data loss, so proceed with caution and make sure you have backups of your data. Also, make sure to test everything thoroughly before using the system for important work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment