Note: Do not place /usr on a separate partition
Mount a disk as read only / read write
mount -o remount,rw /path/to/mount
mount -o remount,ro /path/to/mount
Find a new disk
This is useful if you’ve hot-added another disk, such as with VMWare
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
LVM (Logical Volume Manager)
To Create LVM
fdisk /dev/sda ->create 3 partitions + label to 8e
partprobe
fdisvk -l
pvcreate /dev/sda8 /dev/sda9
pvdisplay /dev/sda8
pvdisplay /dev/sda9
vgcreate vg0 /dev/sda8 /dev/sda9
vgdisplay
lvcreate -L +15g -n label_home /dev/vg00
lvcreate -l +100%FREE -n lv_name /dev/vg01
lvdisplay /dev/vg0/home1
lvcreate -L +300M -n /dev/vg0/var1
lvcreate -L +200GB -n oracle-export vg01
lvdisplay /dev/vg0/var1
mkfs.ext3 /dev/vg0/var1
mkfs.ext3 /dev/vg0/home1
mkdir /home1
mkdir /var1
mount /dev/vg0/home1 /home1
mount /dev/vg0/var1 /var1
cp /etc/a* /home1
cp /etc/b* /var1
vim /etc/fstab
mount -a
LVM SNAPSHOT
lvcreate -L 200M -s -n lv2 /dev/llc/lv1
To find the mapping of an LV
lvdisplay -m
Extend PV
pvcreate /dev/sda999
pvdisplay
To extend VG
vgextend vg00 /dev/sda999
vgdisplay vg00
To reduce VG
vgreduce vg00 /dev/sda999
vgdisplay
TO EXTEND LV (Adding 200M)
lvdisplay /dev/vg00/home
lvextend -L +200M /dev/vg00/home
lvextend -L +200M /dev/vg00/home /dev/sdc1
lvextend -l +100%FREE /dev/myvg/testlv
(optional) umount /home
resize2fs /dev/vg0/home
(optional) mount /home
To reduce LVM (Reducing to 100M)
lvdisplay
umount /var1
e2fsck -f /dev/vg0/var1
resize2fs /dev/vg0/var1 100M
lvreduce -L 100M /dev/vg0/var1
mount /dev/vg0/var1 /var1
df -h
TO REDUCE PV
pvremove /dev/sda10 pvdisplay
REMOVE LVM
lvdisplay umount /dev/vg0/home1 umount /dev/vg0/var1 vi /etc/fstab lvremove /dev/vg0/home1 lvremove /dev/vg0/var1 lvdisplay
REMOVE VG
vgdisplay vgremove /dev/vg0 vgdisplay
REMOVE PV
pvdisplay pvremove /dev/sda9 pvremove /dev/sda8
Label a filesystem
e2label /dev/sdb2 usbstroage
You can add to /etc/fstab “LABEL=labelname”
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
/dev/mapper/server-root / ext4 errors=remount-ro 0 1
UUID=nnnnnnnnnnnnnnnnnn /boot ext2 defaults 0 2
/dev/mapper/server-swap_1 none swap sw 0 0
LABEL=seagate /mnt/seagate ntfs defaults 0 2
LABEL=backup /mnt/backup ext4 ro,nosuid,noexec 0 2
LABEL=wd3tbgreen /usr/local/var/crashplan/ ext4 nosuid,noexec 0 2
Adding swap
swapon -s
lvcreate -L +16G -n /dev/vg00/swap2
mkswap /dev/mapper/vg00-swap2
vi /etc/fstab
swapon -a
swapon -s
Which disk is an LV on
pvdisplay -m
lvdisplay -m
lvs -o +devices
lvs -a -o +devicesq
From Shane
Linux rescue + lvm
Reboot. Edit grub config On the end of the kernel line put “init=/bin/bash” This mounts root as read only mount -o remount,rw / Make whatever changes are required (you might need to mount /proc) Unmount anything mounted mount -o remount,ro / Afterwards “reboot” (not CTRL-D or it will lock up!!!)
To do a linux rescue boot (for resetting the root password for example) :
-
Mount a redhat iso/dvd and boot off it
-
Type “linux rescue” at the prompt
-
Tell the OS not to mount the disks or connect the network interfaces
-
When it boots type
-
lvm vgscan
-
lvm vgchange -a y
-
The vg should be under /dev/[vg]/[lv] - which will likely link to /dev/mapper (eg /dev/mapper/vg00-root)
-
Use this device to mount / fsck this volume as necessary
-
Other commands - “lvm lvscan” and “dmsetup status”
Running ‘fdisk -l’ should give you an overview of attached storage, partitions and file system types. Running ‘pvscan’ should show the Physical Volums (PV). Running ‘vgscan’ the Volume Groups (VG). Running ‘vgchange -ay’ should then enable your LVM. Running ’lvscan; dmsetup status’ afterwards should show the Logical Volumes (LV) and what directory they’re attached to in /dev/ for mounting purposes. Now with ‘mount /dev/VOLUMEGROUPNAME/LOGICALVOLUMENAME /some/directory’ you can mount the LV, e.g.: ‘mount /dev/vg0001/lv001 /mnt/temp/ -o ro’ should mount LV name “lv001” inside the “vg0001” VG at mountpoint /mnt/temp read-only (as you wouldn’t want to change things while making backups).