Linux read external disk data, cannot mount - linux

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 ?

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'

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

[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}'

Setup a RAID1 with MSADM - unexpected type for second hd in lsblk

I tried to setup a RAID1 with mdadm on a Raspberrypi 4. I'm not sure if the raid is configured correctly.
Here is what lsblk shows before setup:
pi#e11:/dev $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
sdb 8:16 0 931.5G 0 disk
mmcblk0 179:0 0 59.5G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 59.2G 0 part /
Here is what I did:
pi#e11:/dev $ sudo parted /dev/sda "mklabel gpt"
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.
pi#e11:/dev $ sudo parted /dev/sdb "mklabel gpt"
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
Information: You may need to update /etc/fstab.
pi#e11:/dev $ sudo parted /dev/sda "mkpart primary ext4 1M -1"
Information: You may need to update /etc/fstab.
pi#e11:/dev $ sudo parted /dev/sdb "mkpart primary ext4 1M -1"
Information: You may need to update /etc/fstab.
pi#e11:/dev $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
└─sda1 8:1 0 931.5G 0 part
sdb 8:16 0 931.5G 0 disk
└─sdb1 8:17 0 931.5G 0 part
mmcblk0 179:0 0 59.5G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 59.2G 0 part /
pi#e11:/dev $ sudo parted /dev/sda "set 1 raid on"
Information: You may need to update /etc/fstab.
pi#e11:/dev $ sudo parted /dev/sdb "set 1 raid on"
Information: You may need to update /etc/fstab.
pi#e11:/dev $ sudo parted -s /dev/sda print
Model: TOSHIBA External USB 3.0 (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 1000GB 1000GB primary raid
pi#e11:/dev $ sudo parted -s /dev/sdb print
Model: TOSHIBA External USB 3.0 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 1000GB 1000GB primary raid
pi#e11:/dev $ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
Lsblk after:
pi#e11:/dev $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 931.5G 0 disk
└─sda1 8:1 0 931.5G 0 part
└─md0 9:0 0 931.4G 0 raid1
sdb 8:16 0 931.5G 0 disk
└─sdb1 8:17 0 931.5G 0 part
mmcblk0 179:0 0 59.5G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 59.2G 0 part /
I would expect that sdb1 should also look like sda1, shouldn't it?
sda 8:0 0 931.5G 0 disk
└─sda1 8:1 0 931.5G 0 part
└─md0 9:0 0 931.4G 0 raid1
sdb 8:16 0 931.5G 0 disk
└─sdb1 8:17 0 931.5G 0 part
└─md0 9:0 0 931.4G 0 raid1
If i am right. What else can I do add sdb1 to the raid array?
Thanks in advance.
Christoph
As it turned out The power supply (15W) was not enough for Raspi 4 and the two disks. With an active USB hub everything works as expected now.

ec2 how to add more volume to exist device

I was trying to add more volume to my device
df -h
I get:
[root#ip-172-x-x-x ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 44K 3.8G 1% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
/dev/nvme0n1p1 7.8G 3.6G 4.2G 46% /
I wanna add all existing storage to /dev/nvme0n1p1
lsblk
I get
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 300G 0 disk
├─nvme0n1p1 259:1 0 8G 0 part /
└─nvme0n1p128 259:2 0 1M 0 part
I was trying to google around on aws instructions, still quite confuse. since most of the instruction is setting up brand new instance. While for my use case i cannot stop the instance.
i cannot do
mkfs
Also seems like the disk is already mount?? I guess i may misunderstand the meaning of mount...
since the filesystem is already there.
just wanna use all existing space.
Thanks for help in advance!!
your lsblk output shows that you have a 300G disk but your nvme0n1p1 is only 8G. You need to first grow your partition to fill the disk and then expand your filesystem to fill your partition:
Snapshot all ebs volumes you care about before doing any resize operations on them.
Install growpart
sudo yum install cloud-utils-growpart
Resize partiongrowpart /dev/nvme0n1 1
Reboot reboot now
Run lsblk and verify that the partition is now the full disk size
You may still have to run sudo resize2fs /dev/nvme0n1 to expand the filesystem

Resources