Having a Ubuntu
Server 14.04 LTS running virtualized with a minimal installation in a 4G virtual disk:
I was thinking to create VM clones from the pattern, but in order to be useful, it is necessary reconfigure the
disk space.
I made this in a new virtual machine, not in production, so you can do it at your own risk.
I made this in a new virtual machine, not in production, so you can do it at your own risk.
- add a 100G virtual disk to the clone
- created partition LVM
- created physical disk
- added to volume group
- resized root to 4G
- resized swap to 4G
- created new logical volume for var, usr, home and tmp
- moved var, usr, home and tmp to new space.
Checking what we have. We see root and swap. We see a new disk with 100G.
Welcome to Ubuntu
14.04.1 LTS (GNU/Linux 3.13.0-32-generic i686)
* Documentation:
https://help.ubuntu.com/
Last login: Mon Nov
10 09:46:27 2014 from 172.16.1.11
elder@JeOS:~$ sudo
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
[sudo] password for
elder:
NAME
FSTYPE SIZE MOUNTPOINT LABEL
sda
4G
├─sda1
ext2 243M /boot
├─sda2
1K
└─sda5
LVM2_member 3.8G
├─JeOS--vg-root
(dm-0) ext4 3.2G /
└─JeOS--vg-swap_1
(dm-1) swap 508M [SWAP]
sdb
100G
sr0
1024M
Creating partition.
elder@JeOS:~$sudo sfdisk /dev/sdb << EOF
> ,,8e
> EOF
Checking that no-one
is using this disk right now ...
OK
Disk /dev/sdb: 13054
cylinders, 255 heads, 63 sectors/track
Old situation:
Units = cylinders of
8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start
End #cyls #blocks Id System
/dev/sdb1 0
- 0 0 0 Empty
/dev/sdb2 0
- 0 0 0 Empty
/dev/sdb3 0
- 0 0 0 Empty
/dev/sdb4 0
- 0 0 0 Empty
New situation:
Units = cylinders of
8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start
End #cyls #blocks Id System
/dev/sdb1
0+ 13053 13054- 104856254+ 8e Linux LVM
/dev/sdb2 0
- 0 0 0 Empty
/dev/sdb3 0
- 0 0 0 Empty
/dev/sdb4 0
- 0 0 0 Empty
Warning: no primary
partition is marked bootable (active)
This does not matter
for LILO, but the DOS MBR will not boot this disk.
Successfully wrote
the new partition table
Re-reading the
partition table ...
If you created or
changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first
512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
elder@JeOS:~$ sudo
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
NAME
FSTYPE SIZE MOUNTPOINT LABEL
sda
4G
├─sda1
ext2 243M /boot
├─sda2
1K
└─sda5
LVM2_member 3.8G
├─JeOS--vg-root
(dm-0) ext4 3.2G /
└─JeOS--vg-swap_1
(dm-1) swap 508M [SWAP]
sdb
100G
└─sdb1
100G
sr0
1024M
elder@JeOS:~$sudo
pvdisplay
--- Physical
volume ---
PV Name
/dev/sda5
VG Name
JeOS-vg
PV Size
3.76 GiB / not usable 2.00 MiB
Allocatable
yes
PE Size
4.00 MiB
Total PE
962
Free PE
10
Allocated PE
952
PV UUID
Xp75Xb-3Tj1-BwEm-QB79-AS2l-ZXsu-pYqzC2
Creating physical volume.
elder@JeOS:~$ sudo pvcreate /dev/sdb1
Physical volume
"/dev/sdb1" successfully created
elder@JeOS:~$ sudo
pvscan
PV /dev/sda5 VG
JeOS-vg lvm2 [3.76 GiB / 40.00 MiB free]
PV /dev/sdb1
lvm2 [100.00 GiB]
Total: 2 [103.76
GiB] / in use: 1 [3.76 GiB] / in no VG: 1 [100.00 GiB]
Attaching to existing volume.
elder@JeOS:~$ sudo
vgextend JeOS-vg /dev/sdb1
Volume group
"JeOS-vg" successfully extended
elder@JeOS:~$ sudo
pvscan
PV /dev/sda5 VG
JeOS-vg lvm2 [3.76 GiB / 40.00 MiB free]
PV /dev/sdb1 VG
JeOS-vg lvm2 [100.00 GiB / 100.00 GiB free]
Total: 2 [103.75
GiB] / in use: 2 [103.75 GiB] / in no VG: 0 [0 ]
elder@JeOS:~$ sudo
lvscan
ACTIVE
'/dev/JeOS-vg/root' [3.22 GiB] inherit
ACTIVE
'/dev/JeOS-vg/swap_1' [508.00 MiB] inherit
Extending root to 4G.
elder@JeOS:~$ sudo
lvextend -L4G /dev/JeOS-vg/root
Extending logical
volume root to 4.00 GiB
Logical volume
root successfully resized
elder@JeOS:~$ sudo
df
Filesystem
1K-blocks Used Available Use% Mounted on
/dev/mapper/JeOS--vg-root
3260568 643788 2431436 21% /
none
4 0 4 0% /sys/fs/cgroup
udev
509464 4 509460 1% /dev
tmpfs
102600 332 102268 1% /run
none
5120 0 5120 0% /run/lock
none
512992 0 512992 0% /run/shm
none
102400 0 102400 0% /run/user
/dev/sda1
240972 22406 206125 10% /boot
elder@JeOS:~$ sudo
resize2fs /dev/JeOS-vg/root
resize2fs 1.42.9
(4-Feb-2014)
Filesystem at
/dev/JeOS-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 1,
new_desc_blocks = 1
The filesystem on
/dev/JeOS-vg/root is now 1048576 blocks long.
elder@JeOS:~$ sudo
df
Filesystem
1K-blocks Used Available Use% Mounted on
/dev/mapper/JeOS--vg-root
4063424 644620 3202004 17% /
none
4 0 4 0% /sys/fs/cgroup
udev
509464 4 509460 1% /dev
tmpfs
102600 332 102268 1% /run
none
5120 0 5120 0% /run/lock
none
512992 0 512992 0% /run/shm
none
102400 0 102400 0% /run/user
/dev/sda1
240972 22406 206125 10% /boot
Extending swap to 4G.
elder@JeOS:~$ cat
/proc/swaps
Filename Type Size Used Priority
/dev/dm-1
partition 520188 0 -1
elder@JeOS:~$ sudo
lvscan
ACTIVE
'/dev/JeOS-vg/root' [4.00 GiB] inherit
ACTIVE
'/dev/JeOS-vg/swap_1' [508.00 MiB] inherit
elder@JeOS:~$ sudo
swapoff /dev/JeOS-vg/swap_1
elder@JeOS:~$ sudo
lvextend -L4G /dev/JeOS-vg/swap_1
Extending logical
volume swap_1 to 4.00 GiB
Logical volume
swap_1 successfully resized
elder@JeOS:~$ sudo
mkswap /dev/JeOS-vg/swap_1
mkswap:
/dev/JeOS-vg/swap_1: warning: don't erase bootbits sectors
on whole
disk. Use -f to force.
Setting up swapspace
version 1, size = 4194300 KiB
no label,
UUID=1da2e07b-9f6d-45e1-888b-4461c18a83da
elder@JeOS:~$ sudo
swapon /dev/JeOS-vg/swap_1
elder@JeOS:~$ sudo
cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-1
partition 4194300 0 -1
elder@JeOS:~$ sudo
lvscan
ACTIVE
'/dev/JeOS-vg/root' [4.00 GiB] inherit
ACTIVE
'/dev/JeOS-vg/swap_1' [4.00 GiB] inherit
Creating logical volumes and formating for var, usr, home and tmp.
elder@JeOS:~$ sudo
lvcreate -L 800 -n home JeOS-vg
Logical volume
"home" created
elder@JeOS:~$ sudo
lvcreate -L 1G -n tmp JeOS-vg
Logical volume
"tmp" created
elder@JeOS:~$ sudo
lvcreate -L 80G -n var JeOS-vg
Logical volume
"var" created
elder@JeOS:~$ sudo
lvcreate -L 10G -n usr JeOS-vg
Logical volume
"usr" created
elder@JeOS:~$ sudo
mkfs.ext4 /dev/JeOS-vg/home
mke2fs 1.42.9
(4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096
(log=2)
Fragment size=4096
(log=2)
Stride=0 blocks,
Stripe width=0 blocks
51296 inodes, 204800
blocks
10240 blocks (5.00%)
reserved for the super user
First data block=0
Maximum filesystem
blocks=209715200
7 block groups
32768 blocks per
group, 32768 fragments per group
7328 inodes per
group
Superblock backups
stored on blocks:
32768, 98304,
163840
Allocating group
tables: 0/7 done
Writing inode
tables: 0/7 done
Creating journal
(4096 blocks): done
Writing superblocks
and filesystem accounting information: 0/7 done
elder@JeOS:~$ sudo
mkfs.ext4 /dev/JeOS-vg/tmp
mke2fs 1.42.9
(4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096
(log=2)
Fragment size=4096
(log=2)
Stride=0 blocks,
Stripe width=0 blocks
65536 inodes, 262144
blocks
13107 blocks (5.00%)
reserved for the super user
First data block=0
Maximum filesystem
blocks=268435456
8 block groups
32768 blocks per
group, 32768 fragments per group
8192 inodes per
group
Superblock backups
stored on blocks:
32768, 98304,
163840, 229376
Allocating group
tables: 0/8 done
Writing inode
tables: 0/8 done
Creating journal
(8192 blocks): done
Writing superblocks
and filesystem accounting information: 0/8 done
elder@JeOS:~$ sudo
mkfs.ext4 /dev/JeOS-vg/var
mke2fs 1.42.9
(4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096
(log=2)
Fragment size=4096
(log=2)
Stride=0 blocks,
Stripe width=0 blocks
5242880 inodes,
20971520 blocks
1048576 blocks
(5.00%) reserved for the super user
First data block=0
Maximum filesystem
blocks=0
640 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
Allocating group
tables: 0/640 done
Writing inode
tables: 0/640 done
Creating journal
(32768 blocks): done
Writing superblocks
and filesystem accounting information: 0/640 done
elder@JeOS:~$ sudo
mkfs.ext4 /dev/JeOS-vg/usr
mke2fs 1.42.9
(4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096
(log=2)
Fragment size=4096
(log=2)
Stride=0 blocks,
Stripe width=0 blocks
655360 inodes,
2621440 blocks
131072 blocks
(5.00%) reserved for the super user
First data block=0
Maximum filesystem
blocks=2684354560
80 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
Allocating group
tables: 0/80 done
Writing inode
tables: 0/80 done
Creating journal
(32768 blocks): done
Writing superblocks
and filesystem accounting information: 0/80 done
Here we need go into single user mode in order to move var, usr, home and tmp to the new locations created. All connections will be lost and be sure that you have access to console.
elder@JeOS:~$ sudo
telinit s #Single user mode, out of production
[sudo] password for
elder:
Tmp is a temporaly folder and a copy is not needed. Mounting var, usr and home in temporal locations.
root@JeOS:~#
mkdir /mnt/home #it is not needed a tmp copy
root@JeOS:~#
mkdir /mnt/var
root@JeOS:~#
mkdir /mnt/usr
root@JeOS:~#
mount /dev/mapper/JeOS—vg-home /mnt/home
root@JeOS:~#
mount /dev/mapper/JeOS—vg-var /mnt/var
root@JeOS:~#
cp -ax /home/* /mnt/home
root@JeOS:~#
cp -ax /var/* /mnt/var
root@JeOS:~#
cp -ax /usr/* /mnt/usr
root@JeOS:~#
mv /home /home.old
root@JeOS:~#
mv /var /var.old
root@JeOS:~#
mv /usr /usr.old
root@JeOS:~#
mv /tmp /tmp.old
root@JeOS:~# mkdir /home
root@JeOS:~# mkdir /var
root@JeOS:~# mkdir /usr
root@JeOS:~# mkdir /tmp
root@JeOS:~# chmod 1777 /tmp #permissions for tmp
root@JeOS:~# mkdir /home
root@JeOS:~# mkdir /var
root@JeOS:~# mkdir /usr
root@JeOS:~# mkdir /tmp
root@JeOS:~# chmod 1777 /tmp #permissions for tmp
Modifing fstab with the /dev/mapper links founded in lsblk.
NAME
MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda
8:0 0 4G 0 disk
|-sda1
8:1 0 243M 0 part /boot
|-sda2
8:2 0 1K 0 part
`-sda5
8:5 0 3.8G 0 part
|-JeOS--vg-root
(dm-0) 252:0 0 4G 0 lvm /
`-JeOS--vg-swap_1
(dm-1) 252:1 0 4G 0 lvm [SWAP]
sdb
8:16 0 100G 0 disk
`-sdb1
8:17 0 100G 0 part
|-JeOS--vg-root
(dm-0) 252:0 0 4G 0 lvm /
|-JeOS--vg-swap_1
(dm-1) 252:1 0 4G 0 lvm [SWAP]
|-JeOS--vg-home
(dm-2) 252:2 0 800M 0 lvm
|-JeOS--vg-tmp
(dm-3) 252:3 0 1G 0 lvm
|-JeOS--vg-var
(dm-4) 252:4 0 80G 0 lvm
`-JeOS--vg-usr
(dm-5) 252:5 0 10G 0 lvm
sr0
11:0 1 1024M 0 rom
root@JeOS:~#
echo '/dev/mapper/JeOS--vg-home /home ext4 defaults 0 0' >>
/etc/fstab
root@JeOS:~#
echo '/dev/mapper/JeOS--vg-var /var ext4 defaults 0 0 ' >>
/etc/fstab
root@JeOS:~#
echo '/dev/mapper/JeOS--vg-usr /usr ext4 defaults 0 0 ' >>
/etc/fstab
root@JeOS:~#
echo '/dev/mapper/JeOS--vg-tmp /tmp ext4 defaults 0 0 ' >>/etc/fstab
# /etc/fstab: static
file system information.
#
# Use 'blkid' to
print the universally unique identifier for a
# device; this may
be used with UUID= as a more robust way to name devices
# that works even if
disks are added and removed. See fstab(5).
#
# <file system>
<mount point> <type> <options> <dump>
<pass>
/dev/mapper/JeOS--vg-root
/ ext4 errors=remount-ro 0 1
# /boot was on
/dev/sda1 during installation
UUID=fa4cb140-0c28-4c06-823e-2f0bb11d08ef
/boot ext2 defaults 0 2
/dev/mapper/JeOS--vg-swap_1
none swap sw 0 0
/dev/mapper/JeOS--vg-home
/home ext4 defaults 0 0
/dev/mapper/JeOS--vg-var
/var ext4 defaults 0 0
/dev/mapper/JeOS--vg-usr
/usr ext4 defaults 0 0
/dev/mapper/JeOS--vg-tmp
/tmp ext4 defaults 0 0
/dev/mapper/JeOS--vg-root
on / type ext4 (rw,errors=remount-ro)
proc on /proc type
proc (rw,noexec,nosuid,nodev)
sysfs on /sys type
sysfs (rw,noexec,nosuid,nodev)
none on
/sys/fs/cgroup type tmpfs (rw)
none on
/sys/fs/fuse/connections type fusectl (rw)
none on
/sys/kernel/debug type debugfs (rw)
none on
/sys/kernel/security type securityfs (rw)
udev on /dev type
devtmpfs (rw,mode=0755)
devpts on /dev/pts
type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type
tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock
type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm
type tmpfs (rw,nosuid,nodev)
none on /run/user
type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on
/sys/fs/pstore type pstore (rw)
/dev/sda1 on /boot
type ext2 (rw)
/dev/mapper/JeOS--vg-home
on /home type ext4 (rw)
/dev/mapper/JeOS--vg-var
on /var type ext4 (rw)
/dev/mapper/JeOS--vg-usr
on /usr type ext4 (rw)
/dev/mapper/JeOS--vg-tmp
on /tmp type ext4 (rw)
Mounting new entries and checking.
backups
cache
lib
local
lock
log
lost+found
mail
opt
run
spool
tmp
root@JeOS:~#
reboot
elder@JeOS:~$ sudo rm -d /mnt/*
elder@JeOS:~$ sudo rm -r /*.old
For me everything was good after rebooting, so clean your own dirt.
elder@JeOS:~$ sudo rm -d /mnt/*
elder@JeOS:~$ sudo rm -r /*.old
No comments:
Post a Comment