Sunday, February 18, 2018

Creating EXT4 partition from unused partition with LVM

This is a quick guide to create a usable EXT4 partition from an unused disk partition with LVM in your Proxmox server

In this example my UNUSED DISK PARTITION is on /dev/sda4

*** THIS WILL ERASE ALL CONTENT IN /dev/sda4 ***


STEP 1 - PREPARE THE PARTITION TO TYPE: linux LVM

fdisk /dev/sda

change partition type by entering 't', '4', '31'

't' is for changing partition type
'4' is to select partition #4
'31' is to select Linux LVM partition type

check to make sure partition type has been set properly by pressing 'p' then ENTER, you should see something like this (I highlighted partition 4 which shows Linux LVM:

/dev/sda1      2048      4095      2048     1M BIOS boot
/dev/sda2      4096    528383    524288   256M EFI System
/dev/sda3    528384  33554432  33026049  15.8G Linux LVM
/dev/sda4  33556480 586072334 552515855 263.5G Linux LVM


STEP 2 - CREATE PV, then VG, then LV 


Every LVM volume involves creating these 3 types of sub lvm systems:

1. Physical volume (PV)
2. Volume group (VG) (I named mine vg_ssd_data)
3. Logical volume (LV) (I named mine lv_ssd_data)

Type the following commands:

pvcreate /dev/sda4

vgcreate vg_ssd_data /dev/sda4

lvcreate -l 100%FREE -n lv_ssd_data vg_ssd_data

lvs   (this command is optional - only to display your logical volumes - see below)

  LV          VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data        pve         twi-a-tz--   8.25g             0.00   0.55
  root        pve         -wi-ao----   3.75g
  swap        pve         -wi-ao----   1.88g
  lv_ssd_data vg_ssd_data -wi-a----- 263.46g


STEP 3 - GET YOUR DEVICE MAPPER NAME

Enter the following command to display all your logical volumes, to get your device mapper path.
(I highlighted my logical volume which shows the device mapper path)

lvdisplay

  --- Logical volume ---
  LV Path                /dev/vg_ssd_data/lv_ssd_data
  LV Name                lv_ssd_data
  VG Name                vg_ssd_data
  LV UUID                dDqnRP-1wt2-UHcI-gE3T-WYle-HtNB-cWbfis
  LV Write Access        read/write
  LV Creation host, time e1, 2018-02-18 10:18:07 -0600
  LV Status              available
  # open                 0
  LV Size                263.46 GiB
  Current LE             67445
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

  --- Logical volume ---
  LV Path                /dev/pve/swap
  LV Name                swap
  VG Name                pve
  LV UUID                QzAL07-mdzD-RoH5-ulXa-gwGt-FtTN-XRhA4q
  LV Write Access        read/write
  LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
  LV Status              available
  # open                 2
  LV Size                1.88 GiB
  Current LE             480
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/pve/root
  LV Name                root
  VG Name                pve
  LV UUID                2LuMFi-XzY9-TWNf-uiH3-qdAc-Y5Xa-r6ajdz
  LV Write Access        read/write
  LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
  LV Status              available
  # open                 1
  LV Size                3.75 GiB
  Current LE             960
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Name                data
  VG Name                pve
  LV UUID                hBfLjZ-Zqib-TMwJ-7dQh-qBrJ-7XHZ-D1G2lQ
  LV Write Access        read/write
  LV Creation host, time proxmox, 2017-12-02 20:53:30 -0600
  LV Pool metadata       data_tmeta
  LV Pool data           data_tdata
  LV Status              available
  # open                 0
  LV Size                8.25 GiB
  Allocated pool data    0.00%
  Allocated metadata     0.55%
  Current LE             2112
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4


STEP 4 - MAKE THE EXT4 PARTITION

The command below will create the EXT4 partition:

mkfs.ext4 /dev/vg_ssd_data/lv_ssd_data

the result should look similar to this:

mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 69063680 4k blocks and 17268736 inodes
Filesystem UUID: 123a79fb-226e-45b2-ab97-bdd8df335538
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done


STEP 5 - CREATE THE DIRECTORY WHERE WE WILL MOUNT THE PARTITION

The following 2 commands will create a directory and set its partition to 777 (all access - this is just for my example - you probably want to restrict your permission)

mkdir /mnt/ssd_data
chmod -R 777 /mnt/ssd_data


STEP 6 - GET UUID USING COMMAND BLKID

The following command 'blkid' will show you the UUID which you will need to mount your newly created partition.

blkid

My result looks like:

/dev/sda2: UUID="72B0-472C" TYPE="vfat" PARTUUID="43003f1e-9cbd-461c-ba1f-b288196eaf8d"
/dev/sda3: UUID="ceYVkY-WxbN-UQME-i6Gt-frKB-rDeW-StrMMz" TYPE="LVM2_member" PARTUUID="ac2082b2-aed1-432d-8102-86246ab4d738"
/dev/mapper/pve-swap: UUID="d44d4cfc-c6b2-4f75-b24a-a6ec99e6d748" TYPE="swap"
/dev/mapper/pve-root: UUID="d41800f7-bf3a-42fb-bbd2-9f4519d99bd6" TYPE="ext4"
/dev/sda1: PARTUUID="491629a5-bea8-4a61-84a7-b4610e8b4607"
/dev/sda4: UUID="Iv347n-th9t-fC3v-UpUc-bHFN-LKOA-shD5Eg" TYPE="LVM2_member" PARTUUID="bfc4c91b-148b-429c-a9eb-b6d80a1dd685"
/dev/sdb: PTUUID="05ca81c9-9745-4fb2-bd15-ced9e1525169" PTTYPE="gpt"
/dev/sdc: PTUUID="8e2952c8-96a6-4c41-a9a8-0ae9cde93182" PTTYPE="gpt"
/dev/mapper/vg_ssd_data-lv_ssd_data: UUID="123a79fb-226e-45b2-ab97-bdd8df335538" TYPE="ext4"


STEP 6 - ADDING YOUR PARTITION TO FSTAB

The following command, you will edit your FSTAB (filesystem table) to add a line which will tell your computer to AUTOMATICALLY MOUNT the partition everytime the computer starts (cold / warm start)

nano /etc/fstab

add the following line (note the UUID in RED and DIRECTORY in BLUE):

UUID=123a79fb-226e-45b2-ab97-bdd8df335538 /mnt/ssd_data ext4 defaults,noatime,nodiratime,noacl,data=writeback,barrier=0,nobh,errors=remount-ro 0 2



STEP 7 - FINALLY! MOUNT AND CHECK YOUR PARTITION FREE DISK SPACE

The following command will mount all your partition by reading your settings from the filesystem table (/etc/fstab)

mount -a

(mount -a does not have any output when successful)

The following command will show FREE DISK SPACE for all your MOUNTED PARTITIONS:

df -h

Filesystem                           Size  Used Avail Use% Mounted on
udev                                  24G     0   24G   0% /dev
tmpfs                                4.8G  9.2M  4.8G   1% /run
/dev/mapper/pve-root                 3.7G  1.8G  1.7G  52% /
tmpfs                                 24G   45M   24G   1% /dev/shm
tmpfs                                5.0M     0  5.0M   0% /run/lock
tmpfs                                 24G     0   24G   0% /sys/fs/cgroup
/dev/fuse                             30M   24K   30M   1% /etc/pve
tmpfs                                4.8G     0  4.8G   0% /run/user/0
/dev/mapper/vg_ssd_data-lv_ssd_data  259G   61M  246G   1% /mnt/ssd_data






No comments:

Post a Comment