I accidentally removed a wrong folder using rm -rf, every tool I've tried tell me either I have no hard disk or that the filesystem is not found.
When I type df I get :
Filesystem Size Used Avail Use% Mounted on
/dev/simfs 25G 7.6G 18G 31% /
none 256M 12K 256M 1% /dev
But if I type debugfs -w /dev/simfs I get the error :
/dev/simfs: No such file or directory while opening filesystem
I'm using a VPS hosted by OVH, what's wrong with that filesystem ?
I have the same scenario/issue. To take the conversation a step further, I've also tried
tune2fs -l /dev/simfs
which outputs
tune2fs 1.42.9 (4-Feb-2014)
tune2fs: No such file or directory while trying to open /dev/simfs
Couldn't find valid filesystem superblock.
You'll get the same invalid superblock error if you try to scan an entire disk eg /dev/sda
Related
For those reaching here; Unfortunately I could not recover the data, after various tries and reproducing the problem it was too costy to keep trying, so we just used a past backup to recreate the information needed
A human error broke an 150G UFS filesystem (Solaris).
When trying to do a backup of the filesytem (c0t0d0s3) the ufsdump(1M) hasn't been correctly used.
I will explain the background that led to this ...
The admin used:
# ufsdump 0f /dev/dsk/c0t0d0s3 > output_1
root#ats-br000432 # ufsdump 0f /dev/dsk/c0t0d0s3 > output_1
Usage: ufsdump [0123456789fustdWwnNDCcbavloS [argument]] filesystem
This is a bad usage, so it created a file called output_1 with 0 bytes:
# ls -la output_1
-rw-r--r-- 1 root root 0 abr 12 14:12 output_1
Then, the syntax used was:
# ufsdump 0f /dev/rdsk/c0t0d0s3 output_1
Which wrote that 0 bytes file output_1 to /dev/rdsk/c0t0d0s3 - which was the partition slice
Now, interestingly, due to being a 0 bytes file, we thought that this would cause no harm to the filesystem, but it did.
When trying to ls in the mountpoint, the partition claimed there was an I/O error, when umounting and mounting again, the filesystem showed no contents, but the disk space was still showing as used just like it was previously.
I assume, at some point, the filesystem 'header' was affected, right? Or was it the slice information?
A small fsck try brings up this:
** /dev/rdsk/c0t0d0s3
** Last Mounted on /database
** Phase 1 - Check Blocks and Sizes
INCORRECT DISK BLOCK COUNT I=11 (400 should be 208)
CORRECT?
Disk block count / I=11
this seems that the command broke filesystem information regarding its own contents, right?
When we tried to fsck -y -F ufs /dev/dsk.. various files have been recovered, but not the dbf files we are after (which are GB sized)
What can be done now? Should I try every superblock information from newfs -N ?
EDIT: new information regarding partition
newfs output showing superblock information
# newfs -N /dev/rdsk/c0t0d0s3
Warning: 2826 sector(s) in last cylinder unallocated
/dev/rdsk/c0t0d0s3: 265104630 sectors in 43149 cylinders of 48 tracks, 128 sectors
129445,6MB in 2697 cyl groups (16 c/g, 48,00MB/g, 5824 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920,
Initializing cylinder groups:
.....................................................
super-block backups for last 10 cylinder groups at:
264150944, 264241184, 264339616, 264438048, 264536480, 264634912, 264733344,
264831776, 264930208, 265028640
How can I get which blocks a file uses that is located inside a virtual file system I created in Linux?
I'm trying to read the disk in raw mode and find out which blocks are allocated for a given file, inside a C program.
I suppose I need to parse the FAT table but I'm not sure how to proceed. Any ideas?
Any help is appreciated.
This is how I created the virtual file system:
sudo su
dd if=/dev/zero of=disk.img bs=1k count=100000
losetup /dev/loop0 disk.img
mkdosfs -s 1 -F 32 /dev/loop0 100000
mkdir /mnt/mydisk
mount -o loop -t vfat /home/a/os/p5/disk.img /mnt/mydisk
cd /mnt/mydisk
-do staff, add files and directories
It's looks like some sort of student assignment. Find nice description of FAT32 here.
I have partition structure like :
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda6 51606140 16939248 34142692 34% /
/dev/sda5 495844 72969 397275 16% /boot
/dev/sda7 113022648 57515608 49765728 50% /home
/dev/sda8 113022648 57515608 49765728 4% /mnt
while parsing directories content using readdir() - how to find out which file resides on what device?
readdir() invoked from root directory and parses the file name and prints its size.
like from device : /dev/sda6 and list the filenames under that partition.
When it reads contents from /home - it should display reading content from /dev/sda7 and list filenames
Please let me know,if you need more details/info
you can just do
df <file_name>
that will give you the device and partition for the particuar file
There is a st_dev member in struct stat, it should uniquely identify one partition.
Example in bash:
stat ~/.vimrc
File: `/home2//leonard/.vimrc' -> `local-priv/vimrc'
Size: 16 Blocks: 0 IO Block: 4096 symbolic link
Device: 802h/2050d Inode: 6818899 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 1024/ leonard) Gid: ( 1024/ leonard)
Access: 2012-06-22 16:36:45.341371003 +0300
Modify: 2012-06-22 16:36:45.341371003 +0300
Change: 2012-06-22 16:36:45.341371003 +0300
The stat utility does no additional magic. Here is strace -vvv output:
lstat64("/home2//leonard/.vimrc", {st_dev=makedev(8, 2), st_ino=6818899, st_mode=S_IFLNK|0777, st_nlink=1, st_uid=1024, st_gid=1024, st_blksize=4096, st_blocks=0, st_size=16, st_atime=2012/06/22-16:36:45, st_mtime=2012/06/22-16:36:45, st_ctime=2012/06/22-16:36:45}) = 0
0x0802 is major 8(sd) partition 2, so /dev/sda2
In order to map this to actual partitions you can iterate /proc/mounts and stat all the devices (first column). The contents of /proc/mounts is just like the output of mount(1) except it comes directly from the kernel. Some distros symlink /etc/mtab to /proc/mounts.
Or you can parse /proc/partitions:
$ cat /proc/partitions
major minor #blocks name
8 0 976762584 sda
8 1 3998720 sda1
8 2 972762112 sda2
Of course /dev/sda might not actually exist, the device could be using a long udev name like /dev/disk/by-uuid/c4181217-a753-4cf3-b61d-190ee3981a3f. Major/Minor numbers should be a reliable unique identifier of a partition.
I have apache virtualhost:
<VirtualHost IP_WAN:80>
ServerName test.localnet
DocumentRoot /srv/http/localnet/test/trunk/docroot
<Directory /srv/http/localnet/test/trunk/docroot>
Options Indexes
</Directory>
</VirtualHost>
The partition /srv is NFS3 mounted filesystem:
172.16.0.2:/srv /srv nfs nodev 0 0
at the server-side it's exported by:
/srv 172.16.0.0/255.255.255.240(rw,sync,no_subtree_check,no_root_squash)
directory /srv/http/localnet/test/trunk is absolute symlink to /srv/http/localnet/test/exports/trunk-v2
In the /srv/http/localnet/test/exports I have exported SVN trees (trunk-v1, trunk-v2, trunk-v3)
When I ask apache for http://test.localnet, it serves 200 OK and index from /srv/http/localnet/test/exports/trunk-v2/docroot
BUT:
If I remove symlink /srv/http/localnet/test/trunk and create a new one to another version (ln -s /srv/http/localnet/test/exports/trunk-v3 /srv/http/localnet/test/trunk), apache gives me 404 Not Found. It takes about seconds/minutes, then everything goes back to normal itself.
If I do ls -la /srv/http/localnet/test/trunk/ in this condition, it goes back to normal immediately. I think there's some problem with NFS cache, but I'm not able to find where exactly the problem occurs and how to prevent it. The symlink occupies the same inode as the previous one, both of targets (the old one and the new one) exists.
On the server side I have /srv partition mounted this way:
/dev/xvda7 on /srv type xfs (rw,nosuid,nodev)
I also use this parameters:
echo 262144 >/proc/sys/net/core/rmem_max
echo 262144 >/proc/sys/net/core/rmem_default
echo 262144 >/proc/sys/net/core/wmem_max
echo 262144 >/proc/sys/net/core/wmem_default
echo noop >/sys/block/xvda7/queue/scheduler
echo 0 >/sys/block/xvda7/queue/read_ahead_kb
I'm also trying to tune MTU of the network interface up to 9000, but without success.
Does anybody know, what's the problem? Why apache can't find the symlink until 'manually' refresh of the directory structure (ls)? Thanks a lot
Ondra
The solution seems to be:
http://publib.boulder.ibm.com/httpserv/manual70/mod/core.html#enablemmap
"With an NFS-mounted DocumentRoot, the httpd may crash due to a segmentation fault if a file is deleted or truncated while the httpd has it memory-mapped"
This is exactly the situation, when removing the symlink in the path to the page.
Hope it helps others :-)
For example, a sample df command output is
Filesystem MB blocks Free %Used Iused %Iused Mounted on
/dev/hd4 512.00 322.96 37% 4842 7% /
/dev/hd2 4096.00 717.96 83% 68173 29% /usr
/dev/hd9var 1024.00 670.96 35% 6385 4% /var
/dev/hd3 5120.00 0.39 100% 158 10% /tmp
Now if I specify something like /tmp/dummy.txt I should be able to get /dev/hd3 or just hd3.
EDIT : Thanks torek for the answer. But probing the /proc would become very tedious. Can anyone suggest me some system calls which can do the same internally?
df `pwd`
...Super simple, works, and also tells you how much space is there...
[stackuser#rhel62 ~]$ pwd
/home/stackuser
[stackuser#rhel62 ~]$ df `pwd`
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 250056240 196130640 41223408 83% /
[stackuser#rhel62 ~]$ cd isos
[stackuser#rhel62 isos]$ pwd
/home/stackuser/isos
[stackuser#rhel62 isos]$ df `pwd`
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 103216920 90417960 11750704 89% /mnt/sda5
[stackuser#rhel62 isos]$ df $(pwd)
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 103216920 90417960 11750704 89% /mnt/sda5
...which is the likely cause of the mount point query in the first place.
Note those are backticks, and the alternate (modern) method, providing further control over slashes and expansion is df $(pwd). Tested and traverses symlinks correctly on bash, dash, busybox, zsh. Note that tcsh won't like the $(...), so stick to the older backtick style in csh-variants.
There are also extra switches in pwd and df for further enjoyment.
On Linux, use /proc/<pid>/mounts to access a list of mount points for a given pid, or /proc/self/mounts (with the literal word self) to refer to yourself. (cat the /proc/self/mount* files to see what they look like.)
Then, for each file system, you can do a statfs() call and compare f_fsid the f_fsid field to the result from an earlier statfs() on the path in question. Once the fsid's match, you have found the appropriate mounted file system and can use the other data from /proc/self/mounts. (However, see statfs(2) for restrictions on doing anything useful with f_fsid.)