Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay-johnson/9815373e196bc3ba331d to your computer and use it in GitHub Desktop.
Save jay-johnson/9815373e196bc3ba331d to your computer and use it in GitHub Desktop.
Mounting a new Volume for increasing /var hard drive space

Format the Volume

driver@localhost:/var/lib$ sudo fdisk -l

Disk /dev/sda: 31.5 GB, 31515377664 bytes
255 heads, 63 sectors/track, 3831 cylinders, total 61553472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078a5a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    53166079    26582016   83  Linux
/dev/sda2        53168126    61552639     4192257    5  Extended
/dev/sda5        53168128    61552639     4192256   82  Linux swap / Solaris

Disk /dev/sdb: 494.2 GB, 494233976832 bytes
255 heads, 63 sectors/track, 60087 cylinders, total 965300736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table
driver@localhost:/var/lib$ sudo fdisk /dev/sdb

Command (m for help): l

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      

Command (m for help): d
No partition is defined yet!

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-965300735, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-965300735, default 965300735): 
Using default value 965300735

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
driver@localhost:/var/lib$ sudo fdisk -l

Disk /dev/sda: 31.5 GB, 31515377664 bytes
255 heads, 63 sectors/track, 3831 cylinders, total 61553472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078a5a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    53166079    26582016   83  Linux
/dev/sda2        53168126    61552639     4192257    5  Extended
/dev/sda5        53168128    61552639     4192256   82  Linux swap / Solaris

Disk /dev/sdb: 494.2 GB, 494233976832 bytes
49 heads, 57 sectors/track, 345614 cylinders, total 965300736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbff8e1de

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   965300735   482649344   83  Linux
driver@localhost:/var/lib$ sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
30171136 inodes, 120662336 blocks
6033116 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3683 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     

driver@localhost:/var/lib$ sudo fdisk -l

Disk /dev/sda: 31.5 GB, 31515377664 bytes
255 heads, 63 sectors/track, 3831 cylinders, total 61553472 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078a5a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    53166079    26582016   83  Linux
/dev/sda2        53168126    61552639     4192257    5  Extended
/dev/sda5        53168128    61552639     4192256   82  Linux swap / Solaris

Disk /dev/sdb: 494.2 GB, 494233976832 bytes
49 heads, 57 sectors/track, 345614 cylinders, total 965300736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbff8e1de

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   965300735   482649344   83  Linux
driver@localhost:/var/lib$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        25G   15G  8.9G  63% /
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           396M  904K  395M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G  160K  2.0G   1% /run/shm
cgroup          2.0G     0  2.0G   0% /sys/fs/cgroup
shared          121G  118G  3.1G  98% /media/sf_shared
driver@localhost:/var/lib$ 

Mount it and retain the permissions

sudo mkdir varnew
sudo mount /dev/sdb1 /varnew
sudo cp -rp /var/* /varnew
sudo mv /var varbak
sudo mkdir var
sudo umount /dev/sdb1
sudo mount /dev/sdb1 /var

Check the new Volume is mounted (/dev/sdb1 on this Ubuntu example)

driver@localhost:/$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        25G   15G  8.9G  63% /
udev            2.0G  4.0K  2.0G   1% /dev
tmpfs           396M  904K  395M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            2.0G  160K  2.0G   1% /run/shm
cgroup          2.0G     0  2.0G   0% /sys/fs/cgroup
shared          121G  121G  359M 100% /media/sf_shared
/dev/sdb1       453G  3.4G  427G   1% /var
driver@localhost:/$ 

###Automatically Mount it with /etc/fstab

Add this line:

sudo echo "/dev/sdb1       /var            ext4    defaults             0       2" >> /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment