Storage
Contents
SCSI rescan without reboot
On debian
backup:~# aptitude install scsiadd backup:~# scsiadd -s Attached devices: Host: scsi0 Channel: 00 Id: 06 Lun: 00 Vendor: PE/PV Model: 1x6 SCSI BP Rev: 1.0 Type: Processor ANSI SCSI revision: 02 Host: scsi0 Channel: 02 Id: 00 Lun: 00 Vendor: MegaRAID Model: LD 0 RAID1 34G Rev: 521X Type: Direct-Access ANSI SCSI revision: 02
On other linux:
backup:~# echo "- - -" > /sys/class/scsi_host/host0/scan
For some Fiber channels it can be:
echo "1" > /sys/class/fc_host/host#/issue_lip
Partition re-read without reboot
backup:~# aptitude install parted backup:~# partprobe
Adding a new partition
fdisk + partprobe
backup:~# fdisk /dev/sda The number of cylinders for this disk is set to 34680. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sda: 36.3 GB, 36364615680 bytes 64 heads, 32 sectors/track, 34680 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x49e2fd2f Device Boot Start End Blocks Id System /dev/sda1 1 7629 7812080 83 Linux /dev/sda2 7630 7631 2048 82 Linux swap / Solaris Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (7632-34680, default 7632): Using default value 7632 Last cylinder or +size or +sizeM or +sizeK (7632-34680, default 34680): Using default value 34680 Command (m for help): p Disk /dev/sda: 36.3 GB, 36364615680 bytes 64 heads, 32 sectors/track, 34680 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x49e2fd2f Device Boot Start End Blocks Id System /dev/sda1 1 7629 7812080 83 Linux /dev/sda2 7630 7631 2048 82 Linux swap / Solaris /dev/sda3 7632 34680 27698176 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. backup:~# partprobe backup:~# ls -la /dev/sda* brw-rw---- 1 root disk 8, 0 2009-10-01 11:10 /dev/sda brw-rw---- 1 root disk 8, 1 2009-09-30 15:32 /dev/sda1 brw-rw---- 1 root disk 8, 2 2009-09-30 15:32 /dev/sda2 brw-rw---- 1 root disk 8, 3 2009-10-01 11:10 /dev/sda3 backup:~#
Formatting ext3 and mounting the partiton
backup:~# mke2fs -j /dev/sda3 mke2fs 1.41.3 (12-Oct-2008) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 1733312 inodes, 6924544 blocks 346227 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 212 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Mounting via command:
backup:~# mkdir /tmp/mount backup:~# mount /dev/sda3 /tmp/mount/
Mounting via fstab
backup:~# cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/sda1 / ext3 errors=remount-ro 0 1 /dev/sda3 /tmp/mount ext3 defaults 0 2 /dev/sda2 none swap sw 0 0 /dev/hde /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/hdb /media/cdrom1 udf,iso9660 user,noauto 0 0 backup:~# umount /tmp/mount/ backup:~# mount /tmp/mount/
LVM
|| Physical Volumes || pv || Physical disk or partions that we will use to create partiongs || || Volume Group || vg || A set of Physical Disk's or partitions that equals like a big disk || || Logical Volume || lv || Logical Volumes that we set up in a Volume Group, like a partition in a disk ||
Create an LVM partition
The procedure is to create the partition like other partition and change the Id to 'Linux LVM'
backup:~# fdisk /dev/sda3 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x10c7f8c8. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 27049. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): p Disk /dev/sda3: 28.3 GB, 28362932224 bytes 64 heads, 32 sectors/track, 27049 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x10c7f8c8 Device Boot Start End Blocks Id System Command (m for help): q backup:~# fdisk /dev/sda The number of cylinders for this disk is set to 34680. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sda: 36.3 GB, 36364615680 bytes 64 heads, 32 sectors/track, 34680 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x49e2fd2f Device Boot Start End Blocks Id System /dev/sda1 1 7629 7812080 83 Linux /dev/sda2 7630 7631 2048 82 Linux swap / Solaris /dev/sda3 7632 34680 27698176 83 Linux Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): L 0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot 1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris 2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx 6 FAT16 42 SFS 86 NTFS volume set da Non-FS data 7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT 10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT 1c Hidden W95 FAT3 75 PC/IX Hex code (type L to list codes): 8e Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 36.3 GB, 36364615680 bytes 64 heads, 32 sectors/track, 34680 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Disk identifier: 0x49e2fd2f Device Boot Start End Blocks Id System /dev/sda1 1 7629 7812080 83 Linux /dev/sda2 7630 7631 2048 82 Linux swap / Solaris /dev/sda3 7632 34680 27698176 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. backup:~# partprobe
Creating Physical Volumes
backup-server:~# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created
To show it:
backup-server:~# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name backup-vg PV Size 9.31 GB / not usable 2.00 MB Allocatable yes (but full) PE Size (KByte) 4096 Total PE 2384 Free PE 0 Allocated PE 2384 PV UUID c523t4-ayG8-111I-w1uj-4MTL-ivau-WO00rR
Creating Volume Group
backup-server:~# vgcreate backup-vg /dev/sda3 Volume group "backup-vg" successfully created
To display the volume group:
backup-server:~# vgdisplay --- Volume group --- VG Name backup-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.31 GB PE Size 4.00 MB Total PE 2384 Alloc PE / Size 0 / 0 Free PE / Size 2384 / 9.31 GB VG UUID rKpG12-3AUc-J2Yg-Kl1V-IlK1-kTBo-prYgMs
Creating a logical volume
backup-server:~# lvcreate -l 100%FREE -n bacula backup-vg Logical volume "bacula" created
backup-server:~# lvdisplay --- Logical volume --- LV Name /dev/backup-vg/bacula VG Name backup-vg LV UUID YIK4iX-faGF-A84t-slGo-6lv1-VKxF-7j8SSC LV Write Access read/write LV Status available # open 0 LV Size 9.31 GB Current LE 2384 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0
Then we need to format the new logical parition by:
backup-server:~# mke2fs -j /dev/backup-vg/bacula mke2fs 1.41.3 (12-Oct-2008) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 610800 inodes, 2441216 blocks 122060 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2499805184 75 block groups 32768 blocks per group, 32768 fragments per group 8144 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Then we can start to mount the partition:
backup-server:~# mkdir /tmp/aa backup-server:~# mount /dev/backup-vg/bacula /tmp/aa/
So here, we go, we have a new partiton of 9.2G
backup-server:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.4G 872M 6.2G 13% / tmpfs 1014M 0 1014M 0% /lib/init/rw udev 10M 724K 9.3M 8% /dev tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/backup--vg-bacula 9.2G 150M 8.6G 2% /tmp/aa
Resizing on LVM
On the worse of the cases, if we want to resize the Logical Volume, we will need to create a new Physical Volume, add it into the Volume Group, and extend the logical volume:
First that we need to do is to ummount the partition.
backup-server:/tmp# unmount /tmp/aa
We will create a new Physical Device
backup-server:/tmp# pvcreate /dev/sda4 Physical volume "/dev/sda4" successfully created backup-server:/tmp# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name backup-vg PV Size 9.31 GB / not usable 2.00 MB Allocatable yes (but full) PE Size (KByte) 4096 Total PE 2384 Free PE 0 Allocated PE 2384 PV UUID c523t4-ayG8-111I-w1uj-4MTL-ivau-WO00rR "/dev/sda4" is a new physical volume of "17.10 GB" --- NEW Physical volume --- PV Name /dev/sda4 VG Name PV Size 17.10 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID N4pKWY-cQyJ-zFiA-4nAO-tN0B-xw63-8NOwYT
Then we will need to extend the Volume Group with the Physical Device
backup-server:/tmp# vgdisplay --- Volume group --- VG Name backup-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.31 GB PE Size 4.00 MB Total PE 2384 Alloc PE / Size 2384 / 9.31 GB Free PE / Size 0 / 0 VG UUID rKpG12-3AUc-J2Yg-Kl1V-IlK1-kTBo-prYgMs backup-server:/tmp# vgextend backup-vg /dev/sda4 Volume group "backup-vg" successfully extended backup-server:/tmp# vgdisplay --- Volume group --- VG Name backup-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 26.41 GB PE Size 4.00 MB Total PE 6761 Alloc PE / Size 2384 / 9.31 GB Free PE / Size 4377 / 17.10 GB VG UUID rKpG12-3AUc-J2Yg-Kl1V-IlK1-kTBo-prYgMs <pre> So we have now a 17G free in the Volume Group. We need now to extend the Logical Volume bacula. <pre> backup-server:/tmp# lvextend -l +100%FREE /dev/backup-vg/bacula Extending logical volume bacula to 26.41 GB Logical volume bacula successfully resized backup-server:/tmp# lvdisplay --- Logical volume --- LV Name /dev/backup-vg/bacula VG Name backup-vg LV UUID YIK4iX-faGF-A84t-slGo-6lv1-VKxF-7j8SSC LV Write Access read/write LV Status available # open 0 LV Size 26.41 GB Current LE 6761 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0
But still if we mount the Logical Volume it is still 9 G :
backup-server:/tmp# mount /dev/backup-vg/bacula /tmp/aa/ backup-server:/tmp# ls -la /tmp/aa/ total 28 drwxr-xr-x 3 root root 4096 2009-10-02 12:37 . drwxrwxrwt 5 root root 4096 2009-10-02 12:34 .. -rw-r--r-- 1 root root 15 2009-10-02 12:37 aa.txt drwx------ 2 root root 16384 2009-10-02 12:34 lost+found backup-server:/tmp# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.4G 872M 6.2G 13% / tmpfs 1014M 0 1014M 0% /lib/init/rw udev 10M 724K 9.3M 8% /dev tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/backup--vg-bacula 9.2G 150M 8.6G 2% /tmp/aa
We will need also to extend the partiton. This will depend on the file-system that we have. In our case this is ext3. So we will use resize2fs utility to resize. If no argument is given it will resize to the max size of the partition. The first time we run the program it will ask to check the partition with e2fsck.
backup-server:/tmp# umount /tmp/aa/ backup-server:/tmp# resize2fs /dev/backup-vg/bacula resize2fs 1.41.3 (12-Oct-2008) Please run 'e2fsck -f /dev/backup-vg/bacula' first. backup-server:/tmp# e2fsck -f /dev/backup-vg/bacula e2fsck 1.41.3 (12-Oct-2008) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/backup-vg/bacula: 12/610800 files (0.0% non-contiguous), 76506/2441216 blocks backup-server:/tmp# resize2fs /dev/backup-vg/bacula resize2fs 1.41.3 (12-Oct-2008) Resizing the filesystem on /dev/backup-vg/bacula to 6923264 (4k) blocks. The filesystem on /dev/backup-vg/bacula is now 6923264 blocks long.
So we will have now a new partiton of 26G and with the data still on it.
backup-server:/tmp# mount /dev/backup-vg/bacula /tmp/aa/ backup-server:/tmp# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.4G 872M 6.2G 13% / tmpfs 1014M 0 1014M 0% /lib/init/rw udev 10M 724K 9.3M 8% /dev tmpfs 1014M 0 1014M 0% /dev/shm /dev/mapper/backup--vg-bacula 26G 154M 25G 1% /tmp/aa backup-server:/tmp# cd /tmp/aa/ backup-server:/tmp/aa# ls -la total 28 drwxr-xr-x 3 root root 4096 2009-10-02 12:37 . drwxrwxrwt 5 root root 4096 2009-10-02 12:34 .. -rw-r--r-- 1 root root 15 2009-10-02 12:37 aa.txt drwx------ 2 root root 16384 2009-10-02 12:34 lost+found backup-server:/tmp/aa#
Mounting LVM on other server
Boot with rescue CD. Skip mounting of the system partitions.
# lvm vgchange -a y