Mount disk by UUID in Linux

Find UUID

blkid

Example output

/dev/xvdb1: UUID="42fbe9a1-eea1-34bc-439d-19a0b48e7df1" TYPE="xfs"

Mount drive using the UUID

[root@host ~]# mount -U 42fbe9a1-eea1-34bc-439d-19a0b48e7df1 /mnt

Add to fstab to automatically mount on system boot up

vi /etc/fstab

Add the following, swap out the UUID for your devices UUID

UUID="42fbe9a1-eea1-34bc-439d-19a0b48e7df1" /backup xfs defaults 0 0

Save and exit. Now when the system reboots it should automatically mount the drive. You should also be able to call “mount -a” to automatically mount everything in fstab.

resize2fs: Read-only file system While checking for on-line resizing support

Had a problem with resize2fs not resizing the root partition of Ubuntu. Was giving the following error

resize2fs: Read-only file system While checking for on-line resizing support

The problem is the root partition I was trying to resize was mounted read only. Remounting as read/write fixed the problem

mount -o remount /

Then rerun the resize command to fill up the rest of the free space

resize2fs /dev/sda1

How to chroot into a Linux drive

Chrooting can be super useful for changing things like the root password, repairing grub bootloader etc., things that require the system to be mounted.  Typically if your chrooting into an OS drive you can boot up on a Live Linux distro, or use the Rescue feature on some Linux installers.

Mount main drive

Change sdb2 to the root partition of your drive.

mount /dev/sdb2 /mnt

Mount other stuff

mount -t proc none /mnt/proc
mount -o bind /dev /mnt/dev
mount -o bind /sys /mnt/sys
mount -o bind /run /mnt/run

If you want to, you can mount the boot partition.  Change sdb1 if your boot partition is something else.  For efi, you may need to mount the boot partition then mount the efi partition inside /boot/efi.

mount /dev/sdb1 /mnt/boot

Chroot

 chroot /mnt

You should now be inside the chroot environment.  To exit the chroot, hit control+d or type exit.

If your having issues resolving DNS refer to this post.

Auto mount CIFS mount point on system startup on Ubuntu

Install CIFS utils

sudo apt-get install -y cifs-utils

You can manually test it with the following command.  Change the ip address, mount points, username, and password.

mount.cifs /192.168.1.102/mount/point /mnt -o user=john,pass=password3,uid=john

Note that specifying the uid in the options, allows the user to add, delete, and modify the files and folders of that specific mount point.

To auto mount on system startup, add the following line to /etc/fstab.  Change the appropriate lines.

//192.168.1.102/mount/point   /mnt  auto   user=john,pass=password3,uid=john   0   0

You can test it by mounting everything in fstab

sudo mount -a