How do i assign a new disk/LV to the root folder "/" which has been already mounted by sdb2 partition? - linux

[root#my-linux-vm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 16G 0 disk
└─sda1 8:1 0 16G 0 part
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 2M 0 part
└─sdb2 8:18 0 10G 0 part /
sdc 8:32 0 12G 0 disk
└─sdc1 8:33 0 12G 0 part
└─vg_new_root-lv0 252:0 0 11G 0 lvm
sr0 11:0 1 1024M 0 rom
Given the above partition/disk situation,
can i mount the 'vg_new_root-lv0' LV onto the root ("/")folder in order to extend the root capacity beyond sdb2 space?

The short answer is No, based on your current configuration.
Due to the fact that the / root filesystem is not part of LVM there is no easy way to expand its capacity.
My suggestion would be to run a disk space script to confirm what is the directory or service that is using a significant amount of the disk space and then (if possible) move that data into the new sdc1 drive / vg_new_root-lv0 Logical Volume, it needs to be formatted and mounted to be ready to use, once mounted you can stop your application and then move all the data to that new filesystem (i.e /mnt/data), after you confirm that the data has been moved you can then start your application, test and then remove the data from the original location under the sdb2 disk / root / filesystem to free up space.
Run the below one liner to get a disk usage report and confirm what you can remove / compress / move.
echo -n "Type Filesystem: ";read FS;NUMRESULTS=20;resize;clear;date;df -h $FS;echo "Largest Directories:"; du -x $FS 2>/dev/null| sort -rnk1| head -n $NUMRESULTS| awk '{printf "%d MB %s\n", $1/1024,$2}';echo "Largest Files:"; nice -n 19 find $FS -mount -type f -ls 2>/dev/null| sort -rnk7| head -n $NUMRESULTS|awk '{printf "%d MB\t%s\n", ($7/1024)/1024,$NF}'

Related

Increate xfs partition size lvm

I am trying to increase xfs disk lvm but I am missing something
"/" size is 70 GB and I want to enlarge it to 90GB .
I enlarged the underlying /dev/sda size to 140gb (it was 120gb) So I have enough space to add.
Also - vgdisplay lvdisplay shows nothing.
Any idea ?
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 140G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 137.2G 0 part
├─rhel_dent--sasacprd01-root 253:0 0 70G 0 lvm /
├─rhel_dent--sasacprd01-swap 253:1 0 7.9G 0 lvm [SWAP]
└─rhel_dent--sasacprd01-home 253:2 0 40.5G 0 lvm /home
sr0
[root#sasacprd01 tmp]# xfs_growfs -D 23470080 /
4096 blocks 18350080
data size 23470080 too large, maximum is 18350080
SO -that didnt work.. enter code here
Thank you
Try this.
lvextend -L +90G /dev/mapper/rhel_dent--sasacprd01-root
xfs_growfs /dev/mapper/rhel_dent--sasacprd01-root

Linux Get physical location from file and write contents

I want to get the physical location of linux file, /root/f.txt and write(overwrite) some contents of file
File is /root/f.txt
lsblk command output:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 16G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 15G 0 part
├─rhel-root 253:0 0 13.4G 0 lvm /
└─rhel-swap 253:1 0 1.6G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
sr0 11:0 1 1024M 0 rom
Contents of file:
#cat /root/f.txt
This is new file ha ha ha
From 'filefrag' command I get pysical location of file
#filefrag -v /root/f.txt
Filesystem type is: 58465342
File size of /root/f.txt is 26 (1 block of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 0: 1761827.. 1761827: 1: eof
/root/f.txt: 1 extent found
Here physical block starts at 1761827 and 1 block is of 4096.
So physical location of file would be: 1761827 * 4096 = 7216443392
I have only '/dev/sda' and I am trying to write at location 7216443392 with dd command as:
#sudo dd seek=7216443392 if=/dev/zero of=/dev/sda count=1 obs=1
1+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00699863 s, 73.2 kB/s
But when I saw contents of file /root/f.txt, output is still same
#cat /root/f.txt
This is new file ha ha ha
So either the physical location is not correct, or I do something wrong with dd. Please suggest.
The initial cat pulls the file into the page cache. Then, you directly write to the block device using dd. At this point, the kernel has no reason to believe the page in memory is not consistent with disk, so the new contents you write to the block device are not reflected when you cat after dd.
To see the new data written using dd, sync(1) and drop the page cache before running dd:
sync
sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'

Linux read external disk data, cannot mount

I just received a hard disk from other people and it includes some data. I want to read the data inside this disk. However, when I try to mount it, it shows:
~ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 217G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 16G 0 part [SWAP]
sdc 8:32 0 74.6G 0 disk
sr0 11:0 1 1024M 0 rom
~ sudo mount /dev/sdc /media/new
mount: /dev/sdc: can't read superblock
~ udisksctl mount -b /dev/sdc
Object /org/freedesktop/UDisks2/block_devices/sdc is not a mountable filesystem.
So what can I do to read the data inside this disk? I am not sure whether I can use command like mkfs.ext4 /dev/sdc, which seems will initialize the disk and erase the data.
Have you tried to use gparted to get some infos ?

Map lvm volume to Physical volume

lsblk provides output in this fornat:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 300G 0 disk
sda1 8:1 0 500M 0 part /boot
sda2 8:2 0 299.5G 0 part
vg_data1-lv_root (dm-0) 253:0 0 50G 0 lvm /
vg_data2-lv_swap (dm-1) 253:1 0 7.7G 0 lvm [SWAP]
vg_data3-LogVol04 (dm-2) 253:2 0 46.5G 0 lvm
vg_data4-LogVol03 (dm-3) 253:3 0 97.7G 0 lvm /map1
vg_data5-LogVol02 (dm-4) 253:4 0 97.7G 0 lvm /map2
sdb 8:16 0 50G 0 disk
for a mounted volume say /map1 how do i directly get the physical volume associated with it. Is there any direct command to fetch the information?
There is no direct command to show that information for a mount. You can run
lvdisplay -m
Which will show which physical volumes are currently being used by the logical volume.
Remember, thought, that there is no such thing as a direct association between a logical volume and a physical volume. Logical volumes are associated with volume groups. Volume groups have a pool of physical volumes over which they can distribute any volume group. If you always want to know that a given lv is on a given pv, you have to restrict the vg to only having that one pv. That rather misses the point. You can use pvmove to push extents off a pv (sometimes useful for maintenance) but you can't stop new extents being created on it if logical volumes are extended or created.
As to why there is no such potentially useful command...
LVM is not ZFS. ZFS is a complete storage and filesystem management system, managing both storage (at several levels of abstraction) and the mounting of filesystems. LVM, in contrast, is just one layer of the Linux Virtual File System. It provides a layer of abstraction on top of physical storage devices and makes no assumption about how the logical volumes are used.
Leaving the grep/awk/cut/whatever to you, this will show which PVs each LV actually uses:
lvs -o +devices
You'll get a separate line for each PV used by a given LV, so if an LV has extents on three PVs you will see three lines for that LV. The PV device node path is followed by the starting extent(I think) of the data on that PV in parentheses.
I need to emphasize that there is no direct relation between a mountpoint (logical volume) and a physical volume in LVM. This is one of its design goals.
However you can traverse the associations between the logical volume, the volume group and physical volumes assigned to that group. However this only tells you: The data is stored on one of those physical volumes, but not where exactly.
I couldn't find a command which can produce the output directly. However you can tinker something using mount, lvdisplay, vgdisplay and awk|sed:
mp=/mnt vgdisplay -v $(lvdisplay $(mount | awk -vmp="$mp" '$3==mp{print $1}') | awk '/VG Name/{print $3}')
I'm using the environment variable mp to pass the mount point to the command. (You need to execute the command as root or using sudo)
For my test-scenario it outputs:
...
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
...
VG Size 992.00 MiB
PE Size 4.00 MiB
Total PE 248
Alloc PE / Size 125 / 500.00 MiB
Free PE / Size 123 / 492.00 MiB
VG UUID VfOdHF-UR1K-91Wk-DP4h-zl3A-4UUk-iB90N7
--- Logical volume ---
LV Path /dev/vg1/testlv
LV Name testlv
VG Name vg1
LV UUID P0rgsf-qPcw-diji-YUxx-HvZV-LOe0-Iq0TQz
...
Block device 252:0
--- Physical volumes ---
PV Name /dev/loop0
PV UUID Qwijfr-pxt3-qcQW-jl8q-Q6Uj-em1f-AVXd1L
PV Status allocatable
Total PE / Free PE 124 / 0
PV Name /dev/loop1
PV UUID sWFfXp-lpHv-eoUI-KZhj-gC06-jfwE-pe0oU2
PV Status allocatable
Total PE / Free PE 124 / 123
If you only want to display the physical volumes you might pipe the results of the above command to sed:
above command | sed -n '/--- Physical volumes ---/,$p'
dev=$(df /map1 | tail -n 1|awk '{print $1}')
echo $dev | grep -q ^/dev/mapper && lvdisplay -m $dev 2>/dev/null | awk '/Physical volume/{print $3}' || echo $dev

missing partition in server centos 6.1

I used the command df-h on my centos 6.1
here's the output
[root#localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 2.3G 45G 5% /
tmpfs 5.9G 0 5.9G 0% /dev/shm
/dev/sda1 485M 35M 425M 8% /boot
/dev/mapper/VolGroup-lv_home
2.0T 199M 1.9T 1% /home
i found out that the hard disk is two terabyte. but when I used the command cat /proc/partitions | more
here's the output
[root#localhost sysconfig]# cat /proc/partitions | more
major minor #blocks name
8 0 4293656576 sda
8 1 512000 sda1
8 2 2146970624 sda2
253 0 52428800 dm-0
253 1 14417920 dm-1
253 2 2080120832 dm-2
you could see on the first line. it is 4396.7 GB . why is it i could only see is 2TB? how could i find my missing another 2TB and make it a partition.
I also use the command lsblk
here is the output
[root#localhost ~]# lblsk
-bash: lblsk: command not found
[root#localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO MOUNTPOINT
sda 8:0 0 4T 0
ââsda1 8:1 0 500M 0 /boot
ââsda2 8:2 0 2T 0
ââVolGroup-lv_root (dm-0) 253:0 0 50G 0 /
ââVolGroup-lv_swap (dm-1) 253:1 0 13.8G 0 [SWAP]
ââVolGroup-lv_home (dm-2) 253:2 0 2T 0 /home
sr0 11:0 1 1024M 0
using the parted /dev/sda i type the print free command
here's the output
(parted) print free
Model: DELL PERC 6/i (scsi)
Disk /dev/sda: 4397GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 525MB 524MB primary ext4 boot
2 525MB 2199GB 2198GB primary lvm
2199GB 4397GB 2198GB Free Space
I was wrong, sorry. As you can see in parted print free output you have 2 MBR partitions - boot and lvm and 2198GB free space (last row).
If you want to use all of your space you have to use GPT partitions. These partitions as opposed to MBR partition that can only address up to 2TB, can address your whole disk and up to 8 ZiB (zebibytes).
You can try to convert MBR partition table to GPT (example 1, example 2), though I strongly recommend to backup your data.
You are using tools showing info from different layers of your system and interpreting it wrong.
df, according to man page, will display the space available on all currently mounted file systems.
/proc/partitions holds info about partitions on your drive - physical device. This file shows you size of your drive as number of blocks. Usually, on HDD block size is a size of sector - 512 bytes.
So, sda size of 4293656576 is size in blocks, not kilobytes.
4293656576 blocks = (4293656576 / 2 ) kilobytes = 2146828288 KiB = 2047.375 GiB, or 2198.352 GB.
Assuming 1 GiB = 1 * 2^30, 1 GB = 1 * 10^3.
If you want to see size of your disk use fdisk -l <device name>.

Resources