December 14, 2018

Relabelling the root filesystem of a droplet

$ ssh root@mydroplet.digital.ocean
The authenticity of host 'mydroplet.digital.ocean (172.17.217.2)' can't be
established. ECDSA key fingerprint is
SHA256:iEUtFh+dbjp9qEaKKzac/dbjp9qEaKKzacFnBC+Z4Vs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'mydroplet.digital.ocean,172.17.217.2' (ECDSA) to
the list of known hosts.
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Dec 13 22:05:41 UTC 2018

  System load:  0.87              Processes:           85
  Usage of /:   4.8% of 24.06GB   Users logged in:     0
  Memory usage: 14%               IP address for eth0: 172.17.217.2
  Swap usage:   0%

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@mydroplet:~# lsblk -o name,type,size,fstype,label,mountpoint
NAME    TYPE  SIZE FSTYPE LABEL            MOUNTPOINT
vda     disk   25G              
├─vda1  part 24.9G ext4   cloudimg-rootfs  /
├─vda14 part    4M              
└─vda15 part  106M vfat   UEFI             /boot/efi

root@mydroplet:~# tune2fs -L LINUX /dev/vda1
tune2fs 1.44.1 (24-Mar-2018)

root@mydroplet:~# lsblk -o name,type,size,fstype,label,mountpoint
NAME    TYPE  SIZE FSTYPE LABEL MOUNTPOINT
vda     disk   25G              
├─vda1  part 24.9G ext4   LINUX /
├─vda14 part    4M              
└─vda15 part  106M vfat   UEFI  /boot/efi

root@mydroplet:~# cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
LABEL=UEFI      /boot/efi       vfat    defaults        0 0

root@mydroplet:~# sed -i -e 's/\s\+/ /g' /etc/fstab

root@mydroplet:~# sed -i -e 's/cloudimg-rootfs/LINUX/g' /etc/fstab

root@mydroplet:~# cat /etc/fstab
LABEL=LINUX / ext4 defaults 0 0
LABEL=UEFI /boot/efi vfat defaults 0 0

root@mydroplet:~# update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.15.0-42-generic

root@mydroplet:~# update-grub
update-grub             update-grub-legacy-ec2  update-grub2            

root@mydroplet:~# update-grub2
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-42-generic
Found initrd image: /boot/initrd.img-4.15.0-42-generic
done

root@mydroplet:~# update-grub-legacy-ec2 
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.15.0-42-generic
Replacing config file /run/grub/menu.lst with new version
Found kernel: /boot/vmlinuz-4.15.0-42-generic
Updating /boot/grub/menu.lst ... done

root@mydroplet:~# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-42-generic
Found initrd image: /boot/initrd.img-4.15.0-42-generic
done

root@mydroplet:~# reboot
$ ssh root@mydroplet.digital.ocean
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Dec 13 22:09:05 UTC 2018

  System load:  0.28              Processes:           88
  Usage of /:   4.8% of 24.06GB   Users logged in:     0
  Memory usage: 13%               IP address for eth0: 172.17.217.2
  Swap usage:   0%

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

Last login: Thu Dec 13 22:05:43 2018 from 198.51.100.149

root@mydroplet:~# mkdir /data

root@mydroplet:~# for d in home srv; do
> mv /$d /data
> mkdir /$d
> echo /data/$d /$d none bind 0 0 >> /etc/fstab
> done

root@mydroplet:~# cat /etc/fstab
LABEL=LINUX / ext4 defaults 0 0
LABEL=UEFI /boot/efi vfat defaults 0 0
/data/home /home none bind 0 0
/data/srv /srv none bind 0 0

root@mydroplet:~# reboot
$ ssh root@mydroplet.digital.ocean
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-42-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Dec 13 22:11:32 UTC 2018

  System load:    0.47              Processes:           85
  Usage of /home: 4.8% of 24.06GB   Users logged in:     0
  Memory usage:   13%               IP address for eth0: 172.17.217.2
  Swap usage:     0%

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

Last login: Thu Dec 13 22:09:06 2018 from 198.51.100.149

root@mydroplet:~# mount | grep '^/dev/\S\+'
/dev/vda1 on / type ext4 (rw,relatime,data=ordered)
/dev/vda1 on /home type ext4 (rw,relatime,data=ordered)
/dev/vda1 on /srv type ext4 (rw,relatime,data=ordered)
/dev/vda15 on /boot/efi type vfat (rw,relatime,fmask=0022,dmask=0022,codepage...

No comments:

Post a Comment