How to access fstab at reboot phase - linux

How can I access and modify /etc/fstab during reboot (maybe accessing to recovery mode) ?
Why this question :
I have updated the virtualbox guests additions in backtrack 5 (as a Virtualbox VM).
I have modified temporary the fstab file to do that but forgotten to turn it back to initial state, like :
mount /dev/cdrom /cdrom
echo "/dev/cdrom /cdrom0 udf,iso9660 defaults,exec 0 0" >> /etc/fstab
So after the guest additions installed, reboot is blocked on mounting this unexisting point.
Thx
edit: maybe to move to serverfault ?

I see two possible solutions to your problem:
Use the recovery mode (if you don't see that in the grub list, edit the default entry and add the word "single" without quotes to the end of the kernel line)
Mount a random .iso file temporarily
Then remove the offending fstab line.

Another option is to boot a Live OS and mount the root filesystem from there. Then you will be able to edit the fstab file.
Once you have the live OS booted
fdisk -l
-find your root partition (usually in the format sda1, sdc1, sda2, etc)
mkdir /mnt/rootfs
mount /dev/sda2 /mnt/rootfs <--sda2 = root partition found in fdisk
cd /mnt/rootfs/etc
-Fstab file should be in there.

Related

How do I edit fstab in emergency mode?

I moved my EFI partition which caused me to enter emergency mode on reboot.
mount -a confirmed fstab had the the UUID of the old partition...it wasn't mounting and that caused emergency mode.
You can't do ANY of the standard remount,rw tricks that normally work... it will always give you an error message the mount doesn't work
Sure, I could start from the USB stick and edit /etc/fstab, but isn't there an easier way?
This question has been around for 10 years and most people answer with a remount as rw, but that always fails.
The clever way is simply mount the / partition on /mnt like:
mount /dev/sda1 /mnt
This mounts it read-write and you just edit /mnt/etc/fstab to change the new UUID for your partition which you can get from either blkid or ls -lha /dev/disk/by-uuid
However, the readonly filesystem will NOT see your changes, so you think you've failed. You'll look at /etc/fstab and it will appear unchanged (at least under btrfs it looks unchanged).
However, when you reboot, you are back in business.
I re-sized my EFI partition down to 260MB, but had to remove it to do that which causes the UUID to change. Just changing the /etc/fstab with the new UUID is all that you need to do so you don't run into trouble. Best to do that when you move the partition, rather than after the fact.
I have RHEL 7.9 installed and here is what I did to edit the fstab after copying from one machine to another using scp.
mount -o remount,rw /dev/sda2 #sda2 is where my root directory is located.
I was then able to open in vim and save the UUID changes I had to make. Worked like a charm.

what causes permission of auto-mount in linaro linux

Sdcard is mounted automatically as root permission.
like this.
/dev/mmcblk1p1 on /media/linaro/11bf7464-471c-42ca-bbc8-d229a43e8fe51 type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks2)
/etc/fstab is emtpy like below.
linaro#linaro-alip:/lib/udev$ cat /etc/fstab
# UNCONFIGURED FSTAB FOR BASE SYSTEM
did udisks mount the device? If so, where can I change mount permission option?
Sometimes, it is mounted as a linaro user.
What causes this difference? any idea?
For Gnone to disable Nautilus automount use this command:
gsettings set org.gnome.desktop.media-handling automount false

Recover Hibernated partition

I accidently formatted my ntfs windows partition with "mkfs.ext4".
I was able to recover it with testdisk but it seems that the windows partition was hibernated,
so whenever i tried to open windows it starts repairing disk errors which was taking too long,
so i manually chkdsk ,to which after some time it started telling -"unreadable sector........
which also took very long so i shut it down.
In kali linux whenever i tried to mount it with "mount /dev/sda3 /mnt -t ntfs -r"
it mounts but many of the folders are empty including windows,program files,Users.
I am new to linux,can you tell me steps to recover my files if possible windows...
Thanks in Advance.
Use sudo ntfsfix /dev/sdXY where XY is the partition name. ex:sda4. use gparted to find partition name. Then mount. It may help.
First check to see it the partition is mounted, it maybe mounted as Read-only. Then issue the mount command with the options.
sudo mount -t ntfs-3g -o remove_hiberfile /dev/yourWindowsPartition /media/yourUser/WindowsPartitionName

