lvm: created guide to root lv shrinking

master
tiyn 2 years ago
parent 608b53adb1
commit e8a5a95294

@ -0,0 +1,18 @@
# Arch Linux
[Arch Linux](https://archlinux.org/) is a rolling-release, general-purpose Linux
distribution.
Arch Linux uses the [pacman](./pacman_and_yay.md) package manager.
The Arch User Repositories (AUR) features community-made packages that can be
installed with different
[package manager that inlcude access to the AUR](/wiki/linux/arch-linux/pacman_and_yay.md).
## Installation Medium
For the installation usage of a simple USB key is advised.
This has to be flashed with the Arch ISO.
The ISO file can be found on the
[official website](https://www.archlinux.org/download/).
The iso can be written on an USB-stick using the command
`dd bs=4M if=<path to ISO> of=/dev/sdx conv=fsync oflag=direct status=progress`.
`<path to ISO>` points the command to the location of the ISO file

@ -2,14 +2,17 @@
This guide is based upon a
[german arch wiki article](https://wiki.archlinux.de/title/Moderne_Installation_mit_UEFI_und_Verschlüsselung).
For encryption [dm-crypt](../dm-crypt.md) is used.
Inside the encrypted partition a logical volume will be created with
[LVM](../lvm.md).
At the end of this guide a fully functional Arch Linux will be installed.
## 1. Preparation
Ahead of the installation an Arch boot-stick has to be created. The iso-file can
be found on the [official website](https://www.archlinux.org/download/).
The iso can be written on an USB-stick using `dd`.
Ahead of the installation an Arch boot-stick has to be created as described in
[the Arch Linux entry](/wiki/linux/arch-linux/arch-linux.md#installation-medium).
After that the USB can be plugged in the system on which Arch should be installed.
Boot the target system and select `Boot Arch Linux (x86_64)`.

@ -1,9 +1,47 @@
# Disk Management
This article focusses on non-LVM and non-MDADM storage.
For [LVM](lvm.md), [MDADM](./mdadm.md) and [LUKS volumes](./dm-crypt.md) there
For [LVM](lvm.md), [NTFS](./ntfs.md), [Samba](./samba.md), [MDADM](./mdadm.md) and [LUKS volumes](./dm-crypt.md) there
are separate entries.
## Universally Unique identifier
Universally Unique identifier (UUID) are identifiers for informations on
computer systems.
Most notably they are used to identify file systems.
This way the UUID of a file system can be used to identify and
[mount it](#mounting) persistently and correctly.
By listing the directory `/dev/disk/by-partuuid` all mappings of devices to a
UUID are displayed.
## Mounting
Mounting a file system makes the files of it accessible to the user.
The command `mount` is used to manually and temporarily mount file systems.
Automatic mounting is done by changing the file `/etc/fstab`.
The exact guide on how to mount specific file systems can be found in their
respecitive wiki entries.
The following describes the general basics of mounting temporarily and
persistently.
The basic mount command for temporarily accessing a file system is the
following:
`mount <path to partition> <path to mount point>`
All partitions can be found at `/dev` and the standard mount point is `/mnt` and
its subfolders.
For automatic mounting the following line has to be adapted and added to the
file `/etc/fstab`
`<specified partition> <path to mount point> <file system> <additional options> <dump flag> <fsck order>`
The partition can be specified by [UUID](#universally-unique-identifier).
The file system varies and a file system specific guide on how to mount them
can be found in their respective entries.
The dump flag signals if the file system should be dumped.
The `fsck` order signals if a file system should be checked at boot.
Boot partitions should be flagged with a `1` for this reason, otherwise `0`.
## Create Partition
In the following it is assumed that the disk is `/dev/sda`
@ -13,7 +51,10 @@ In the following it is assumed that the disk is `/dev/sda`
- create a primary partition (ext4 format) with `mkpart primary 2048s 100%`
- `quit` parted
## Grow non-LVM ext4 partition
`<path to partition>` points to the partition that will be enlarged (for
example `/dev/sda2`).
## Grow non-LVM partition
ATTENTION: Please note that the partition to enlarge has to be the last one with
the free space after it.
@ -28,7 +69,33 @@ the last step (alternatively you can insert `100%` as end, if you want to add al
the available free space to the partition)
- `quit` parted
Now you need to resize the filesystem with `resize2fs /dev/sda2`.
Afterwards the file system need to be resized as described in a
[later section](#growing-a-file-system).
## Growing a File System
A file system can easily be resized if free space is available on the partition
it is stored in.
The free space has to be placed behind the partition.
This can be done by running the following command:
```sh
sudo resize2fs <path to partition>
```
## Shrinking a File System
To shrink a file system the `resize2fs` command will be used aswell as `e2fsck`.
First the file system needs to be checked for size aswell as data distribution.
This can be done using the command `sudo e2fsck -f <path to partition>`.
`<path to partition>` directs to the volume whose file system should be
shrinked - for example `/dev/sda1`.
It has to be the same for the next step aswell.
Afterwards the file system can be shrinked with the command
`sudo resize2fs <path to partition> <new size of the file system>`.
`<new size of the file system>` is the size that the file system will be
shrunken to in the usual notation (for example `12G`).
Especially for large file systems this might take a while.
## Error solving

@ -12,7 +12,7 @@ package.
### Manual Mounting of Bitlocker Partition
For the [mounting](/wiki/linux/filesystems.md#mounting) to work two directories
For the [mounting](/wiki/linux/disk-management.md#mounting) to work two directories
are required.
One to mount the `dislocker-file` (`/mnt/bitlocker`) and one to mount the
[windows volume](/wiki/linux/ntfs.md#manual-mounting) (`/mnt/windows`).
@ -35,10 +35,10 @@ or another mount point as described in the
### Automatic Mounting at Boot
Using [fstab](/wiki/linux/filesystems.md#mounting) the partition encrypted with
Using [fstab](/wiki/linux/disk-management.md#mounting) the partition encrypted with
Bitlocker can be automatically mounted.
The following lines have to be adapted and written into
[`/etc/fstab`](/wiki/linux/filesystems.md#mounting).
[`/etc/fstab`](/wiki/linux/disk-management.md#mounting).
In this case the intermediary dislocker file `dislocker-file` is mounted to
`/mnt/bitlocker`.

@ -171,7 +171,7 @@ Additionally the following lines has to be adapted and added to the file
`<mapping location>` has to be the same as chosen in the step before.
`<UUID of encrypted volume>` is the
[universally unique identifier](/wiki/linux/filesystems.md#universally-unique-identifier)
[universally unique identifier](/wiki/linux/disk-management.md#universally-unique-identifier)
of the volume.
`<location of key file>` describes the location where to find the key file
created in the previous step.

@ -1,50 +0,0 @@
# File Systems
File systems control how data on a drive is stored.
- [NTFS](./ntfs.md) is a proprietary file system used by Windows which can
additionally be encrypted with [Bitlocker](./dislocker.md).
- [Samba](./samba.md) is free windows interoperability software that is not a
classic file system can be mounted so it will be mentioned here
- [DM-Crypt] is an encryption service. Volumes encrypted with it follow a
special decryption process.
## Mounting
Mounting a file system makes the files of it accessible to the user.
The command `mount` is used to manually and temporarily mount file systems.
Automatic mounting is done by changing the file `/etc/fstab`.
The exact guide on how to mount specific file systems can be found in their
respecitive wiki entries.
The following describes the general basics of mounting temporarily and
persistently.
The basic mount command for temporarily accessing a file system is the
following:
`mount <path to partition> <path to mount point>`
All partitions can be found at `/dev` and the standard mount point is `/mnt` and
its subfolders.
For automatic mounting the following line has to be adapted and added to the
file `/etc/fstab`
`<specified partition> <path to mount point> <file system> <additional options> <dump flag> <fsck order>`
The partition can be specified by [UUID](#universally-unique-identifier).
The file system varies and a file system specific guide on how to mount them
can be found in their respective entries.
The dump flag signals if the file system should be dumped.
The `fsck` order signals if a file system should be checked at boot.
Boot partitions should be flagged with a `1` for this reason, otherwise `0`.
## Universally Unique identifier
Universally Unique identifier (UUID) are identifiers for informations on
computer systems.
Most notably they are used to identify file systems.
This way the UUID of a file system can be used to identify and
[mount it](#mounting) persistently and correctly.
By listing the directory `/dev/disk/by-partuuid` all mappings of devices to a
UUID are displayed.

@ -4,7 +4,7 @@
## Usage
### Create VG for proxmox
### Create Volume Group for Proxmox
We will use `/dev/sdb` as our drive.
Setup the disk for the physical volume with `sgdisk -N 1 /dev/sdb`.
@ -15,7 +15,7 @@ This can be solved by removing the old partition table with `wipefs -a /dev/sdb`
And finally create the volume group `vgcreate vmdata /dev/sdb`.
Then follow the guide in proxmox on how to connect a `vg` to proxmox.
### Add Drive to existing volume group
### Add Physical Volume to Existing Volume Group
First format the disk so that it has one partition (we will assume its called
`/dev/sdc1`).
@ -26,7 +26,24 @@ pvcreate /dev/sdc1
vgextend <name of your volume group> /dev/sdc1
```
### Resize a physical volume
### Remove Physical Volume
Before removing a physical volume it has to be confirmed that it is not part of
any volume group.
This can be done by running `sudo pvs` and confirm it is not listed for any
logical volumes.
If it is [a later section](#shrink-size-of-a-logical-volume) how the physical
volume can be completely emptied and removed from the logical volume.
A physical volume can be removed by running the following command:
```sh
sudo pvremove <path to physical volume>
```
`<path to physical volume>` is the physical volume that will get removed.
### Resize a Physical Volume
To increase the size of a physical volume you have to have free free space
in the partition containing the physical volume.
@ -38,7 +55,7 @@ encrypted with LUKS a guide is available in
To resize the physical volume to the size of the containing volume run:
`pvresize /dev/mapper/<name of physical volume>`
### Increase size of a logical volume
### Increase Size of a Logical Volume
To increase the size of the logical volume you have to have free space in the
according volume group. You can check that by running: `vgdisplay`.
@ -61,3 +78,89 @@ Now you need to extend the filesystem with:
```sh
resize2fs /dev/<volume group>/<logical volume>
```
### Shrink Size of a Logical Volume
When trying to shrink a logical volume caution is advised as data can easily be
destroyed by mistyping commands of paths.
This section is based on a guide given by
[telcoM](https://unix.stackexchange.com/questions/591389/how-to-remove-a-disk-from-an-lvm-partition).
First of all the volumes have to be unmounted and not used by any programs or
services other than the following commands.
If the volume to shrink is the root volume it has to be done offline.
For that a simple installation stick is enough.
[The Arch Linux entry](/wiki/linux/arch-linux/arch-linux.md#installation-medium)
describes the creation of such a boot stick.
Afterwards the operating system has to be booted from the just created stick or
a comparable device.
For non-root volumes this extra step can be skipped.
The volume group needs to be activated by running the command
`sudo vgchange -ay <volume group>`.
`<volume group>` is the name of the volumegroup that features the logical volume
to shrink.
Then the file system needs to be resized.
For safety reasons make the file system exactly as big or smaller than the
future logical volume.
The process of shrinking a filesystem is explained in the
[file system entry](/wiki/linux/disk-management.md#shrinking-a-file-system).
The partition to shrink in this case is the logical volume.
This is the only step that needs to be done offline for root volumes.
Rebooting to the root volume at this moment is advised.
The next step will shrink the logical volume itself.
This will be done by running the following command:
```sh
sudo lvreduce -L <new size of logical volume> /dev/mapper/<volume group>-<logical volume>
```
Again this statement has to be adapted accordingly.
`new size of logical volume` describes the new size the logical volume will have
after successful completion of the command.
It is important for this to be exactly the same or larger than the size given
into the resizing of the file system with `resize2fs`.
### Remove Physical Volume from Volume Group
This section describes the removal of a physical volume from a logical volume.
First the command `vgs <volume group>` has to be run.
`<volume group>` is the name of the volume group belonging to the logical volume
a physical volume should be removed from.
It has to be ensured, that enough free space (`VFree`) on all physical volumes
(except the ones to remove) is available to remove a physical volume from the
volume group.
There has to be equal or more free space than the size (`VSize`) of the physical
volume that will be removed.
Otherwise an [earlier section](#shrink-size-of-a-logical-volume) explains how to
shrink a logical volume.
The logical volume has to be shrunk according to the described ration between
`VFree` and `VSize`.
The following command will distribute the contents of a physical volume onto
other physical volumes available:
```sh
sudo pvmove <path to physical volume>
```
`<path to physical volume>` is the physical volume that will get emptied and
later removed from the logical volume.
Afterwards the physical volume is emptied and can be removed from the logical
volume by running the following command:
```sh
sudo vgreduce <logical volume> <path to physical volume>
```
`<logical volume>` is the name of the logical volume.
After this command the physical volume is no longer a part of it.
If no longer used the empty physical volume can then be removed as described in
the [according section](#remove-physical-volume).
Afterwards the file system can be matched to the logical volume so it takes up
the full new size.
This is explained in

@ -1,6 +1,6 @@
# NTFS
NTFS is the proprietary [file system](./filesystems.md) of Windows.
NTFS is the proprietary [file system](./disk-management.md) of Windows.
## Setup
@ -9,7 +9,7 @@ distributions - has to be installed.
## Usage
When [mounting](/wiki/linux/filesystems.md#mounting) a
When [mounting](/wiki/linux/disk-management.md#mounting) a
[Bitlocker encrypted drive](./dislocker.md) there are additional steps that have
to be taken to decrypt the device.

Loading…
Cancel
Save