2022-01-16 18:20:39 +00:00
|
|
|
---
|
|
|
|
title: "partitions"
|
2022-01-26 22:35:07 +00:00
|
|
|
tags: [ "Documentation", "System" ]
|
2022-01-16 18:20:39 +00:00
|
|
|
---
|
2020-01-02 00:04:35 +00:00
|
|
|
# FDisk Basics
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo fdisk /dev/sda
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
- m for help.
|
|
|
|
|
|
|
|
- n to make a partition.
|
|
|
|
|
|
|
|
- t to mark the partition type (see IDs below).
|
|
|
|
|
|
|
|
- w to write the changes to the disk.
|
|
|
|
|
|
|
|
Note the asterisk marking the boot partition.
|
|
|
|
|
|
|
|
|
|
|
|
# IDs
|
|
|
|
|
|
|
|
| ID | Meaning |
|
|
|
|
|----|:--------|
|
|
|
|
|83 |Linux |
|
|
|
|
| 5 |Extended |
|
|
|
|
| 82 |Swap |
|
|
|
|
|
|
|
|
fdisk will not help with a GPT formatted drive. For this, use gdisk, which is mostly the same.
|
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
Now that we have a partition, we can make it into a fileSystem. Most will use:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mkfs -t ext4 /dev/sdc1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
or if you're making a swap partition, you can use:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mkswap /dev/sdb2
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
or for the reiser fileSystem, we can use:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mkreiserfs /dev/sdc2
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# File System Types
|
|
|
|
|
|
|
|
| Type | Advantages | Disadvantages |
|
|
|
|
|------|:-----------|:--------------|
|
|
|
|
|ext2 | |No journaling means that the file offers no crash recovery.
|
|
|
|
|ext3 | Journaling |
|
|
|
|
|ext4 | Journaling and handles files of up to 16TB.|
|
|
|
|
|reiserfs| Journalin and stable.|
|
|
|
|
|btrfs |Reliable and stable|
|
|
|
|
|XFS |Journaling, great for large files.|
|
|
|
|
|VFAT |Comptable with Windows, like FAT32|
|
|
|
|
|
|
|
|
# Parted
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo parted /dev/sdb
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Monitoring
|
|
|
|
Look at physical and virtual partitions:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
df -h
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
or divide things by inode - the thing which records where files are?
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
df -i
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
Examine a fileSystem with:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo dumpe2fs /dev/sda1 | less
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# Prevention
|
|
|
|
There are multiple programs which work mostly the same way.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo tune2fs -c 30 /dev/sda1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
This will check sda1 every 30 boots. It can also be checked every month.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo tune2fs -i 1m /dev/sda1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
This thing can also make a new label for the System:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo tune2fs -L new_name /dev/sdb3
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# Repair
|
2022-01-26 22:35:07 +00:00
|
|
|
Start by unmounting the fileSystem.
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo umount /dev/sdc1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Then it's time to check.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo fsck /dev/sdc1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
And possibly repair damage:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
e2fsck -p /dev/sdc1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
or the same with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo debugfs /dev/sdc1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# Mounting
|
|
|
|
You can mount with a specified filetype with:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mount -t ext3 /dev/sdc2 /mnt/stick
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
or if you don't know the type, just try the lot:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo mount -a /dev/sdc1 /mnt/stick
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
# File Systems
|
|
|
|
xfs and zfs can only be expanded.
|
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
# Shrink FileSystem
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
NB: When I followed these instructions, the process destroyed my data. Seemed fine on the YouTube video.
|
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
Check the fileSystem's health:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo e2fsck -f /dev/sdb1
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
Resize the file System to something smaller than what you want, so here I want 500G and so I resize to 450 G.
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
resize2fs /dev/sdb1 450G
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Then delete the partition with either gdisk or fdisk, depending upon the layout.
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo fdisk /dev/sdb
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
d
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2022-01-26 22:35:07 +00:00
|
|
|
Then make a new fileSystem of the desired type with:
|
2020-01-02 00:04:35 +00:00
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
n
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
And finally resize to the full size you want:
|
|
|
|
|
|
|
|
sudo resize2fs /dev/sdb1
|
|
|
|
|
|
|
|
And then check your disk again with e2fsck.
|
|
|
|
|
|
|
|
(The e2fsck saved my disk in the end, YMMV)
|
|
|
|
|
|
|
|
|
|
|
|
# Logical Volume
|
|
|
|
|
|
|
|
Let's start with names. PV = 'Physical Volume', VG = 'Volume Group', and LV = 'Logical Volume'.
|
|
|
|
|
|
|
|
Now we can create a volume group out of sdb2 and sdc3:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo vgcreate my-new-vg /dev/sdb2 /dev/sdc3
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Then make a new logical volume out of the volume group:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo lvcreate -n my-new-lv my-new-vg
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
Then have a look at all logical volumes:
|
|
|
|
|
2023-06-17 19:28:20 +00:00
|
|
|
```bash
|
|
|
|
sudo lvscan
|
|
|
|
```
|
2020-01-02 00:04:35 +00:00
|
|
|
|
|
|
|
|