KVM Virtual machine running Windows XP: How to get files from guest to host?

I'm running Ubuntu 10.04, and on it, kvm/qemu. I created a storage device with the 'raw' format and installed XP on it, so I assume the file has ntfs format. I have a file on the XP virtual machine that I want on the host. It's 2gigs, so I can't just use a zip drive or burn it to CD.
I tried mounting the file (winxp.img) using losetup:
$ sudo losetup /dev/loop1 winxp.img
$ sudo losetup -a
/dev/loop1: [0801]:40637460 (/home/robert/kvm/images/winxp.img)
$ sudo mount -t ntfs /dev/loop1 /home/robert/kvm/images/tmp
NTFS signature is missing.
Failed to mount '/dev/loop1': Invalid argument
The device '/dev/loop1' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
I thought that would work. It didn't. Does anyone have another idea?
winxp.img and loop1 is not a single partition (which can be mounted), it is image of full hard disk with own partition table.
You should read partition table from loop1 with fdisk; compute offset of first partition and do:
sudo mount -o offset=N -t ntfs /dev/loop1 /home/robert/kvm/images/tmp
where N is offset in bytes.
Telepathic mode on
N is 32256
Telepathic mode off
and finally, google mode on (I'll google "offset 32256"):
http://en.wikibooks.org/wiki/QEMU/Images#Mounting_an_image_on_the_host
Linux and other Unix-like hosts can mount images created with the raw format type using a loopback device. From a root login (or using sudo), mount a loopback with an offset of 32,256.
mount -o loop,offset=32256 /path/to/image.img /mnt/mountpoint
In my opinion the generic and correct way is via libguestfs http://libguestfs.org/
If you master it, you can open every virtual image in any format and get files or even make snapshots

Repairing fstab (read only /)

I had a typo in my fstab and it boots to a commandline but is readonly, I know what the error is but i can't change it because it's mounted as readonly. I want to mount the filesystem and make the changes. I know I can boot a live distro and edit it that way, but i was wondering if there was an easier way to do it.
It's debian lenny by the way.
Yes, if you end up in single-user mode with a readonly root, try:
mount / -o remount,rw
Maybe a -n is necessary, maybe not. That should remount the root fs read/write (assuming there's nothing wrong with it).
I know that question is outdated, but saw it, because nowadays got in the same trouble.
I broke my fstab manually (make a typo in parameter).
That was very easy to correct fstab from readonly mode. We must mount / in read-write mode.
If /etc/fstab is correct, you can simply type:
mount -n -o remount /
But if /etc/fstab is wrong (as it was in my case), you must give the device name and possibly the type, too: e.g.
mount -n -o remount -t extX /dev/hdaX /
Where extX is your filesystem type and /dev/hdaX -- is partition you use for your root mount point.
To see all your available partitions just type ls /dev/[sh]d*.
#mount -n -o remount,rw /
if /dev/sda1 is the real device, then do:
#mount -n -o remount,rw /dev/sda1 /
#troyane saved my hassle by providing
mount -n -o remount -t extX /dev/hdaX /
I was on Orangepi3 EMMC when I had a typo in UUID of root having ext4 filesystem.
The command remounted in read-write mode and I fixed my fstab
mount -n -o remount -t ext4 /dev/mmcblk2p1 /
My kernel command line looks like this:
$ cat /proc/cmdline
root=/dev/sda4 ro
$
Tell grub that it should omit passing "ro" to the kernel when booting (pressing esc, e on the entry you want edit will allow you to edit the arguments given to the kernel), and it will mount your root file system not read only anymore. Then you can change your /etc/fstab and restart.
In my case, in grub2 after pressing "e" I have changed "ro" to "rw init=/bin/bash" then the root filesystem is mounted read and write so I could change the content of /etc/fstab file.
If you have something wrong with your /etc/fstab file. Please follow the following steps.
boot your ubuntu system or restart your computer
since you can not start your system, you will encounter some errors like
“a start job is running for dev-disk-by....
(you may need pressing F2 key to come the linux command terminal to see this)
use command vi /etc/fstab and edit your fstab file
use # to commend out some problems and add something you want put in the fstab file.
finish editing. hit shift+z and save the modification
use command reboot to restart your system
it works again
Please comment here, if you have questions

Resources