It will cover the basics of Linux which is a must for every Computer student. For example, Becoming an administrator of IT infrastructure and also important for developers of any language.
-
- sudo fdisk /dev/sdb (replace /dev/sdb with your disk device)
- n (create a new partition)
- p (make it a primary partition)
- 1 (assign it as partition number 1)
- 2048 (set the first sector)
- +100G (specify the partition size)
- t (change partition type)
- 8e (LVM partition type)
- w (make revisions)
When adding a new hard drive to an Ubuntu server and creating LVM (Logical Volume Manager) on it, follow these steps:
-
- sudo apt-get install lvm2 (if not already installed)
-
- sudo pvcreate /dev/sdb (replace /dev/sdb with your new disk device)
-
- sudo vgcreate myvg /dev/sdb (replace myvg with your desired VG name)
-
- sudo lvcreate -n mylv -l +100%FREE myvg
- sudo lvcreate -n mylv -L 100G myvg (replace mylv with your desired LV name and 100G with your desired size)
-
- sudo mkfs.ext4 /dev/myvg/mylv
- sudo mount /dev/myvg/mylv /mnt
-
- sudo lsblk -o +UUID (get the UUID of the LV)
- sudo UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\t/mnt/data\text4\tdefaults\t0\t0 (\t means press a tab)
- e.g. UUID=30dbec69-b3d0-4ac3-9619-cf4a534bca09 /mnt ext4 defaults 0 0
-
- df -h
- ls -al /mnt (files are shown)
- Verify Partition on New Disk (/dev/sdd): This step checks for the newly created partition.
- Create Physical Volume (PV): This command creates a PV using the partition.
- Extend Volume Group (VG): This step expands the VG to include the new PV.
- Identify Root Logical Volume (LV): Locate your root LV for resizing.
- Resize the Logical Volume (LV): This command extends the LV using available free space.
- Verify Available Space (Optional): (Optional step) Check if unallocated space is visible within the partition.
- Identify Filesystem Type: Determine the filesystem type of your root partition (e.g., ext4, xfs).
- Resize the Filesystem: Use the appropriate command (ext4:
resize2fs
, xfs:xfs_growfs
) to resize the filesystem and utilize the extended space. - Verify Resize (Optional): (Optional step) Confirm that the size of your root partition has increased.
Verify Partition on New Disk
fdisk -l /dev/sdd
# Note the whole disk 5GB partitioned with name: /dev/sdd1
Create Physical Volume (PV)
pvcreate /dev/sdd1
Extend Volume Group (VG)
Add the new physical volume to the existing volume group :
vgextend <your_vg_name> /dev/sdd1
# Example: ubuntu-vg is root volum group
vgextend ubuntu-vg /dev/sdd1
Identify Logical Volume (LV)
List all logical volumes and locate the root LV:
lvdisplay
Resize Logical Volume (LV)
- Copy the path to the LV you want to extend (e.g., /dev/ubuntu-vg/ubuntu-lv)
- Extend the logical volume:
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv or
lvextend -L +5G /dev/mapper/ubuntu--vg-ubuntu--lv
Resize Filesystem
- Check the disk usage:
lsblk
df -h
- Resize the Filesystem:
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
- Verify the updated disk usage:
df -h
# Example output:
# Note: The available space has increased from 24GB to 29GB.
Only Remove LVM but /dev/sdb1 is remains available for you. This is The Step by Step Style guide for Ubuntu Server.
Before deleting any partitions, make sure to backup your important data to an external drive or cloud storage.
Open a terminal and run the command:
sudo lvdisplay
Sudo umount /mnt
This will list all the LVM partitions on your system.
Note the name of the partition you want to delete (e.g., "my_partition").
Run the command:
sudo lvchange -an /dev/my_partition
e.g. lvchange -an /dev/mapper/myvg-mylv
Replace "my_partition" with the actual name of the partition.
Run the command:
sudo lvremove /dev/my_partition
e.g. lvremove /dev/mapper/myvg-mylv
Replace "my_partition" with the actual name of the partition.
If the partition was part of a VG, you need to remove the VG as well. Run the command:
sudo vgremove my_vg
e.g. vgremove myvg
Replace "my_vg" with the actual name of the VG.
If the partition was on a PV, you need to remove the PV as well. Run the command:
sudo pvremove /dev/sda1
Replace "/dev/sda1" with the actual device path of the PV.
Run the command:
sudo vgscan --mknodes
This will update the LVM configuration and remove any remaining references to the deleted partition.
Run the command:
sudo lvdisplay
lsblk