How to manage Linux File System?¶
New disk Adding¶
After adding a disk to the service, the disk will be added automatically to the virtual machine.
The lsblk
command on Linux lists block devices.
Before adding:
[root@weathered-firefly-vs ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─fedora-root 253:0 0 48G 0 lvm /
└─fedora-swap 253:1 0 1G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sdc 8:32 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 376K 0 rom
zram0 252:0 0 1.9G 0 disk [SWAP]
After after adding:
[root@weathered-firefly-vs ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─fedora-root 253:0 0 48G 0 lvm /
└─fedora-swap 253:1 0 1G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sdc 8:32 0 50G 0 disk
sdd 8:48 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 376K 0 rom
zram0 252:0 0 1.9G 0 disk [SWAP]
New Partition Creation¶
-
Using
fdisk
, create a new partition on the/dev/sdc
device. Entern
, to create a new partition:[root@weathered-firefly-vs ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.36). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x58db5961. Command (m for help): n
-
Now choose
p
to create a new primary partition.Note
Your system can only have 4 primary partitions on this disk. If you've already reached this limit, create an extended partition.
-
Choose the partition number and its first and last sectors, if you hit
Enter
, then by default new partition will use all available disk space. -
Finally, you need to write the partitions to disk with the
w
command.Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Check whether the partition was created with the
lsblk
command.[root@weathered-firefly-vs ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─fedora-root 253:0 0 98G 0 lvm / └─fedora-swap 253:1 0 1G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk └─sdb1 8:17 0 50G 0 part └─fedora-root 253:0 0 98G 0 lvm / sdc 8:32 0 50G 0 disk └─sdc1 8:33 0 50G 0 part sdd 8:48 0 50G 0 disk sr0 11:0 1 1024M 0 rom sr1 11:1 1 376K 0 rom zram0 252:0 0 1.9G 0 disk [SWAP]
Expanding Disk Storage¶
Enhancing Physical Volume, Volume Group, Logical Volume, and XFS Filesystem with Additional Partition.
-
First, enter the
df -hT
command and select the system partition from the list that you want to extend.
For example/dev/mapper/fedora-root
[root@weathered-firefly-vs ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 786M 1000K 785M 1% /run /dev/mapper/fedora-root xfs 98G 2.8G 96G 3% / tmpfs tmpfs 2.0G 4.0K 2.0G 1% /tmp /dev/sda1 xfs 1014M 248M 767M 25% /boot tmpfs tmpfs 393M 4.0K 393M 1% /run/user/0
-
With the help of
pvs
command, you can find out how your Physical Volume is called. ThePFree
column shows the amount of free space. -
Now create a physical volume as the basis for your LVM. Here
/dev/sdc1
is the created partition. -
With the help of
vgs
command, you can find out how your Volume Group is called. TheVFree
column shows the amount of free space. -
Then extend that Volume Group
fedora
by adding the newly created physical volume to it usingvgextend
command, check whether the changes can be applied again with thevgs
command. -
With the help of
lvs
command, you can find out how your Volume Group is called. -
To extend the logical volume execute command:
lvextend
[root@weathered-firefly-vs ~]# lvextend -l +100%FREE /dev/mapper/fedora-root Size of logical volume fedora/root changed from 97.99 GiB (25086 extents) to <147.99 GiB (37885 extents). Logical volume fedora/root successfully resized. [root@weathered-firefly-vs ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root fedora -wi-ao---- <147.99g swap fedora -wi-ao---- 1.00g
-
Finally, resize the
XFS
file system to a logical volume using thexfs_growfs
command. If you are usingext4
filesystem, use the utilityresize2fs
.[root@weathered-firefly-vs ~]# df -hT /dev/mapper/fedora-root Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/fedora-root xfs 98G 2.8G 96G 3% / [root@weathered-firefly-vs ~]# xfs_growfs / meta-data=/dev/mapper/fedora-root isize=512 agcount=15, agsize=1834752 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=25688064, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=3583, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 25688064 to 38794240
Execute
df -hT
to confirm that new disk size is available to the Virtual Machine.
Expanding the 'root' Partition: Ubuntu Server¶
The list of commands to extend the 'root' partition Ubuntu Server.
Suitable for 18.04 LTS and 20.04 LTS.
> \# growpart /dev/sda/ 3
> \# pvresize /dev/sda3/
> \# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv/
> \# resize2fs /dev/ubuntu-vg/ubuntu-lv/
Expanding the 'root' Partition: Ubuntu Desktop 20.04 LTS¶
> \# growpart /dev/sda/ 2
> \# growpart /dev/sda/ 5
> \# pvresize /dev/sda5/
> \# lvextend -l +100%FREE /dev/mapper/vgubuntu-root/
> \# resize2fs /dev/vgubuntu/root/